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
54789675
Commit
54789675
authored
Jan 22, 2021
by
Choi Ga Young
Browse files
병합에러수정
parent
e9b2bd86
Changes
3
Hide whitespace changes
Inline
Side-by-side
client/src/Components/Chat.js
View file @
54789675
...
@@ -40,7 +40,6 @@ function Chat(props) {
...
@@ -40,7 +40,6 @@ function Chat(props) {
props
.
setSingleImg
(
user
.
profileimg
)
props
.
setSingleImg
(
user
.
profileimg
)
props
.
setSingleUser
(
user
.
nickname
)
props
.
setSingleUser
(
user
.
nickname
)
// props.setSingleUser(sessionStorage.getItem('name'))
props
.
setSingleChat
(
inner
)
props
.
setSingleChat
(
inner
)
props
.
sendMsg
(
e
)
props
.
sendMsg
(
e
)
...
@@ -48,7 +47,7 @@ function Chat(props) {
...
@@ -48,7 +47,7 @@ function Chat(props) {
setDisabled
(
true
)
setDisabled
(
true
)
}
}
function
handleClick
(
e
)
{
function
handleClick
()
{
setChat
([])
setChat
([])
props
.
handleChatc
()
props
.
handleChatc
()
}
}
...
@@ -108,8 +107,7 @@ function Chat(props) {
...
@@ -108,8 +107,7 @@ function Chat(props) {
})
})
}
}
<
Button
variant
=
"
light
"
onClick
=
{
props
.
handleChatc
}
>
{
`<`
}
<
/Button
>
<
Button
variant
=
"
light
"
onClick
=
{
handleClick
}
>
{
`<`
}
<
/Button
>
<
/Container
>
<
/Container
>
<
Form
onSubmit
=
{
sendMsgCH
}
fluid
>
<
Form
onSubmit
=
{
sendMsgCH
}
fluid
>
...
...
client/src/Pages/HomePage.js
View file @
54789675
...
@@ -51,6 +51,11 @@ function Home() {
...
@@ -51,6 +51,11 @@ function Home() {
setNewUser
(
data
)
setNewUser
(
data
)
})
})
const
sendMsg
=
(
e
)
=>
{
e
.
preventDefault
()
}
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
!
(
singleChat
==
''
))
{
if
(
!
(
singleChat
==
''
))
{
socket
.
emit
(
"
chat
"
,
{
socket
.
emit
(
"
chat
"
,
{
...
@@ -67,7 +72,7 @@ function Home() {
...
@@ -67,7 +72,7 @@ function Home() {
useEffect
(()
=>
{
useEffect
(()
=>
{
socket
.
on
(
"
sendedMSG
"
,
(
msg
)
=>
{
socket
.
on
(
"
sendedMSG
"
,
(
sendInfo
)
=>
{
setRecievedImg
(
sendInfo
.
img
)
setRecievedImg
(
sendInfo
.
img
)
setRecievedUser
(
sendInfo
.
sender
)
setRecievedUser
(
sendInfo
.
sender
)
setRecievedMsg
(
sendInfo
.
msg
)
setRecievedMsg
(
sendInfo
.
msg
)
...
...
server/server.js
View file @
54789675
import
express
,
{
response
}
from
'
express
'
import
express
from
'
express
'
import
connectDb
from
'
./utils/connectDb.js
'
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
'
...
@@ -9,7 +9,6 @@ import http from "http";
...
@@ -9,7 +9,6 @@ import http from "http";
import
{
Server
}
from
'
socket.io
'
;
import
{
Server
}
from
'
socket.io
'
;
import
cors
from
"
cors
"
import
cors
from
"
cors
"
import
Room
from
'
./models/Room.js
'
import
Room
from
'
./models/Room.js
'
import
{
nextTick
}
from
'
process
'
import
Chat
from
"
./models/Chat.js
"
import
Chat
from
"
./models/Chat.js
"
connectDb
()
connectDb
()
...
@@ -29,8 +28,8 @@ io.on("connection", (socket) => { // 기본 연결
...
@@ -29,8 +28,8 @@ io.on("connection", (socket) => { // 기본 연결
socket
.
join
(
roomInfo
);
//클라이언트에서 data에 적힌 room으로 참여시킴
socket
.
join
(
roomInfo
);
//클라이언트에서 data에 적힌 room으로 참여시킴
});
});
socket
.
on
(
'
newUser
'
,
(
data
)
=>
{
socket
.
on
(
'
newUser
'
,
(
data
)
=>
{
console
.
log
(
'
newUser
'
,
data
)
console
.
log
(
'
newUser
'
,
data
)
let
userInfo
=
data
.
userInfo
;
let
userInfo
=
data
.
userInfo
;
io
.
to
(
data
.
rmIf
).
emit
(
'
sendUser
'
,
userInfo
)
io
.
to
(
data
.
rmIf
).
emit
(
'
sendUser
'
,
userInfo
)
})
})
...
@@ -46,14 +45,14 @@ io.on("connection", (socket) => { // 기본 연결
...
@@ -46,14 +45,14 @@ io.on("connection", (socket) => { // 기본 연결
message
:
data
.
sendInfo
.
msg
message
:
data
.
sendInfo
.
msg
}).
save
()
}).
save
()
console
.
log
(
'
resChat확인
'
,
chat
)
console
.
log
(
'
resChat확인
'
,
chat
)
socket
.
broadcast
.
to
(
data
.
roomInfo
).
emit
(
'
sendedMSG
'
,
data
.
msg
);
// sender 제외 특정 방으로
});
socket
.
broadcast
.
to
(
data
.
roomInfo
).
emit
(
'
sendedMSG
'
,
data
.
sendInfo
);
// sender 제외 특정 방으로
socket
.
on
(
'
disconnect
'
,
()
=>
{
});
console
.
log
(
'
disconnected from server id=
'
,
socket
.
id
)
})
socket
.
on
(
'
disconnect
'
,
()
=>
{
console
.
log
(
'
disconnected from server id=
'
,
socket
.
id
)
})
});
});
...
...
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