Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
messenger
Commits
228362f2
Commit
228362f2
authored
Jan 20, 2021
by
JeongYeonwoo
Browse files
Merge remote-tracking branch 'origin/young' into yeonwoo
parents
8b3af68d
918ba292
Changes
27
Hide whitespace changes
Inline
Side-by-side
server/controllers/roomEnter.controller.js
0 → 100644
View file @
228362f2
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
server/controllers/user.controller.js
View file @
228362f2
...
...
@@ -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
}
// {} : 객체로 return함
\ No newline at end of file
export
default
{
signup
,
profileUpload
,
update
,
userById
,
getProfile
,
loginNavbar
}
// {} : 객체로 return함
server/models/Chat.js
View file @
228362f2
...
...
@@ -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
server/models/Room.js
View file @
228362f2
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
...
...
server/routes/room.routers.js
View file @
228362f2
...
...
@@ -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
server/routes/roomEnter.routers.js
0 → 100644
View file @
228362f2
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
server/server.js
View file @
228362f2
...
...
@@ -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
'
)
...
...
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment