├── .gitignore ├── .prettierrc ├── README.md ├── backend ├── app.ts ├── bin │ └── www ├── config │ └── redis.ts ├── models │ ├── MUSIC.js │ ├── USER.js │ ├── index.js │ ├── init-models.js │ └── sessions.js ├── package.json ├── public │ ├── index.html │ └── stylesheets │ │ └── style.css ├── routes │ ├── api │ │ ├── index.ts │ │ ├── music.ts │ │ ├── room.ts │ │ └── userList.ts │ ├── audio.ts │ ├── download.ts │ ├── loginRouter.ts │ ├── room.ts │ └── uploadRouter.ts ├── services │ ├── loginService.ts │ ├── music.ts │ └── uploadService.ts ├── socket │ ├── SocketHandler.ts │ ├── index.ts │ ├── music.ts │ └── userData.ts ├── tsconfig.json ├── types │ └── index.ts ├── utils │ ├── cloudConfig.ts │ └── util.ts ├── yarn-error.log └── yarn.lock └── frontend ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── icons │ ├── chevron-left.svg │ ├── chevron-right.svg │ ├── close.svg │ ├── create-room.svg │ ├── file-upload.svg │ ├── leave-room.svg │ ├── music-note.svg │ ├── no-room.svg │ ├── pause.svg │ ├── play-circle.svg │ ├── play.svg │ ├── playlist-add.svg │ ├── search.svg │ ├── thumbs-up.svg │ ├── user.svg │ ├── volume-off.svg │ └── volume-up.svg ├── images │ ├── GitHub-Mark-120px-plus.png │ ├── GitHub-Mark-32px.png │ ├── btn_google_signin_light_normal_web.png │ ├── kakao.png │ └── logo.png ├── index.html ├── manifest.json └── robots.txt ├── src ├── components │ ├── App.tsx │ ├── Header │ │ ├── CreateRoomButton.tsx │ │ ├── Header.tsx │ │ ├── UploadModal.tsx │ │ └── UserButton.tsx │ ├── Main │ │ └── RoomItem.tsx │ ├── Room │ │ ├── Chat │ │ │ └── ChatComponent.tsx │ │ ├── MusicPlayer │ │ │ ├── MusicPlayer.tsx │ │ │ ├── ThumbnailPlayer.tsx │ │ │ └── Title.tsx │ │ ├── PlayList │ │ │ ├── MusicSearch │ │ │ │ ├── MusicSearch.tsx │ │ │ │ ├── MusicSearchItem.tsx │ │ │ │ └── reducer │ │ │ │ │ ├── addMusicState.tsx │ │ │ │ │ └── searchResult.tsx │ │ │ ├── PlayList.tsx │ │ │ └── PlayListItem.tsx │ │ └── UserList │ │ │ ├── UserItem.tsx │ │ │ └── UserList.tsx │ └── Util │ │ ├── CircleButton.tsx │ │ ├── Loading.tsx │ │ ├── Modal.tsx │ │ ├── PopUp.tsx │ │ ├── Progress.tsx │ │ ├── SearchBar.tsx │ │ ├── scrollbar.tsx │ │ └── uploadController.ts ├── config.host.json ├── context │ └── MyContext.tsx ├── hooks │ ├── useAsync.tsx │ ├── useinfiniteScroll.tsx │ └── utils.tsx ├── images │ └── search.png ├── index.css ├── index.tsx ├── pages │ ├── Login.tsx │ ├── Main.tsx │ ├── Result.tsx │ └── Room.tsx ├── react-app-env.d.ts ├── stylesheets │ ├── MusicPlayer.scss │ ├── Progress.scss │ ├── global.scss │ ├── header.scss │ ├── login.scss │ ├── main.scss │ ├── palette.scss │ ├── reset.css │ ├── style.module.scss │ └── userList.scss └── types │ └── index.ts ├── tsconfig.json └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env 3 | *.mp3 4 | *.wav 5 | config.json 6 | config.local.json 7 | dump.rdb 8 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "arrowParens": "avoid", 3 | "printWidth": 120, 4 | "singleQuote": true, 5 | "tabWidth": 2, 6 | "trailingComma": "all", 7 | "useTabs": false 8 | } 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Shall We Sound? 2 | 3 | [ShallWeSound 바로가기]('https://shallwesound.p-e.kr/') 4 | 5 | ## 👨‍👨‍👦 참여자 6 | 7 | | | | | | 8 | | :-------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------: | :-------------------------------------------------------------------------: | 9 | | J006 곽성준 | J084 박기범 | J163 이진선 | J171 이홍덕 | 10 | | [@seongjunme](https://github.com/seongjunme) | [@kbpark9898](https://github.com/kbpark9898) | [@jsl0149](https://github.com/jsl0149) | [@doggydeok2](https://github.com/doggydeok2) | 11 | 12 | ## 개요 13 | 14 | **_'같이 음악 듣지 않으실래요?'_** 15 | 16 | 내가 지금 듣고 있는 🎧이 노래🎧 너무 좋은데! 다른 사람도 다 알았으면 좋겠는데! 17 | 18 | 이런 경험 모두 한번씩은 있지 않나요?? 19 | 20 | 이제 더 이상 고민하지 마세요. Shall We Sound와 함께라면 같이 듣고, 같이 즐길 수 있습니다. 😆 21 | 22 | 모두가 동시에 같은 노래를 듣고, 그 노래에 대해 이야기할 수 있어요. 🎶🎶 23 | 24 | 내가 직접 만든 노래라구요? 걱정하지 마세요! Shall We Sound는 이용자들에게 열려있는 음악 플랫폼입니다. 25 | 26 | 내 노래를 자랑하고 싶다면, 서슴없이 업로드하세요. 그리고 재생하세요! 이제 당신은 프로 뮤지션입니다. 27 | 28 | 그럼 이제 옆에있는 내 사람에게 말해보세요. 29 | 30 | **'shall we sound?'** 31 | 32 | ## 기술스택 33 | 34 | --- 35 | 36 | | division | stack | 37 | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | 38 | | Web | ![socket.io](https://img.shields.io/badge/socket.io-v4.3.1-white?logo=socket.io) ![multer](https://img.shields.io/badge/multer-v1.4.3-white?logo=node.js) ![aws_sdk](https://img.shields.io/badge/aws_sdk-v2.348.0-orange?logo=amazon) | 39 | | Front-end | ![TypeScript](https://img.shields.io/badge/TypeScript-v4.4.4-blue?logo=TypeScript) ![Sass](https://img.shields.io/badge/Sass-v1.43.4-pink?logo=Sass) ![React](https://img.shields.io/badge/React-v17.0.2-blue?logo=react) | 40 | | Back-end | ![NodeJS](https://img.shields.io/badge/node.js-v14.15-green?logo=node.js) ![Express](https://img.shields.io/badge/Express-v4.16.1-9cf?logo=express) ![TypeScript](https://img.shields.io/badge/TypeScript-v4.4.4-blue?logo=TypeScript)![TypeScript](https://img.shields.io/badge/Redis-v6.2.5-red?logo=redis)![TypeScript](https://img.shields.io/badge/MySQL-v5.7.17-blue?logo=MySQL) | 41 | | Production | ![Naver Cloud Platform](https://img.shields.io/badge/NCP-NaverNCloud-9cf&color=brightgreen?logo=naver) ![PM2](https://img.shields.io/badge/PM2-nodeJS_BG_runtime-9cf?logo=pm2) | 42 | | Code Management | ![Git](https://img.shields.io/badge/Git-v2.34.0-red?logo=Git) ![github](https://img.shields.io/badge/GitHub-gray?logo=github) | 43 | | Formatting | ![eslint](https://img.shields.io/badge/eslint-v2.2.2-purple?logo=eslint) ![prettier](https://img.shields.io/badge/prettier-v9.0.0-yellow?logo=prettier) | 44 | 45 | ## 주요기능 46 | 47 | 👨‍💻 **로그인** 48 | 49 | 🎧 **공유 스트리밍** 50 | 51 | 🎼 **음악 업로드** 52 | 53 | 🏠 **방만들기** 54 | 55 | 💬 **유저** **채팅** 56 | 57 | ♻️ **방장 권한 위임** 58 | 59 | 🔎 **음악 검색** 60 | 61 | ## 상세소개 62 | 63 | [프로젝트 노션 링크](https://www.notion.so/boostcamp-wm/15-10-Web21-e15fcfdb965b4aa08bf9c8c5cf795796) 64 | -------------------------------------------------------------------------------- /backend/app.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import cors from 'cors'; 3 | import path from 'path'; 4 | import http from 'http'; 5 | import dotenv from 'dotenv'; 6 | dotenv.config({ path: __dirname + '/config/.env' }); 7 | import socket from './socket'; 8 | import roomRouter from './routes/room'; 9 | import audioRouter from './routes/audio'; 10 | import apiRouter from './routes/api/'; 11 | import uploadRouter from './routes/uploadRouter'; 12 | import downloadRouter from './routes/download'; 13 | import loginRouter from './routes/loginRouter'; 14 | 15 | const models = require('./models/index.js'); 16 | const app: express.Application = express(); 17 | const server: http.Server = http.createServer(app); 18 | 19 | const sequelize = require('sequelize'); 20 | const SequelizeAuto = require('sequelize-auto'); 21 | 22 | app.use( 23 | cors({ 24 | origin: true, 25 | credentials: true, 26 | }), 27 | ); 28 | 29 | app.use('/api', apiRouter); 30 | 31 | app.get('/', (req, res) => { 32 | res.send('hello'); 33 | }); 34 | 35 | app.use('/room', roomRouter); 36 | app.use('/audio', audioRouter); 37 | app.use('/upload', uploadRouter); 38 | app.use('/download', downloadRouter); 39 | app.use('/oauth', loginRouter); 40 | 41 | app.use(express.static(path.join(__dirname, 'videos'))); 42 | 43 | app.set('port', 3000); 44 | 45 | server.listen(3000); 46 | 47 | socket(server); 48 | -------------------------------------------------------------------------------- /backend/bin/www: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * Module dependencies. 5 | */ 6 | 7 | var app = require('../app'); 8 | var debug = require('debug')('backend:server'); 9 | var http = require('http'); 10 | 11 | /** 12 | * Get port from environment and store in Express. 13 | */ 14 | 15 | var port = normalizePort(process.env.PORT || '3000'); 16 | app.set('port', port); 17 | 18 | /** 19 | * Create HTTP server. 20 | */ 21 | 22 | var server = http.createServer(app); 23 | 24 | /** 25 | * Listen on provided port, on all network interfaces. 26 | */ 27 | 28 | server.listen(port); 29 | server.on('error', onError); 30 | server.on('listening', onListening); 31 | 32 | /** 33 | * Normalize a port into a number, string, or false. 34 | */ 35 | 36 | function normalizePort(val) { 37 | var port = parseInt(val, 10); 38 | 39 | if (isNaN(port)) { 40 | // named pipe 41 | return val; 42 | } 43 | 44 | if (port >= 0) { 45 | // port number 46 | return port; 47 | } 48 | 49 | return false; 50 | } 51 | 52 | /** 53 | * Event listener for HTTP server "error" event. 54 | */ 55 | 56 | function onError(error) { 57 | if (error.syscall !== 'listen') { 58 | throw error; 59 | } 60 | 61 | var bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; 62 | 63 | // handle specific listen errors with friendly messages 64 | switch (error.code) { 65 | case 'EACCES': 66 | console.error(bind + ' requires elevated privileges'); 67 | process.exit(1); 68 | break; 69 | case 'EADDRINUSE': 70 | console.error(bind + ' is already in use'); 71 | process.exit(1); 72 | break; 73 | default: 74 | throw error; 75 | } 76 | } 77 | 78 | /** 79 | * Event listener for HTTP server "listening" event. 80 | */ 81 | 82 | function onListening() { 83 | var addr = server.address(); 84 | var bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; 85 | debug('Listening on ' + bind); 86 | } 87 | -------------------------------------------------------------------------------- /backend/config/redis.ts: -------------------------------------------------------------------------------- 1 | import redis from 'redis' 2 | export const client = redis.createClient(); 3 | client.on("error", function(error) { 4 | console.error(error); 5 | }); 6 | export const resultPrint = redis.print; 7 | 8 | export const updateOrDeleteToken = (token:string, updateToken:string|null, option:number)=>{ 9 | if(option === 1){ 10 | client.get(token, (err, data)=>{ 11 | client.set(updateToken!, data!); 12 | }) 13 | client.del(token); 14 | }else{ 15 | client.del(token); 16 | } 17 | } -------------------------------------------------------------------------------- /backend/models/MUSIC.js: -------------------------------------------------------------------------------- 1 | const Sequelize = require('sequelize'); 2 | module.exports = function(sequelize, DataTypes) { 3 | return sequelize.define('MUSIC', { 4 | MID: { 5 | autoIncrement: true, 6 | type: DataTypes.INTEGER, 7 | allowNull: false, 8 | primaryKey: true 9 | }, 10 | name: { 11 | type: DataTypes.STRING(500), 12 | allowNull: true 13 | }, 14 | singer: { 15 | type: DataTypes.STRING(500), 16 | allowNull: true 17 | }, 18 | description: { 19 | type: DataTypes.STRING(200), 20 | allowNull: true 21 | }, 22 | thumbnail: { 23 | type: DataTypes.STRING(500), 24 | allowNull: true 25 | }, 26 | path: { 27 | type: DataTypes.STRING(500), 28 | allowNull: true 29 | }, 30 | content_hash: { 31 | type: DataTypes.STRING(200), 32 | allowNull: true, 33 | unique: "content_hash_UNIQUE" 34 | } 35 | }, { 36 | sequelize, 37 | tableName: 'MUSIC', 38 | timestamps: false, 39 | indexes: [ 40 | { 41 | name: "PRIMARY", 42 | unique: true, 43 | using: "BTREE", 44 | fields: [ 45 | { name: "MID" }, 46 | ] 47 | }, 48 | { 49 | name: "content_hash_UNIQUE", 50 | unique: true, 51 | using: "BTREE", 52 | fields: [ 53 | { name: "content_hash" }, 54 | ] 55 | }, 56 | { 57 | name: "m_u_s_i_c_name_singer", 58 | type: "FULLTEXT", 59 | fields: [ 60 | { name: "name" }, 61 | { name: "singer" }, 62 | ] 63 | }, 64 | ] 65 | }); 66 | }; 67 | -------------------------------------------------------------------------------- /backend/models/USER.js: -------------------------------------------------------------------------------- 1 | const Sequelize = require('sequelize'); 2 | module.exports = function(sequelize, DataTypes) { 3 | return sequelize.define('USER', { 4 | U_ID: { 5 | autoIncrement: true, 6 | type: DataTypes.INTEGER, 7 | allowNull: false, 8 | primaryKey: true 9 | }, 10 | user_email: { 11 | type: DataTypes.STRING(100), 12 | allowNull: true 13 | }, 14 | ID: { 15 | type: DataTypes.STRING(400), 16 | allowNull: false 17 | }, 18 | platform: { 19 | type: DataTypes.STRING(45), 20 | allowNull: false 21 | } 22 | }, { 23 | sequelize, 24 | tableName: 'USER', 25 | timestamps: false, 26 | indexes: [ 27 | { 28 | name: "PRIMARY", 29 | unique: true, 30 | using: "BTREE", 31 | fields: [ 32 | { name: "U_ID" }, 33 | ] 34 | }, 35 | ] 36 | }); 37 | }; 38 | -------------------------------------------------------------------------------- /backend/models/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | const path = require('path'); 5 | const Sequelize = require('sequelize'); 6 | const basename = path.basename(__filename); 7 | const env = process.env.NODE_ENV || 'development'; 8 | const config = require(__dirname + '/../config/config.json')[env]; 9 | const db = {}; 10 | 11 | let sequelize; 12 | if (config.use_env_variable) { 13 | sequelize = new Sequelize(process.env[config.use_env_variable], config); 14 | } else { 15 | sequelize = new Sequelize(config.database, config.username, config.password, config); 16 | } 17 | 18 | fs.readdirSync(__dirname) 19 | .filter(file => { 20 | return file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js'; 21 | }) 22 | .forEach(file => { 23 | const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes); 24 | db[model.name] = model; 25 | }); 26 | 27 | Object.keys(db).forEach(modelName => { 28 | if (db[modelName].associate) { 29 | db[modelName].associate(db); 30 | } 31 | }); 32 | 33 | db.sequelize = sequelize; 34 | db.Sequelize = Sequelize; 35 | 36 | module.exports = db; 37 | -------------------------------------------------------------------------------- /backend/models/init-models.js: -------------------------------------------------------------------------------- 1 | var DataTypes = require("sequelize").DataTypes; 2 | var _MUSIC = require("./MUSIC"); 3 | var _USER = require("./USER"); 4 | var _sessions = require("./sessions"); 5 | 6 | function initModels(sequelize) { 7 | var MUSIC = _MUSIC(sequelize, DataTypes); 8 | var USER = _USER(sequelize, DataTypes); 9 | var sessions = _sessions(sequelize, DataTypes); 10 | 11 | 12 | return { 13 | MUSIC, 14 | USER, 15 | sessions, 16 | }; 17 | } 18 | module.exports = initModels; 19 | module.exports.initModels = initModels; 20 | module.exports.default = initModels; 21 | -------------------------------------------------------------------------------- /backend/models/sessions.js: -------------------------------------------------------------------------------- 1 | const Sequelize = require('sequelize'); 2 | module.exports = function(sequelize, DataTypes) { 3 | return sequelize.define('sessions', { 4 | session_id: { 5 | type: DataTypes.STRING(128), 6 | allowNull: false, 7 | primaryKey: true 8 | }, 9 | expires: { 10 | type: DataTypes.INTEGER.UNSIGNED, 11 | allowNull: false 12 | }, 13 | data: { 14 | type: DataTypes.TEXT, 15 | allowNull: true 16 | } 17 | }, { 18 | sequelize, 19 | tableName: 'sessions', 20 | timestamps: false, 21 | indexes: [ 22 | { 23 | name: "PRIMARY", 24 | unique: true, 25 | using: "BTREE", 26 | fields: [ 27 | { name: "session_id" }, 28 | ] 29 | }, 30 | ] 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /backend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "backend", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "nodemon --exec ts-node app.ts" 7 | }, 8 | "dependencies": { 9 | "@ffmpeg-installer/ffmpeg": "^1.1.0", 10 | "@types/axios": "^0.14.0", 11 | "@types/body-parser": "^1.19.2", 12 | "@types/express": "^4.17.13", 13 | "@types/jsonwebtoken": "^8.5.6", 14 | "@types/multer": "^1.4.7", 15 | "@types/mysql": "^2.15.19", 16 | "@types/qs": "^6.9.7", 17 | "@types/redis": "^2.8.32", 18 | "aws-sdk": "2.348.0", 19 | "axios": "^0.24.0", 20 | "body-parser": "^1.19.0", 21 | "cookie-parser": "~1.4.4", 22 | "cors": "^2.8.5", 23 | "debug": "~2.6.9", 24 | "dotenv": "^10.0.0", 25 | "express": "~4.16.1", 26 | "express-mysql-session": "^2.1.7", 27 | "express-session": "^1.17.2", 28 | "fluent-ffmpeg": "^2.1.2", 29 | "global": "^4.4.0", 30 | "hls-server": "^1.5.0", 31 | "http": "^0.0.1-security", 32 | "jsonwebtoken": "^8.5.1", 33 | "morgan": "~1.9.1", 34 | "multer": "^1.4.3", 35 | "mysql": "^2.18.1", 36 | "mysql2": "^2.3.3-rc.0", 37 | "qs": "^6.10.1", 38 | "redis": "^3.1.2", 39 | "sequelize": "^6.9.0", 40 | "sequelize-auto": "^0.8.5", 41 | "sequelize-cli": "^6.3.0", 42 | "session-file-store": "^1.5.0", 43 | "socket.io": "^4.3.1", 44 | "typescript": "^4.4.4" 45 | }, 46 | "devDependencies": { 47 | "nodemon": "^2.0.15", 48 | "ts-node": "^10.4.0" 49 | }, 50 | "nodemonConfig": { 51 | "ignore": [ 52 | "sessions" 53 | ] 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /backend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Express 6 | 7 | 8 | 9 | 10 |

