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
a176c47f
Commit
a176c47f
authored
Jan 20, 2021
by
Soo Hyun Kim
Browse files
0120참여코드로참가
parent
0a02c1c5
Changes
6
Show whitespace changes
Inline
Side-by-side
client/src/Components/Chat.js
View file @
a176c47f
...
...
@@ -6,12 +6,11 @@ function Chat(props) {
let
defaultname
=
sessionStorage
.
getItem
(
'
name
'
);
const
[
inner
,
setInner
]
=
useState
([
''
])
const
[
chat
,
setChat
]
=
useState
([
inner
])
//object로 key는 보낸사람 value는 메세지
const
[
chat
,
setChat
]
=
useState
([])
//object로 key는 보낸사람 value는 메세지
function
handleChange
(
e
)
{
e
.
preventDefault
()
setInner
(
e
.
target
.
value
)
console
.
log
(
e
.
target
.
value
)
}
function
sendMsgCH
(
e
)
{
...
...
client/src/Components/ClosedList.js
View file @
a176c47f
...
...
@@ -24,7 +24,7 @@ function ClosedList(props) {
console
.
log
(
e
.
target
.
name
)
console
.
log
(
e
.
target
)
const
roomName
=
e
.
target
.
name
props
.
enterChat
r
oom
(
roomName
)
// 각각의 room으로 들어가도록 설정해야 함
props
.
enterChat
R
oom
(
roomName
)
// 각각의 room으로 들어가도록 설정해야 함
props
.
setRoomName
(
roomName
)
}
...
...
client/src/Components/EnterRoom.js
View file @
a176c47f
...
...
@@ -18,8 +18,11 @@ function EnterRoom(props) {
event
.
preventDefault
()
try
{
setError
(
''
)
await
axios
.
post
(
'
/room/enterRoom
'
,
enterCode
)
let
res
=
await
axios
.
post
(
'
/room/enterRoom
'
,
{
enterCode
})
props
.
setRoomName
(
res
.
data
)
props
.
enterChatRoom
(
enterCode
)
props
.
handleCloseEnter
()
props
.
handleChato
()
setEnterCode
(
''
)
}
catch
(
error
){
catchErrors
(
error
,
setError
)
...
...
client/src/Components/OpenList.js
View file @
a176c47f
...
...
@@ -18,7 +18,7 @@ function OpenList(props) {
function
enterChatRoomCH
(
e
)
{
const
roomName
=
e
.
target
.
name
props
.
enterChat
r
oom
(
roomName
)
// 각각의 room으로 들어가도록 설정해야 함
props
.
enterChat
R
oom
(
roomName
)
// 각각의 room으로 들어가도록 설정해야 함
props
.
setRoomName
(
roomName
)
// props.clearChat()
}
...
...
client/src/Pages/HomePage.js
View file @
a176c47f
...
...
@@ -23,9 +23,6 @@ function Home() {
const
[
roomName
,
setRoomName
]
=
useState
(
''
)
const
[
roomCode
,
setRoomCode
]
=
useState
(
''
)
//방참가
const
[
roomId
,
setRoomId
]
=
useState
(
''
)
const
handleCloseModal
=
()
=>
setShowModal
(
false
);
const
handleShowModal
=
()
=>
setShowModal
(
true
);
const
handleCloseEnter
=
()
=>
setEnter
(
false
);
...
...
@@ -36,7 +33,7 @@ function Home() {
//SOCKET 관련 시작
function
enterChat
r
oom
(
rName
)
{
//방 입장하기
function
enterChat
R
oom
(
rName
)
{
//방 입장하기
socket
.
emit
(
'
joinRoom
'
,
rName
)
console
.
log
(
`joinRoom :
${
rName
}
입장`
)
}
...
...
@@ -92,7 +89,7 @@ function Home() {
<
/Col
>
<
/Row
>
<
RoomMake
showModal
=
{
showModal
}
handleCloseModal
=
{
handleCloseModal
}
/
>
<
EnterRoom
showEnter
=
{
showEnter
}
enterChatRoom
=
{
enterChat
r
oom
}
handleCloseEnter
=
{
handleCloseEnter
}
/
>
<
EnterRoom
showEnter
=
{
showEnter
}
enterChatRoom
=
{
enterChat
R
oom
}
handleCloseEnter
=
{
handleCloseEnter
}
handleChato
=
{
handleChato
}
setRoomName
=
{
setRoomName
}
/
>
<
/
>
);
}
...
...
server/controllers/roomEnter.controller.js
View file @
a176c47f
import
Room
from
"
../models/Room.js
"
const
roomEnter
=
async
(
req
,
res
)
=>
{
const
roomId
=
req
.
body
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
(
`참여코드가 존재하지 않습니다.`
)
}
// room.member =
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
(
'
로그인 에러가 발생하였습니다
'
)
res
.
status
(
500
).
send
(
'
방 참여 에러
'
)
}
}
export
default
{
roomEnter
}
\ No newline at end of file
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