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) => {
...
@@ -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함
// {} : 객체로 return함
\ No newline at end of file
server/models/Chat.js
View file @
228362f2
...
@@ -18,4 +18,4 @@ const ChatSchema = new mongoose.Schema({
...
@@ -18,4 +18,4 @@ const ChatSchema = new mongoose.Schema({
timestamps
:
true
timestamps
:
true
})
})
export
default
mongoose
.
models
.
ChatSchema
||
mongoose
.
model
(
'
Chat
'
,
ChatSchema
)
export
default
mongoose
.
models
.
Chat
||
mongoose
.
model
(
'
Chat
'
,
ChatSchema
)
\ No newline at end of file
\ No newline at end of file
server/models/Room.js
View file @
228362f2
import
mongoose
from
'
mongoose
'
import
mongoose
from
'
mongoose
'
const
{
String
}
=
mongoose
.
Schema
.
Types
const
{
String
}
=
mongoose
.
Schema
.
Types
const
{
Array
}
=
mongoose
.
Schema
.
Types
const
RoomSchema
=
new
mongoose
.
Schema
({
const
RoomSchema
=
new
mongoose
.
Schema
({
roomId
:
{
roomId
:
{
...
@@ -20,6 +21,10 @@ const RoomSchema = new mongoose.Schema({
...
@@ -20,6 +21,10 @@ const RoomSchema = new mongoose.Schema({
isOpen
:
{
isOpen
:
{
type
:
Boolean
,
type
:
Boolean
,
required
:
true
,
required
:
true
,
},
member
:
{
type
:
Array
,
required
:
true
,
}
}
},
{
},
{
timestamps
:
true
timestamps
:
true
...
...
server/routes/room.routers.js
View file @
228362f2
...
@@ -5,4 +5,10 @@ const router = express.Router()
...
@@ -5,4 +5,10 @@ const router = express.Router()
router
.
route
(
'
/room/makeRoom
'
)
router
.
route
(
'
/room/makeRoom
'
)
.
post
(
roomCtrl
.
makeRoom
)
.
post
(
roomCtrl
.
makeRoom
)
router
.
route
(
'
/room/closedlist
'
)
.
get
(
roomCtrl
.
getClosedList
)
router
.
route
(
'
/room/openlist
'
)
.
get
(
roomCtrl
.
getOpenList
)
export
default
router
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'
...
@@ -3,6 +3,7 @@ import connectDb from './utils/connectDb.js'
import
userRouter
from
'
./routes/user.routes.js
'
import
userRouter
from
'
./routes/user.routes.js
'
import
authRouter
from
'
./routes/auth.routes.js
'
import
authRouter
from
'
./routes/auth.routes.js
'
import
roomRouter
from
'
./routes/room.routers.js
'
import
roomRouter
from
'
./routes/room.routers.js
'
import
roomEnterRouter
from
'
./routes/roomEnter.routers.js
'
import
bodyParser
from
"
body-parser
"
;
import
bodyParser
from
"
body-parser
"
;
import
http
from
"
http
"
;
import
http
from
"
http
"
;
import
{
Server
}
from
'
socket.io
'
;
import
{
Server
}
from
'
socket.io
'
;
...
@@ -20,14 +21,16 @@ io.on("connection", (socket) => { // 기본 연결
...
@@ -20,14 +21,16 @@ io.on("connection", (socket) => { // 기본 연결
console
.
log
(
"
socket connect ok
"
,
socket
.
id
)
console
.
log
(
"
socket connect ok
"
,
socket
.
id
)
socket
.
on
(
'
joinRoom
'
,
(
data
)
=>
{
// joinRoom을 클라이언트가 emit했을 때
socket
.
on
(
'
joinRoom
'
,
(
data
)
=>
{
// joinRoom을 클라이언트가 emit했을 때
let
roomName
=
data
;
console
.
log
(
'
join_data확인
'
,
data
)
socket
.
join
(
roomName
);
//클라이언트에서 data에 적힌 room으로 참여시킴
let
roomInfo
=
data
;
socket
.
join
(
roomInfo
);
//클라이언트에서 data에 적힌 room으로 참여시킴
});
});
socket
.
on
(
'
chat
'
,
(
data
)
=>
{
socket
.
on
(
'
chat
'
,
(
data
)
=>
{
console
.
log
(
`chat실행 :`
,
data
.
roomName
,
data
.
msg
)
console
.
log
(
'
roomname확인
'
,
data
)
io
.
to
(
data
.
roomName
).
emit
(
'
broadcast
'
,
data
.
msg
);
//roomName에 존재하는 모든 소켓들에게
socket
.
broadcast
.
to
(
data
.
roomInfo
).
emit
(
'
sendedMSG
'
,
data
.
msg
);
// sender 제외 특정 방으로
})
});
socket
.
on
(
'
disconnect
'
,
()
=>
{
socket
.
on
(
'
disconnect
'
,
()
=>
{
console
.
log
(
'
disconnected from server id=
'
,
socket
.
id
)
console
.
log
(
'
disconnected from server id=
'
,
socket
.
id
)
...
@@ -35,8 +38,6 @@ io.on("connection", (socket) => { // 기본 연결
...
@@ -35,8 +38,6 @@ io.on("connection", (socket) => { // 기본 연결
});
});
// app.use(express.json())
//이부분을 body 파싱함
app
.
use
(
bodyParser
.
json
());
app
.
use
(
bodyParser
.
json
());
app
.
use
(
cors
());
app
.
use
(
cors
());
...
@@ -44,6 +45,7 @@ app.use('/images', express.static('uploads/'))
...
@@ -44,6 +45,7 @@ app.use('/images', express.static('uploads/'))
app
.
use
(
userRouter
)
app
.
use
(
userRouter
)
app
.
use
(
authRouter
)
app
.
use
(
authRouter
)
app
.
use
(
roomRouter
)
app
.
use
(
roomRouter
)
app
.
use
(
roomEnterRouter
)
server
.
listen
(
3030
,
()
=>
{
server
.
listen
(
3030
,
()
=>
{
console
.
log
(
'
Listening on port 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