Express

11 |

Welcome to Express

12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /backend/public/stylesheets/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 50px; 3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; 4 | } 5 | 6 | a { 7 | color: #00B7FF; 8 | } 9 | -------------------------------------------------------------------------------- /backend/routes/api/index.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import musicRouter from './music'; 3 | import roomRouter from './room'; 4 | import userListRouter from './userList'; 5 | const router = express.Router(); 6 | 7 | router.use('/music', musicRouter); 8 | router.use('/room', roomRouter); 9 | router.use('/userList', userListRouter); 10 | export default router; 11 | -------------------------------------------------------------------------------- /backend/routes/api/music.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import MusicService from '../../services/music'; 3 | 4 | const router = express.Router(); 5 | 6 | router.get('/', async (req: express.Request, res: express.Response) => { 7 | const keyword = (req.query.keyword as string) ?? ''; 8 | const page = parseInt(req.query.page as string); 9 | 10 | if (keyword === '') { 11 | res.send([]); 12 | } else { 13 | const result = await MusicService.searchByPage(keyword, page); 14 | res.send(result); 15 | } 16 | }); 17 | 18 | export default router; 19 | -------------------------------------------------------------------------------- /backend/routes/api/room.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import { socketData } from '../../socket/SocketHandler'; 3 | 4 | const router = express.Router(); 5 | 6 | router.use(express.json()); 7 | 8 | router.get('/', (req: express.Request, res: express.Response) => { 9 | const data = socketData.map(val => { 10 | return { id: val.id, name: val.name, description: val.description, totalUser: val.socketId.length }; 11 | }); 12 | res.json({ list: data }); 13 | }); 14 | 15 | export default router; 16 | -------------------------------------------------------------------------------- /backend/routes/api/userList.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import { socketData } from '../../socket/userData'; 3 | import { utils } from '../../utils/util'; 4 | 5 | const router = express.Router(); 6 | 7 | router.get('/', (req, res, next) => { 8 | const roomTitle = `${req.query.roomTitle}`; 9 | const targetRoom = utils.findRoomOnTitle(socketData, roomTitle); 10 | const userList = targetRoom?.userId.filter((val, idx, arr) => arr.indexOf(val) === idx); 11 | if (!targetRoom) res.json({ list: ['bad'] }); 12 | 13 | res.json({ list: userList }); 14 | }); 15 | 16 | export default router; 17 | -------------------------------------------------------------------------------- /backend/routes/audio.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import fs from 'fs'; 3 | import path from 'path'; 4 | const router = express.Router(); 5 | 6 | router.get('/:name', (req: express.Request, res: express.Response) => { 7 | const music = req.params.name; 8 | 9 | const data = fs.readFileSync(path.resolve(__dirname, `../audio/${music}`)); 10 | res.writeHead(200, { 11 | 'Content-Type': 'audio/mpeg', 12 | 'Accept-Ranges': 'none', 13 | }); 14 | res.write(data); 15 | res.end(); 16 | }); 17 | 18 | export default router; 19 | -------------------------------------------------------------------------------- /backend/routes/download.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import {myS3, makeSignedURL} from '../utils/cloudConfig' 3 | const router = express.Router(); 4 | router.use(express.json()); 5 | 6 | router.get('/' ,(req, res)=>{ 7 | const contentHash = req.body.contentHash; 8 | const musicName = req.body.musicName; 9 | res.send(makeSignedURL(myS3, contentHash, musicName)); 10 | }) 11 | 12 | 13 | export default router; -------------------------------------------------------------------------------- /backend/routes/loginRouter.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import { loginServie } from '../services/loginService'; 3 | import * as jwt from 'jsonwebtoken'; 4 | 5 | const router = express.Router(); 6 | router.use(express.json()); 7 | 8 | router.get('/', (req, res) => { 9 | res.send('test complete'); 10 | }); 11 | 12 | router.get('/test', (req, res) => { 13 | res.send('test test complete'); 14 | }); 15 | 16 | router.get('/kakao', (req, res) => { 17 | res.redirect( 18 | `https://kauth.kakao.com/oauth/authorize?client_id=${process.env.KAKAO_CLIENT_KEY}&redirect_uri=${process.env.KAKAO_CALLBACK_URL}&response_type=code`, 19 | ); 20 | }); 21 | router.get('/github', (req, res) => { 22 | res.redirect( 23 | `https://github.com/login/oauth/authorize?client_id=${process.env.GITHUB_CLIENT_ID}&redirect_uri=${process.env.GITHUB_CALLBACK_URL}`, 24 | ); 25 | }); 26 | 27 | router.get('/github/callback', async (req, res) => { 28 | const { code } = req.query; 29 | const token = await loginServie.githubLogin(code); 30 | res.cookie('userID', loginServie.getUserId(jwt.verify(token, `${process.env.SALT}`))); 31 | res.cookie('userEmail', loginServie.getUserEmail(jwt.verify(token, `${process.env.SALT}`))); 32 | res.cookie('jwt', token).redirect(`${process.env.LOCALHOST_URL}`); 33 | }); 34 | 35 | router.get('/kakao/callback', async (req, res) => { 36 | const token = await loginServie.kakaoLogin(req.query.code); 37 | res.cookie('userID', loginServie.getUserId(jwt.verify(token, `${process.env.SALT}`))); 38 | res.cookie('userEmail', loginServie.getUserEmail(jwt.verify(token, `${process.env.SALT}`))); 39 | res.cookie('jwt', token).redirect(`${process.env.LOCALHOST_URL}`); 40 | }); 41 | 42 | router.post('/authenticate', async (req, res) => { 43 | const curToken = req.body.jwt; 44 | const authenticateResult = await loginServie.verifyToken(curToken); 45 | if (authenticateResult.result === true) { 46 | if (authenticateResult.newToken === null) { 47 | res.json({ isOK: true }); 48 | } else { 49 | loginServie.updateOrDelete(curToken, authenticateResult.newToken, 1); 50 | res.cookie('jwt', authenticateResult.newToken); 51 | res.cookie('userID', authenticateResult.userID); 52 | res.cookie('userEmail', authenticateResult.userEmail); 53 | res.json({ isOK: true }); 54 | } 55 | } else { 56 | loginServie.updateOrDelete(curToken, null, 2); 57 | res.cookie('jwt', null); 58 | res.cookie('userID', null); 59 | res.cookie('userEmail', null); 60 | res.json({ isOK: false }); 61 | } 62 | }); 63 | 64 | export default router; 65 | -------------------------------------------------------------------------------- /backend/routes/room.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | const router = express.Router(); 3 | 4 | router.get('/', (req: express.Request, res: express.Response) => { 5 | res.send('room page'); 6 | }); 7 | 8 | export default router; 9 | -------------------------------------------------------------------------------- /backend/routes/uploadRouter.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import multer from 'multer'; 3 | import {makeHash} from '../utils/util' 4 | import {uploadLogic} from'../services/uploadService' 5 | const upload = multer({ 6 | storage: multer.memoryStorage(), 7 | limits:{ 8 | fileSize: 15 * 1024 * 1024 9 | } 10 | }); 11 | const router = express.Router(); 12 | const cpUpload = upload.fields([{name:'userFile1'}, {name:'userFile2'}]) 13 | 14 | 15 | router.post('/', cpUpload, async (req, res, next)=>{ 16 | const bucket_name = 'sws'; 17 | const files = req.files as { [fieldname: string]: Express.Multer.File[] }; 18 | const object_name = `${files.userFile1[0].originalname}`; 19 | const contentHash = makeHash(files.userFile1[0].buffer.toString()); 20 | const thumbnailName = object_name.split('.')[0]+'.'+files.userFile2[0].originalname.split('.')[1]; 21 | const singer = req.body.singer; 22 | const description = req.body.description 23 | uploadLogic(bucket_name, files, object_name, contentHash, thumbnailName, singer, description); 24 | res.send(200); 25 | }) 26 | export default router; -------------------------------------------------------------------------------- /backend/services/loginService.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | import * as jwt from 'jsonwebtoken' 3 | import {authCode, userProfileRequestHeader} from '../types/index' 4 | import {client, resultPrint, updateOrDeleteToken} from '../config/redis' 5 | import {promisify} from 'util' 6 | const models = require('../models/index.js'); 7 | 8 | const makeOauthAccessToken = async (platform:string, cururl:string, curheaders:string)=>{ 9 | if(platform === 'github'){ 10 | return axios({ 11 | method: `POST`, 12 | withCredentials: true, 13 | url: cururl, 14 | headers: { 15 | 'content-type': curheaders, 16 | }, 17 | }) 18 | }else{ 19 | return axios({ 20 | method: `POST`, 21 | url: cururl, 22 | headers: { 23 | 'content-type': curheaders, 24 | }, 25 | }) 26 | } 27 | } 28 | 29 | 30 | const getUserProfileFromOauth = async (platform:string, url:string, headers:userProfileRequestHeader) =>{ 31 | if(platform === 'github'){ 32 | return axios({ 33 | method:'GET', 34 | withCredentials:true, 35 | url: url, 36 | headers:{ 37 | Authorization: headers.Authorization 38 | } 39 | }) 40 | }else{ 41 | return axios({ 42 | method:'POST', 43 | withCredentials:true, 44 | url: url, 45 | data:{ 46 | property_keys: ["kakao_account.email"] 47 | }, 48 | headers: { 49 | 'Authorization': headers.Authorization, 50 | 'content-type': headers.contentType!, 51 | }, 52 | }) 53 | } 54 | 55 | } 56 | const githubLoginService = async(code:authCode)=>{ 57 | const tokenURL = `https://github.com/login/oauth/access_token?client_id=${process.env.GITHUB_CLIENT_ID}&client_secret=${process.env.GITHUB_CLIENT_SECRET}&code=${code}`; 58 | const access_token = await makeOauthAccessToken('github', tokenURL, 'application/json'); 59 | let access_token_split = access_token.data.split('&')[0].split('=')[1]; 60 | const requestHeader:userProfileRequestHeader={ 61 | Authorization:`token ${access_token_split}`, 62 | contentType:null 63 | } 64 | const userResponse = await getUserProfileFromOauth('github','https://api.github.com/user', requestHeader ) 65 | const userID = userResponse.data.login; 66 | const userEmail = userResponse.data.email === null || userResponse.data.email === undefined ? '':userResponse.data.email; 67 | const aToken = jwt.sign({userID:userID, userEmail:userEmail}, `${process.env.SALT}`, { 68 | expiresIn: '30m' 69 | }); 70 | const rToken = jwt.sign({}, `${process.env.SALT}`, {expiresIn:'2h'}) 71 | searchOrCreate(userID, userEmail, 'github'); 72 | client.set(aToken, rToken, resultPrint); 73 | return aToken; 74 | 75 | } 76 | const kakaoLoginService = async(code:authCode)=>{ 77 | const tokenURL=`https://kauth.kakao.com/oauth/token?client_id=${process.env.KAKAO_CLIENT_KEY}&grant_type=authorization_code&redirect_uri=${process.env.KAKAO_CALLBACK_URL}&code=${code}`; 78 | const tokenObj = await makeOauthAccessToken('kakao', tokenURL, 'application/x-www-form-urlencoded'); 79 | const accessToken = tokenObj.data.access_token; 80 | const requestHeader:userProfileRequestHeader={ 81 | Authorization:`Bearer ${accessToken}`, 82 | contentType:'application/x-www-form-urlencoded' 83 | } 84 | const userResponse = await getUserProfileFromOauth('kakao','https://kapi.kakao.com/v2/user/me', requestHeader); 85 | const userID = userResponse.data.id; 86 | const curEmail = userResponse.data.kakao_account.email; 87 | const userEmail = curEmail === null || curEmail == undefined ? '' : curEmail; 88 | searchOrCreate(userID, userEmail, 'kakao'); 89 | const aToken = jwt.sign({userID:userID, userEmail:userEmail}, `${process.env.SALT}`, { 90 | expiresIn: '30m' 91 | }); 92 | const rToken = jwt.sign({}, `${process.env.SALT}`, {expiresIn:'2h'}) 93 | client.set(aToken, rToken, resultPrint); 94 | 95 | return aToken; 96 | } 97 | 98 | const getUserId = (obj:string|jwt.JwtPayload):string =>{ 99 | if(typeof obj === 'string'){ 100 | return obj; 101 | }else{ 102 | return obj.userID; 103 | } 104 | } 105 | const getUserEmail = (obj:string|jwt.JwtPayload):string =>{ 106 | if(typeof obj === 'string'){ 107 | return obj; 108 | }else{ 109 | return obj.userEmail; 110 | } 111 | } 112 | 113 | 114 | const IDsearchInDB = async(verifyResult:string|jwt.JwtPayload)=>{ 115 | try{ 116 | await models.USER.findAll({ID:getUserId(verifyResult)}) 117 | }catch(DBerr){ 118 | return false; 119 | } 120 | return true; 121 | } 122 | 123 | const makeReturnResultOfVerifyToken = (result:boolean, userID:string|null, userEmail:string|null, newToken:string|null) =>{ 124 | return { 125 | result:result, 126 | userID:userID, 127 | userEmail:userEmail, 128 | newToken:newToken 129 | } 130 | } 131 | const verifyToken = async (accessToken:string) =>{ 132 | try{ 133 | const verifyResult = jwt.verify(accessToken, `${process.env.SALT}`); 134 | const DBsearchResult = await IDsearchInDB(verifyResult); 135 | if(DBsearchResult === false){ 136 | return makeReturnResultOfVerifyToken(false, null, null, null); 137 | } 138 | return makeReturnResultOfVerifyToken(true, getUserId(verifyResult), getUserEmail(verifyResult), null); 139 | }catch(err){ 140 | const refreshRes = await refreshToken(accessToken); 141 | if (refreshRes !== null){ 142 | const DBsearchResult = await IDsearchInDB(`${refreshRes}`); 143 | if(DBsearchResult === true){ 144 | return makeReturnResultOfVerifyToken(true, 145 | getUserId(jwt.verify(`${refreshRes}`, `${process.env.SALT}`)), 146 | getUserEmail(jwt.verify(`${refreshRes}`, `${process.env.SALT}`)) , 147 | refreshRes); 148 | }else{ 149 | return makeReturnResultOfVerifyToken(false, null, null, null); 150 | } 151 | }else{ 152 | return makeReturnResultOfVerifyToken(false, null, null, null); 153 | } 154 | } 155 | 156 | } 157 | 158 | const redisGET = promisify(client.get).bind(client); 159 | const refreshToken = async (accessToken:string)=>{ 160 | const rToken = await redisGET(accessToken); 161 | try{ 162 | jwt.verify(rToken!, `${process.env.SALT}`); 163 | return jwt.sign({userID:getUserId(jwt.decode(accessToken)!), userEmail:getUserEmail(jwt.decode(accessToken)!)}, 164 | `${process.env.SALT}`, {expiresIn:'30m'}); 165 | }catch(err){ 166 | return null 167 | } 168 | 169 | } 170 | 171 | const updateOrDelete = (token:string, updateToken:string|null, option:number) =>{ 172 | updateOrDeleteToken(token, updateToken, option); 173 | } 174 | 175 | const searchOrCreate = (id:string, email:string, platform:string)=>{ 176 | models.USER.findOrCreate({ 177 | where: { ID:id, platform:platform }, 178 | defaults: { 179 | ID:id, 180 | user_email:email, 181 | platform:platform 182 | } 183 | }); 184 | } 185 | export const loginServie={ 186 | githubLogin:githubLoginService, 187 | kakaoLogin:kakaoLoginService, 188 | verifyToken:verifyToken, 189 | updateOrDelete:updateOrDelete, 190 | getUserId:getUserId, 191 | getUserEmail:getUserEmail, 192 | searchOrCreate:searchOrCreate 193 | } 194 | 195 | 196 | -------------------------------------------------------------------------------- /backend/services/music.ts: -------------------------------------------------------------------------------- 1 | import { Music } from '../types'; 2 | 3 | const MusicModel = require('../models').MUSIC; 4 | const Op = require('sequelize').Op; 5 | 6 | export default { 7 | async searchByPage(keyword: string, page: number) { 8 | try { 9 | const result = await MusicModel.findAll({ 10 | where: { 11 | [Op.or]: { 12 | name: { [Op.like]: '%' + keyword + '%' }, 13 | singer: { [Op.like]: '%' + keyword + '%' }, 14 | }, 15 | }, 16 | replacements: { 17 | keyword: keyword, 18 | }, 19 | limit: 11, 20 | offset: page, 21 | }); 22 | 23 | if (result.length >= 11) { 24 | result.pop(); 25 | return { result, hasMore: true }; 26 | } 27 | 28 | return { result, hasMore: false }; 29 | } catch (e) { 30 | return { result: [], hasMore: false }; 31 | } 32 | }, 33 | async findMusicsBy(MIDS: number[]) { 34 | const result = await MusicModel.findAll({ 35 | attribute: ['MID', 'name', 'singer', 'description', 'thumbnail', 'path'], 36 | where: { 37 | MID: { 38 | [Op.or]: MIDS, 39 | }, 40 | }, 41 | }); 42 | 43 | return result.map( 44 | (res: Music): Music => ({ 45 | MID: res.MID, 46 | name: res.name, 47 | singer: res.singer, 48 | description: res.description, 49 | thumbnail: res.thumbnail, 50 | path: res.path, 51 | isPlayed: false, 52 | }), 53 | ); 54 | }, 55 | }; 56 | -------------------------------------------------------------------------------- /backend/services/uploadService.ts: -------------------------------------------------------------------------------- 1 | import {myS3, makeSignedURL} from '../utils/cloudConfig' 2 | import {Readable} from 'stream'; 3 | const models = require('../models/index.js'); 4 | 5 | const options = { 6 | partSize: 15 * 1024 * 1024 7 | }; 8 | 9 | const uploadToStorage = async( 10 | S3:AWS.S3, 11 | objectName:string, 12 | bucketName:string, 13 | files:{[fieldname: string]: Express.Multer.File[];}, 14 | contentHash:string, 15 | thumbnailName:string 16 | )=>{ 17 | let folder_name = `${contentHash}/`; 18 | // 해쉬값을 이름으로 하는 폴더를 생성하고, 그 안에 파일 업로드 19 | await S3.putObject({ 20 | Bucket: bucketName, 21 | Key: folder_name 22 | }).promise(); 23 | await Promise.all([ 24 | S3.upload({ 25 | Bucket: bucketName, 26 | Key: folder_name+objectName, 27 | Body: Readable.from(files.userFile1[0].buffer) 28 | }, options).promise(), 29 | S3.upload({ 30 | Bucket: bucketName, 31 | Key: folder_name+thumbnailName, 32 | Body: Readable.from(files.userFile2[0].buffer) 33 | }, options).promise() 34 | ]) 35 | } 36 | 37 | export const uploadLogic = async ( 38 | bucket_name:string, 39 | files:{[fieldname: string]: Express.Multer.File[];}, 40 | object_name:string, 41 | contentHash:string, 42 | thumbnailName:string, 43 | singer:string, 44 | description:string 45 | )=>{ 46 | try{ 47 | const queryResult = await models.MUSIC.create({ 48 | name:object_name, 49 | singer:singer, 50 | description:description, 51 | thumbnail:thumbnailName, 52 | path:'경로경로', 53 | content_hash:contentHash}); 54 | await uploadToStorage(myS3, object_name, bucket_name, files, contentHash, thumbnailName); 55 | const path = makeSignedURL(myS3, contentHash, object_name); 56 | const thumbnailPath = makeSignedURL(myS3, contentHash, thumbnailName); 57 | await queryResult.update({path:path, thumbnail:thumbnailPath}); 58 | 59 | }catch(e){ 60 | console.log(e); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /backend/socket/SocketHandler.ts: -------------------------------------------------------------------------------- 1 | import { Server, Socket } from 'socket.io'; 2 | import { socketData, userHash } from './userData'; 3 | import musicService from '../services/music'; 4 | import { utils } from '../utils/util'; 5 | import type { Music, socketInfo } from '../types'; 6 | 7 | let userNum: number = 0; 8 | let roomNumber: number = 1; 9 | 10 | const socketHandler = (io: Server) => { 11 | const namespace = io.of('/music'); 12 | 13 | namespace.on('connection', (socket: Socket) => { 14 | console.log('접속 중: ', socket.id); 15 | userHash[socket.id] = userNum; 16 | userNum += 1; 17 | 18 | socket.on('disconnect', () => { 19 | const targetRoom: socketInfo = utils.findRoom(socketData, socket.id); 20 | const leaveUser = targetRoom?.socketId[0]; 21 | utils.updateDisconnectData(targetRoom, socketData, socket); 22 | 23 | if (targetRoom && targetRoom.socketId.length > 0) { 24 | if (leaveUser === socket.id) { 25 | namespace.to(targetRoom.socketId[0]).emit('delegateHost', true); 26 | } 27 | 28 | namespace.to(targetRoom.id).emit('updateUserList'); 29 | const roomList = utils.getRoomListForClient(socketData); 30 | socket.broadcast.emit('updateRoomList', { list: roomList }); 31 | } 32 | }); 33 | 34 | socket.on('chatMessage', (message: string) => { 35 | const targetRoom: socketInfo = utils.findRoom(socketData, socket.id); 36 | const userID = utils.getUserBySocketID(targetRoom, socket.id); 37 | if (targetRoom !== undefined) socket.to(targetRoom.id).emit('chatMessage', { id: userID, msg: message }); 38 | }); 39 | 40 | socket.on('responseTime', (currentPlayTime: number) => { 41 | const targetRoom: socketInfo = utils.findRoom(socketData, socket.id); 42 | socket.broadcast.to(targetRoom.id).emit('sync', currentPlayTime); 43 | namespace.to(targetRoom.id).emit('changeMusicInfo', targetRoom.playList.getCurrentMusic()); 44 | namespace.to(targetRoom.id).emit('responsePlayList', targetRoom.playList.getPlayList()); 45 | }); 46 | 47 | socket.on('playControl', playType => { 48 | const targetRoom = utils.findRoomMaster(socketData, socket.id); 49 | if (playType === 'play') { 50 | const targetRoomTemp: socketInfo = utils.findRoom(socketData, socket.id); 51 | utils.joinRoom(socket, namespace, targetRoomTemp); 52 | } 53 | if (targetRoom !== undefined) socket.to(targetRoom.id).emit('playControl', playType); 54 | }); 55 | 56 | socket.on('nextMusicReq', () => { 57 | const targetRoom: socketInfo = utils.findRoom(socketData, socket.id); 58 | if (socket.id !== targetRoom?.socketId[0]) return; 59 | namespace.to(targetRoom.id).emit('changeMusicInfo', targetRoom.playList.getNextMusic()); 60 | namespace.to(targetRoom.id).emit('responsePlayList', targetRoom.playList.getPlayList()); 61 | }); 62 | 63 | socket.on('prevMusicReq', () => { 64 | const targetRoom: socketInfo = utils.findRoom(socketData, socket.id); 65 | if (socket.id !== targetRoom?.socketId[0]) return; 66 | namespace.to(targetRoom.id).emit('changeMusicInfo', targetRoom.playList.getPreMusic()); 67 | namespace.to(targetRoom.id).emit('responsePlayList', targetRoom.playList.getPlayList()); 68 | }); 69 | 70 | socket.on('currentMusicReq', () => { 71 | const targetRoom: socketInfo = utils.findRoom(socketData, socket.id); 72 | socket.emit('currentMusicRes', targetRoom?.playList.getCurrentMusic()); 73 | }); 74 | 75 | socket.on('addMusicInPlayListReq', async (MIDs: number[]) => { 76 | const targetRoom: socketInfo = utils.findRoom(socketData, socket.id); 77 | if (!targetRoom) { 78 | return; 79 | } 80 | if (targetRoom.playList.isExist(MIDs)) { 81 | namespace.to(socket.id).emit('duplicatedMusicInPlayList'); 82 | return; 83 | } 84 | 85 | const musics: Music[] = await musicService.findMusicsBy(MIDs); 86 | targetRoom.playList.addMusics(musics); 87 | namespace.to(socket.id).emit('successAddMusic'); 88 | 89 | const list = targetRoom?.playList.getPlayList(); 90 | 91 | if (list.length === musics.length) { 92 | list[0].isPlayed = true; 93 | namespace.to(targetRoom.id).emit('changeMusicInfo', list[0]); 94 | } 95 | 96 | namespace.to(targetRoom.id).emit('responsePlayList', list); 97 | }); 98 | 99 | socket.on('removeMusicInPlayListReq', (MID: number) => { 100 | const targetRoom = socketData.find(val => val.socketId.some(client => client === socket.id) === true); 101 | if (!targetRoom) return; 102 | 103 | targetRoom.playList.removeMusicByMID(MID); 104 | 105 | const res = targetRoom.playList.getPlayList(); 106 | namespace.to(targetRoom.id).emit('responsePlayList', res); 107 | }); 108 | 109 | socket.on('createRoom', data => { 110 | utils.updateNewRoom(socketData, socket, data, roomNumber.toString()); 111 | namespace.to(socket.id).emit('routingAfterCreateRoom', roomNumber.toString()); 112 | roomNumber++; 113 | }); 114 | 115 | socket.on('joinRoom', roomInfo => { 116 | socket.join(roomInfo.roomID); 117 | if (utils.isRoomExist(socketData, roomInfo.roomID)) { 118 | const target = utils.findRoomOnTitle(socketData, roomInfo.roomID); 119 | target?.socketId.push(socket.id); 120 | target?.userId.push(roomInfo.userID); 121 | if (target?.socketId.length) utils.joinRoom(socket, namespace, target); 122 | namespace.to(target?.id!).emit('updateUserList'); 123 | socket.broadcast.emit('updateRoomList'); 124 | } 125 | }); 126 | 127 | socket.on('leaveRoom', () => { 128 | const targetRoom: socketInfo = utils.findRoom(socketData, socket.id); 129 | const leaveUser = targetRoom?.socketId[0]; 130 | utils.updateDisconnectData(targetRoom, socketData, socket); 131 | 132 | if (targetRoom !== undefined) { 133 | if (leaveUser === socket.id) namespace.to(targetRoom.socketId[0]).emit('delegateHost', true); 134 | namespace.to(targetRoom.id).emit('updateUserList'); 135 | socket.leave(targetRoom.id); 136 | const roomList = utils.getRoomListForClient(socketData); 137 | socket.broadcast.emit('updateRoomList', { list: roomList }); 138 | } 139 | }); 140 | 141 | socket.on('clickAndPlayMusic', (clickedMusic: string) => { 142 | const targetRoom = utils.findRoom(socketData, socket.id); 143 | const targetPlayList = targetRoom.playList; 144 | targetPlayList.setIsPlayed(false, targetPlayList.getCurrentMusic().name); 145 | targetPlayList.setIsPlayed(true, clickedMusic); 146 | namespace.to(targetRoom.id).emit('changeMusicInfo', targetPlayList.getMusicByName(clickedMusic)); 147 | namespace.to(targetRoom.id).emit('responsePlayList', targetPlayList.getPlayList()); 148 | }); 149 | 150 | socket.on('redundancyCheck', userInfo => { 151 | const targetRoom: socketInfo = utils.findRoomOnTitle(socketData, userInfo.roomID)!; 152 | const isRedundancy = targetRoom.userId.some(val => val === userInfo.userID); 153 | socket.emit('redundancyCheck', { isRedundancy: isRedundancy, roomID: userInfo.roomID }); 154 | }); 155 | 156 | socket.on('delegateManual', (userName: string) => { 157 | const targetRoom: socketInfo = utils.findRoom(socketData, socket.id); 158 | utils.delegateHost(targetRoom, userName, socket.id, namespace); 159 | }); 160 | }); 161 | }; 162 | 163 | export { socketHandler, socketData }; 164 | -------------------------------------------------------------------------------- /backend/socket/index.ts: -------------------------------------------------------------------------------- 1 | import { Server } from 'socket.io'; 2 | import http from 'http'; 3 | import { socketHandler } from './SocketHandler'; 4 | 5 | export default (server: http.Server) => { 6 | const io = new Server(server, { cors: { origin: '*' } }); 7 | 8 | socketHandler(io); 9 | }; 10 | -------------------------------------------------------------------------------- /backend/socket/music.ts: -------------------------------------------------------------------------------- 1 | import type { Music } from '../types'; 2 | 3 | export class PlayList { 4 | playlist: Music[] = []; 5 | 6 | getPlayList(): Music[] { 7 | return this.playlist; 8 | } 9 | 10 | getNextMusic(): Music { 11 | const now = this.playlist.find(music => music.isPlayed); 12 | if (!now) { 13 | this.playlist[0].isPlayed = true; 14 | return this.playlist[0]; 15 | } 16 | 17 | const next = this.playlist[(this.playlist.indexOf(now) + 1) % this.playlist.length]; 18 | now.isPlayed = false; 19 | next.isPlayed = true; 20 | 21 | return next; 22 | } 23 | 24 | getPreMusic() { 25 | const now = this.playlist.find(music => music.isPlayed); 26 | if (!now) { 27 | this.playlist[0].isPlayed = true; 28 | return this.playlist[0]; 29 | } 30 | 31 | let previous: Music; 32 | 33 | if (this.playlist.indexOf(now) === 0) { 34 | previous = this.playlist[this.playlist.length - 1]; 35 | } else { 36 | previous = this.playlist[(this.playlist.indexOf(now) - 1) % this.playlist.length]; 37 | } 38 | 39 | now.isPlayed = false; 40 | previous.isPlayed = true; 41 | 42 | return previous; 43 | } 44 | 45 | getCurrentMusic(): Music { 46 | return this.playlist.find(music => music.isPlayed)!; 47 | } 48 | 49 | addMusics(musics: Music[]): void { 50 | this.playlist.push(...musics); 51 | } 52 | 53 | getMusicByName(musicName: string) { 54 | return this.playlist.find(val => val.name === musicName); 55 | } 56 | 57 | setIsPlayed(state: boolean, musicName: string) { 58 | const music: Music = this.getMusicByName(musicName)!; 59 | music.isPlayed = state; 60 | } 61 | 62 | removeMusicByMID(MID: number): void { 63 | this.playlist = this.playlist.filter(music => music.MID !== MID); 64 | } 65 | 66 | isExist(MIDs: number[]): boolean { 67 | const temp = new Set(this.playlist.map(music => music.MID)); 68 | return MIDs.find(MID => temp.has(MID)) ? true : false; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /backend/socket/userData.ts: -------------------------------------------------------------------------------- 1 | import { socketInfo, userList } from '../types'; 2 | 3 | const userHash: userList = {}; 4 | 5 | let socketData: socketInfo[] = []; 6 | 7 | export { userHash, socketData, socketInfo }; 8 | -------------------------------------------------------------------------------- /backend/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig.json to read more about this file */ 4 | 5 | /* Projects */ 6 | // "incremental": true, /* Enable incremental compilation */ 7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 8 | // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ 9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ 10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 12 | 13 | /* Language and Environment */ 14 | "target": "es5" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, 15 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 16 | // "jsx": "preserve", /* Specify what JSX code is generated. */ 17 | // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ 18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ 20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ 22 | // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ 23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 24 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 25 | 26 | /* Modules */ 27 | "module": "commonjs" /* Specify what module code is generated. */, 28 | // "rootDir": "./", /* Specify the root folder within your source files. */ 29 | // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ 30 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 31 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 32 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 33 | // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ 34 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */ 35 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 36 | // "resolveJsonModule": true, /* Enable importing .json files */ 37 | // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ 38 | 39 | /* JavaScript Support */ 40 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ 41 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 42 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ 43 | 44 | /* Emit */ 45 | // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 46 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 47 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 48 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 49 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ 50 | // "outDir": "./", /* Specify an output folder for all emitted files. */ 51 | // "removeComments": true, /* Disable emitting comments. */ 52 | // "noEmit": true, /* Disable emitting files from a compilation. */ 53 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 54 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ 55 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 56 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 57 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 58 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 59 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 60 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 61 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 62 | // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ 63 | // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */ 64 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 65 | // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */ 66 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 67 | 68 | /* Interop Constraints */ 69 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ 70 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 71 | "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */, 72 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 73 | "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, 74 | 75 | /* Type Checking */ 76 | "strict": true /* Enable all strict type-checking options. */, 77 | "noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied `any` type.. */, 78 | // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ 79 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 80 | // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ 81 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 82 | // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ 83 | // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ 84 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 85 | // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ 86 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ 87 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 88 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 89 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 90 | // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ 91 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 92 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ 93 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 94 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 95 | 96 | /* Completeness */ 97 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 98 | "skipLibCheck": true /* Skip type checking all .d.ts files. */ 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /backend/types/index.ts: -------------------------------------------------------------------------------- 1 | import { PlayList } from '../socket/music'; 2 | 3 | type authCode = string | qs.ParsedQs | string[] | qs.ParsedQs[] | undefined; 4 | 5 | type userProfileRequestHeader={ 6 | Authorization:string, 7 | contentType:string|null 8 | } 9 | 10 | type Music = { 11 | MID: number; 12 | name: string; 13 | singer: string; 14 | description: string; 15 | thumbnail: string; 16 | path: string; 17 | isPlayed: boolean; 18 | }; 19 | 20 | type socketInfo = { 21 | id: string; 22 | name: string; 23 | socketId: string[]; 24 | userId: string[]; 25 | description: string; 26 | playList: PlayList; 27 | }; 28 | 29 | type userList = { 30 | [socketid: string]: number; 31 | }; 32 | 33 | type musicTable = { 34 | MID: number; 35 | name: string; 36 | singer: string; 37 | description: string; 38 | thumbnail: string; 39 | path: string; 40 | content_hash: string; 41 | }; 42 | 43 | export type { Music, socketInfo, userList, musicTable, authCode, userProfileRequestHeader}; 44 | -------------------------------------------------------------------------------- /backend/utils/cloudConfig.ts: -------------------------------------------------------------------------------- 1 | import * as AWS from 'aws-sdk'; 2 | const region = 'kr-standard'; 3 | const access_key = `${process.env.ACCESS_KEY}`; 4 | const secret_key = `${process.env.SECRET_KEY}`; 5 | export const myS3 = new AWS.S3({ 6 | endpoint:'https://kr.object.ncloudstorage.com', 7 | region, 8 | credentials: { 9 | accessKeyId : access_key, 10 | secretAccessKey: secret_key 11 | } 12 | }); 13 | 14 | export const makeSignedURL = (S3:AWS.S3, contentHash:string, musicName:string):string =>{ 15 | const params = {Bucket: 'sws', Key: `${contentHash}/${musicName}`, Expires: 5000000}; 16 | return S3.getSignedUrl('getObject', params); 17 | } -------------------------------------------------------------------------------- /backend/utils/util.ts: -------------------------------------------------------------------------------- 1 | import { Socket } from 'socket.io'; 2 | import { socketInfo } from '../types'; 3 | import { PlayList } from '../socket/music'; 4 | import crypto from 'crypto'; 5 | 6 | export function makeHash(fileBuffer: string): string { 7 | return crypto 8 | .createHash('sha512') 9 | .update(fileBuffer + `${process.env.SALT}`) 10 | .digest('hex'); 11 | } 12 | 13 | export const utils = { 14 | findRoom: function (socketData: socketInfo[], socketID: string) { 15 | return socketData.find(val => val.socketId.some(client => client === socketID) === true)!; 16 | }, 17 | 18 | updateList: function (socketData: socketInfo[], targetRoom: socketInfo) { 19 | socketData.splice(socketData.indexOf(targetRoom), 1); 20 | return socketData.map(val => { 21 | return { id: val.id, name: val.name, description: val.description }; 22 | }); 23 | }, 24 | 25 | updateDisconnectData: function (targetRoom: socketInfo, socketData: socketInfo[], socket: Socket) { 26 | if (targetRoom !== undefined) { 27 | const targetIdx = targetRoom.socketId.indexOf(socket.id); 28 | targetRoom.socketId = targetRoom.socketId.filter(val => val !== socket.id); 29 | targetRoom.userId = targetRoom.userId.filter((val, idx) => idx !== targetIdx); 30 | if (!targetRoom.socketId.length) { 31 | const updatedList = this.updateList(socketData, targetRoom); 32 | socket.broadcast.emit('updateRoomList', { list: updatedList }); 33 | } 34 | } 35 | }, 36 | 37 | findRoomMaster: function (socketData: socketInfo[], socketID: string) { 38 | return socketData.find(val => val.socketId[0] === socketID); 39 | }, 40 | 41 | updateNewRoom: function (socketData: socketInfo[], socket: Socket, roomData: any, roomID: string) { 42 | socketData.push({ 43 | id: roomID, 44 | name: roomData.name, 45 | socketId: [], 46 | userId: [], 47 | description: roomData.description, 48 | playList: new PlayList(), 49 | }); 50 | }, 51 | 52 | getRoomListForClient: function (socketData: socketInfo[]) { 53 | return socketData.map(val => { 54 | return { id: val.id, name: val.name, description: val.description, totalUesr: val.socketId.length }; 55 | }); 56 | }, 57 | 58 | isRoomExist: function (socketData: socketInfo[], roomName: string) { 59 | return socketData.some(val => { 60 | return val.id === roomName; 61 | }); 62 | }, 63 | findRoomOnTitle: function (socketData: socketInfo[], roomName: string) { 64 | return socketData.find(val => val.id === roomName); 65 | }, 66 | 67 | joinRoom: function (socket: Socket, namespace: any, target: socketInfo) { 68 | socket.broadcast.to([target.socketId[0]]).emit('requestTime', 'time'); 69 | }, 70 | 71 | getUserBySocketID: function (targetRoom: socketInfo, socketID: string) { 72 | const targetIdx = targetRoom.socketId.indexOf(socketID); 73 | return targetRoom.userId[targetIdx]; 74 | }, 75 | 76 | delegateHost: function (targetRoom: socketInfo, userName: string, socketID: string, namespace: any) { 77 | const targetSocket = this.findSocketIDByUserName(targetRoom, userName); 78 | targetRoom.socketId = [targetSocket, ...targetRoom.socketId.filter(val => val !== targetSocket)]; 79 | targetRoom.userId = [userName, ...targetRoom.userId.filter(val => val !== userName)]; 80 | namespace.to(targetRoom.id).emit('updateUserList'); 81 | namespace.to(socketID).emit('delegateHost', false); 82 | namespace.to(targetSocket).emit('delegateHost', true); 83 | }, 84 | 85 | findSocketIDByUserName: function (targetRoom: socketInfo, userName: string) { 86 | const idx = targetRoom.userId.indexOf(userName); 87 | return targetRoom.socketId[idx]; 88 | }, 89 | }; 90 | -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | public/songs 3 | 4 | # dependencies 5 | /node_modules 6 | /.pnp 7 | .pnp.js 8 | 9 | # testing 10 | /coverage 11 | 12 | # production 13 | /build 14 | 15 | # misc 16 | .DS_Store 17 | .env.local 18 | .env.development.local 19 | .env.test.local 20 | .env.production.local 21 | .env 22 | 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | *.mp3 27 | *.wav -------------------------------------------------------------------------------- /frontend/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `yarn start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `yarn test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `yarn build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `yarn eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `yarn build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.11.4", 7 | "@testing-library/react": "^11.1.0", 8 | "@testing-library/user-event": "^12.1.10", 9 | "@types/jest": "^27.0.2", 10 | "@types/lodash": "^4.14.176", 11 | "@types/node": "^16.11.6", 12 | "@types/react-dom": "^17.0.10", 13 | "@types/react-router-dom": "^5.3.2", 14 | "@types/socket.io-client": "^3.0.0", 15 | "@types/styled-components": "^5.1.15", 16 | "react": "^17.0.2", 17 | "react-cookie": "^4.1.1", 18 | "react-dom": "^17.0.2", 19 | "react-router-dom": "^5.3.0", 20 | "react-scripts": "4.0.3", 21 | "sass": "^1.43.4", 22 | "socket-client": "^1.0.0", 23 | "socket.io-client": "^4.3.2", 24 | "styled-components": "^5.3.3", 25 | "typescript": "^4.4.4", 26 | "web-vitals": "^1.0.1" 27 | }, 28 | "proxy": "http://localhost:3000", 29 | "scripts": { 30 | "start": "react-scripts start", 31 | "build": "react-scripts build", 32 | "test": "react-scripts test", 33 | "eject": "react-scripts eject" 34 | }, 35 | "eslintConfig": { 36 | "extends": [ 37 | "react-app", 38 | "react-app/jest" 39 | ] 40 | }, 41 | "browserslist": { 42 | "production": [ 43 | ">0.2%", 44 | "not dead", 45 | "not op_mini all" 46 | ], 47 | "development": [ 48 | "last 1 chrome version", 49 | "last 1 firefox version", 50 | "last 1 safari version" 51 | ] 52 | }, 53 | "devDependencies": { 54 | "@types/react": "^17.0.33", 55 | "@types/react-responsive": "^8.0.4", 56 | "react-responsive": "^9.0.0-beta.5" 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /frontend/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostcampwm-2021/WEB21-ShallWeSound/169272ba5855b5f76b277ff7a9fc94c674705f81/frontend/public/favicon.ico -------------------------------------------------------------------------------- /frontend/public/icons/chevron-left.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /frontend/public/icons/chevron-right.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /frontend/public/icons/close.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/public/icons/create-room.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/public/icons/file-upload.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/public/icons/leave-room.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/public/icons/music-note.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /frontend/public/icons/no-room.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/public/icons/pause.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /frontend/public/icons/play-circle.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /frontend/public/icons/play.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/public/icons/playlist-add.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/public/icons/search.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/public/icons/thumbs-up.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/public/icons/user.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/public/icons/volume-off.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/public/icons/volume-up.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/public/images/GitHub-Mark-120px-plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostcampwm-2021/WEB21-ShallWeSound/169272ba5855b5f76b277ff7a9fc94c674705f81/frontend/public/images/GitHub-Mark-120px-plus.png -------------------------------------------------------------------------------- /frontend/public/images/GitHub-Mark-32px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostcampwm-2021/WEB21-ShallWeSound/169272ba5855b5f76b277ff7a9fc94c674705f81/frontend/public/images/GitHub-Mark-32px.png -------------------------------------------------------------------------------- /frontend/public/images/btn_google_signin_light_normal_web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostcampwm-2021/WEB21-ShallWeSound/169272ba5855b5f76b277ff7a9fc94c674705f81/frontend/public/images/btn_google_signin_light_normal_web.png -------------------------------------------------------------------------------- /frontend/public/images/kakao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostcampwm-2021/WEB21-ShallWeSound/169272ba5855b5f76b277ff7a9fc94c674705f81/frontend/public/images/kakao.png -------------------------------------------------------------------------------- /frontend/public/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostcampwm-2021/WEB21-ShallWeSound/169272ba5855b5f76b277ff7a9fc94c674705f81/frontend/public/images/logo.png -------------------------------------------------------------------------------- /frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | Shall We Sound? 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /frontend/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /frontend/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /frontend/src/components/App.tsx: -------------------------------------------------------------------------------- 1 | import { useState, useEffect} from 'react'; 2 | import { Room } from '../pages/Room'; 3 | import { MainPage } from '../pages/Main'; 4 | import { ResultPage } from '../pages/Result'; 5 | import { LoginPage } from '../pages/Login'; 6 | import '../stylesheets/reset.css'; 7 | import { BrowserRouter as Router, Route, Redirect, Switch } from 'react-router-dom'; 8 | import { Cookies } from 'react-cookie'; 9 | import config from '../config.host.json'; 10 | import HeaderComponent from '../components/Header/Header'; 11 | 12 | function App() { 13 | const cookies = new Cookies(); 14 | const [jwt, ] = useState(cookies.get('jwt')); 15 | const [authenticate, setAuthenticate] = useState(false); 16 | 17 | const authAsync= async()=>{ 18 | if (!jwt || jwt === undefined) { 19 | return false; 20 | }else{ 21 | const result = await fetch(`${config.localhost}/oauth/authenticate`, { 22 | method: 'POST', 23 | credentials: 'include', 24 | headers: { 25 | 'Content-Type': 'application/json', 26 | }, 27 | body: JSON.stringify({ jwt: cookies.get('jwt') }), 28 | }) 29 | const authenticateResponse = await result.json(); 30 | if(authenticate != authenticateResponse.isOK){ 31 | setAuthenticate(authenticateResponse.isOK); 32 | } 33 | return true; 34 | } 35 | 36 | } 37 | useEffect(() => { 38 | (async()=>{ 39 | await authAsync(); 40 | })() 41 | }, []) 42 | 43 | return ( 44 | <> 45 | 46 | 47 | { 51 | if (!authenticate) { 52 | return ; 53 | } else { 54 | return ; 55 | } 56 | }} 57 | /> 58 | <> 59 | 60 | { 64 | if (!authenticate) { 65 | return ; 66 | } else { 67 | return ; 68 | } 69 | }} 70 | /> 71 | { 75 | if (!authenticate) { 76 | return ; 77 | } else { 78 | return ; 79 | } 80 | }} 81 | /> 82 | { 85 | if (!authenticate) { 86 | return ; 87 | } else { 88 | return ; 89 | } 90 | }} 91 | /> 92 | { 95 | if (!authenticate) { 96 | return ; 97 | } else { 98 | return ; 99 | } 100 | }} 101 | /> 102 | 103 | 104 | 105 | 106 | ); 107 | } 108 | 109 | export default App; 110 | -------------------------------------------------------------------------------- /frontend/src/components/Header/CreateRoomButton.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState, useRef } from 'react'; 2 | import { RouteComponentProps } from 'react-router'; 3 | import { Socket } from 'socket.io-client'; 4 | import { useSocket } from '../../context/MyContext'; 5 | import { apiFetch, fadeOut } from '../../hooks/utils'; 6 | import '../../stylesheets/header.scss'; 7 | import { Room } from '../../types'; 8 | 9 | function CreateRoomModal({ history, onClose }: { history: RouteComponentProps['history']; onClose: () => void }) { 10 | const socket: Socket = useSocket()!; 11 | const alertRef = useRef(null); 12 | const [dialogInput, setDialogInput] = useState({ 13 | id: '', 14 | name: '', 15 | description: '', 16 | totalUser: 0, 17 | }); 18 | 19 | function changeDialogRoomName(e: React.BaseSyntheticEvent) { 20 | setDialogInput({ 21 | ...dialogInput, 22 | name: e.target.value, 23 | }); 24 | } 25 | 26 | function changeDialogRoomDescription(e: React.BaseSyntheticEvent) { 27 | setDialogInput({ 28 | ...dialogInput, 29 | description: e.target.value, 30 | }); 31 | } 32 | 33 | function createRoom() { 34 | if ( 35 | dialogInput.name.split('').every(val => val === ' ') || 36 | dialogInput.description.split('').every(val => val === ' ') 37 | ) { 38 | fadeOut(alertRef.current!); 39 | return; 40 | } 41 | 42 | if (dialogInput.name && dialogInput.description) { 43 | socket.emit('createRoom', { 44 | id: 0, 45 | name: dialogInput.name, 46 | description: dialogInput.description, 47 | }); 48 | 49 | onClose(); 50 | } else { 51 | fadeOut(alertRef.current!); 52 | } 53 | } 54 | 55 | return ( 56 |
57 |
58 | 59 | 60 | 61 | 62 |
63 |

방 생성

64 |
65 | 66 | 67 | 68 |