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
ffa2f2f0
Commit
ffa2f2f0
authored
Jan 22, 2021
by
Choi Ga Young
Browse files
새로운 유저
parent
44665bf6
Changes
4
Show whitespace changes
Inline
Side-by-side
client/src/Components/Chat.js
View file @
ffa2f2f0
...
@@ -14,6 +14,7 @@ function Chat(props) {
...
@@ -14,6 +14,7 @@ function Chat(props) {
const
[
user
,
setUser
]
=
useState
(
''
)
const
[
user
,
setUser
]
=
useState
(
''
)
const
[
error
,
setError
]
=
useState
(
''
);
const
[
error
,
setError
]
=
useState
(
''
);
const
userId
=
isAuthenticated
()
const
userId
=
isAuthenticated
()
async
function
getProfile
(
userId
)
{
async
function
getProfile
(
userId
)
{
try
{
try
{
...
@@ -74,7 +75,7 @@ function Chat(props) {
...
@@ -74,7 +75,7 @@ function Chat(props) {
return
(
return
(
<
div
className
=
"
chat
"
id
=
"
chat
"
style
=
{{
border
:
"
2px solid
"
,
height
:
"
300%
"
,
margin
:
"
1%
"
,
borderColor
:
"
#BDBDBD
"
,
background
:
''
}}
>
<
div
className
=
"
chat
"
id
=
"
chat
"
style
=
{{
border
:
"
2px solid
"
,
height
:
"
300%
"
,
margin
:
"
1%
"
,
borderColor
:
"
#BDBDBD
"
,
background
:
''
}}
>
<
h2
>
해당
방에
대한
참여코드는
{
props
.
roomCode
}
입니다
.
<
/h2
>
<
h2
>
해당
방에
대한
참여코드는
{
props
.
roomCode
}
입니다
.
<
/h2
>
{
/* 상대방이 보낸 메세지 띄우기 + 같은유저면 프로필 이미지는 생략(chat을 object로 보낸사람과 함께 보내서 구분하자) */
}
<
p
>
{
props
.
newUser
}
님이
입장하셨습니다
.
<
/p
>
{
chat
.
map
((
value
,
index
)
=>
{
{
chat
.
map
((
value
,
index
)
=>
{
if
(
!
(
value
==
''
))
{
if
(
!
(
value
==
''
))
{
return
(
return
(
...
@@ -94,6 +95,7 @@ function Chat(props) {
...
@@ -94,6 +95,7 @@ function Chat(props) {
}
else
{
}
else
{
return
null
return
null
}
}
})
})
}
}
{
/* 내가 보낸 메세지 띄우기 */
}
{
/* 내가 보낸 메세지 띄우기 */
}
...
@@ -112,7 +114,6 @@ function Chat(props) {
...
@@ -112,7 +114,6 @@ function Chat(props) {
}
}
})
})
}
}
<
Button
variant
=
"
light
"
onClick
=
{
handleClick
}
>
{
`<`
}
<
/Button
>
<
Button
variant
=
"
light
"
onClick
=
{
handleClick
}
>
{
`<`
}
<
/Button
>
<
Form
onSubmit
=
{
sendMsgCH
}
>
<
Form
onSubmit
=
{
sendMsgCH
}
>
<
Form
.
Group
className
=
'
d-flex flex-wrap-nowrap justify-content-center ml-2 mr-2
'
>
<
Form
.
Group
className
=
'
d-flex flex-wrap-nowrap justify-content-center ml-2 mr-2
'
>
...
...
client/src/Components/OpenList.js
View file @
ffa2f2f0
...
@@ -16,6 +16,7 @@ function OpenList(props) {
...
@@ -16,6 +16,7 @@ function OpenList(props) {
function
enterChatRoomCH
(
e
)
{
function
enterChatRoomCH
(
e
)
{
console
.
log
(
'
e확인
'
,
e
.
target
)
const
roomCode
=
e
.
target
.
name
const
roomCode
=
e
.
target
.
name
props
.
enterChatRoom
(
roomCode
)
// 각각의 room으로 들어가도록 설정해야 함
props
.
enterChatRoom
(
roomCode
)
// 각각의 room으로 들어가도록 설정해야 함
props
.
setRoomCode
(
roomCode
)
props
.
setRoomCode
(
roomCode
)
...
...
client/src/Pages/HomePage.js
View file @
ffa2f2f0
...
@@ -23,6 +23,7 @@ function Home() {
...
@@ -23,6 +23,7 @@ function Home() {
const
[
singleChat
,
setSingleChat
]
=
useState
(
''
)
const
[
singleChat
,
setSingleChat
]
=
useState
(
''
)
const
[
recievedMsg
,
setRecievedMsg
]
=
useState
(
''
)
const
[
recievedMsg
,
setRecievedMsg
]
=
useState
(
''
)
const
[
roomCode
,
setRoomCode
]
=
useState
(
''
)
const
[
roomCode
,
setRoomCode
]
=
useState
(
''
)
const
[
newUser
,
setNewUser
]
=
useState
(
''
)
//방참가
//방참가
...
@@ -35,11 +36,10 @@ function Home() {
...
@@ -35,11 +36,10 @@ function Home() {
const
handleChato
=
()
=>
setChat
(
true
);
const
handleChato
=
()
=>
setChat
(
true
);
const
handleChatc
=
()
=>
setChat
(
false
);
const
handleChatc
=
()
=>
setChat
(
false
);
//SOCKET 관련 시작
//SOCKET 관련 시작
function
enterChatRoom
(
rCode
)
{
//방 입장하기
function
enterChatRoom
(
rCode
)
{
//방 입장하기
socket
.
emit
(
'
joinRoom
'
,
rCode
)
socket
.
emit
(
'
joinRoom
'
,
rCode
)
socket
.
emit
(
'
newUser
'
,
{
rmIf
:
rCode
,
userInfo
:
userName
})
console
.
log
(
`joinRoom :
${
rCode
}
입장`
)
console
.
log
(
`joinRoom :
${
rCode
}
입장`
)
}
}
...
@@ -47,6 +47,10 @@ function Home() {
...
@@ -47,6 +47,10 @@ function Home() {
e
.
preventDefault
()
e
.
preventDefault
()
}
}
socket
.
on
(
"
sendUser
"
,
(
data
)
=>
{
setNewUser
(
data
)
})
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
!
(
singleChat
==
''
))
{
if
(
!
(
singleChat
==
''
))
{
socket
.
emit
(
"
chat
"
,
{
socket
.
emit
(
"
chat
"
,
{
...
@@ -61,7 +65,7 @@ function Home() {
...
@@ -61,7 +65,7 @@ function Home() {
useEffect
(()
=>
{
useEffect
(()
=>
{
socket
.
on
(
"
sendedMSG
"
,
(
msg
)
=>
{
socket
.
on
(
"
sendedMSG
"
,
(
msg
)
=>
{
console
.
log
(
msg
)
console
.
log
(
'
msg
'
,
msg
)
setRecievedMsg
(
msg
)
setRecievedMsg
(
msg
)
})
})
},
[])
},
[])
...
@@ -82,7 +86,7 @@ function Home() {
...
@@ -82,7 +86,7 @@ function Home() {
<
/Col
>
<
/Col
>
<
Col
style
=
{{
padding
:
"
0
"
}}
>
<
Col
style
=
{{
padding
:
"
0
"
}}
>
{
chat
?
<
Chat
handleChatc
=
{
handleChatc
}
sendMsg
=
{
sendMsg
}
singleChat
=
{
singleChat
}
recievedMsg
=
{
recievedMsg
}
setSingleChat
=
{
setSingleChat
}
roomCode
=
{
roomCode
}
/> : <div style={{ position: "fixed", bottom: "20px", right: "30px" }}
>
{
chat
?
<
Chat
handleChatc
=
{
handleChatc
}
sendMsg
=
{
sendMsg
}
singleChat
=
{
singleChat
}
recievedMsg
=
{
recievedMsg
}
newUser
=
{
newUser
}
setSingleChat
=
{
setSingleChat
}
roomCode
=
{
roomCode
}
/> : <div style={{ position: "fixed", bottom: "20px", right: "30px" }}
>
<
Button
variant
=
"
primary
"
onClick
=
{
handleShowModal
}
size
=
"
lg
"
block
>
<
Button
variant
=
"
primary
"
onClick
=
{
handleShowModal
}
size
=
"
lg
"
block
>
생성
생성
<
/Button
>
<
/Button
>
...
...
server/server.js
View file @
ffa2f2f0
...
@@ -29,6 +29,12 @@ io.on("connection", (socket) => { // 기본 연결
...
@@ -29,6 +29,12 @@ io.on("connection", (socket) => { // 기본 연결
socket
.
join
(
roomInfo
);
//클라이언트에서 data에 적힌 room으로 참여시킴
socket
.
join
(
roomInfo
);
//클라이언트에서 data에 적힌 room으로 참여시킴
});
});
socket
.
on
(
'
newUser
'
,
(
data
)
=>
{
console
.
log
(
'
newUser
'
,
data
)
let
userInfo
=
data
.
userInfo
;
io
.
to
(
data
.
rmIf
).
emit
(
'
sendUser
'
,
userInfo
)
})
socket
.
on
(
'
chat
'
,
async
(
data
)
=>
{
socket
.
on
(
'
chat
'
,
async
(
data
)
=>
{
console
.
log
(
'
roomname확인
'
,
data
)
console
.
log
(
'
roomname확인
'
,
data
)
const
room
=
await
Room
.
findOne
({
roomId
:
data
.
roomInfo
})
const
room
=
await
Room
.
findOne
({
roomId
:
data
.
roomInfo
})
...
...
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