Commit 228362f2 authored by JeongYeonwoo's avatar JeongYeonwoo
Browse files

Merge remote-tracking branch 'origin/young' into yeonwoo

parents 8b3af68d 918ba292
import Room from "../models/Room.js"
const roomEnter = async (req, res) => {
const roomId = req.body.enterCode
// console.log(req)
try {
console.log(roomId)
const room = await Room.findOne({ roomId })
if (!room) {
return res.status(404).send(`참여코드가 존재하지 않습니다.`)
}
console.log('roomId존재')
const name = await Room.findOne({ roomId: roomId }).select('roomName')
return res.json(name.roomName)
} catch (error) {
//알수없는 모든 에러발생시 처리
console.log(error)
res.status(500).send('방 참여 에러')
}
}
export default { roomEnter }
\ No newline at end of file
......@@ -85,6 +85,14 @@ const getProfile = (req, res) => {
}
const loginNavbar = async (req, res) => {
try {
let user = await User.findOne(req.body).select('username').exec()
return res.json(user)
} catch (error) {
alert('올바르지 못한 접근입니다.')
}
}
export default { signup, profileUpload, update, userById, getProfile }
export default { signup, profileUpload, update, userById, getProfile, loginNavbar }
// {} : 객체로 return함
......@@ -18,4 +18,4 @@ const ChatSchema = new mongoose.Schema({
timestamps: true
})
export default mongoose.models.ChatSchema || mongoose.model('Chat', ChatSchema)
\ No newline at end of file
export default mongoose.models.Chat || mongoose.model('Chat', ChatSchema)
\ No newline at end of file
import mongoose from 'mongoose'
const {String} = mongoose.Schema.Types
const {Array} = mongoose.Schema.Types
const RoomSchema = new mongoose.Schema({
roomId: {
......@@ -20,6 +21,10 @@ const RoomSchema = new mongoose.Schema({
isOpen: {
type: Boolean,
required: true,
},
member: {
type: Array,
required: true,
}
}, {
timestamps: true
......
......@@ -5,4 +5,10 @@ const router = express.Router()
router.route('/room/makeRoom')
.post(roomCtrl.makeRoom)
router.route('/room/closedlist')
.get(roomCtrl.getClosedList)
router.route('/room/openlist')
.get(roomCtrl.getOpenList)
export default router
\ No newline at end of file
import express from 'express'
import roomEnterCtrl from '../controllers/roomEnter.controller.js'
const router = express.Router()
router.route('/room/enterRoom')
.post(roomEnterCtrl.roomEnter)
export default router
\ No newline at end of file
......@@ -3,6 +3,7 @@ import connectDb from './utils/connectDb.js'
import userRouter from './routes/user.routes.js'
import authRouter from './routes/auth.routes.js'
import roomRouter from './routes/room.routers.js'
import roomEnterRouter from './routes/roomEnter.routers.js'
import bodyParser from "body-parser";
import http from "http";
import { Server } from 'socket.io';
......@@ -20,14 +21,16 @@ io.on("connection", (socket) => { // 기본 연결
console.log("socket connect ok", socket.id)
socket.on('joinRoom', (data)=>{ // joinRoom을 클라이언트가 emit했을 때
let roomName=data;
socket.join(roomName); //클라이언트에서 data에 적힌 room으로 참여시킴
console.log('join_data확인',data)
let roomInfo=data;
socket.join(roomInfo); //클라이언트에서 data에 적힌 room으로 참여시킴
});
socket.on('chat', (data) => {
console.log(`chat실행 :`, data.roomName, data.msg)
io.to(data.roomName).emit('broadcast', data.msg); //roomName에 존재하는 모든 소켓들에게
})
console.log('roomname확인', data)
socket.broadcast.to(data.roomInfo).emit('sendedMSG', data.msg ); // sender 제외 특정 방으로
});
socket.on('disconnect', () => {
console.log('disconnected from server id=', socket.id)
......@@ -35,8 +38,6 @@ io.on("connection", (socket) => { // 기본 연결
});
// app.use(express.json())
//이부분을 body 파싱함
app.use(bodyParser.json());
app.use(cors());
......@@ -44,6 +45,7 @@ app.use('/images', express.static('uploads/'))
app.use(userRouter)
app.use(authRouter)
app.use(roomRouter)
app.use(roomEnterRouter)
server.listen(3030, () => {
console.log('Listening on port 3030')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment