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
4c6f4efe
Commit
4c6f4efe
authored
Jan 30, 2021
by
Choi Ga Young
Browse files
끝
parent
bd853bc1
Changes
12
Show whitespace changes
Inline
Side-by-side
client/src/Components/Chat.js
View file @
4c6f4efe
...
@@ -14,11 +14,9 @@ const INIT_CHAT = {
...
@@ -14,11 +14,9 @@ const INIT_CHAT = {
}
}
function
Chat
(
props
)
{
function
Chat
(
props
)
{
//const [sender, setSender] = useState([])
//const [roomName, setRoomName] = useState('')
const
[
inner
,
setInner
]
=
useState
([
''
])
const
[
inner
,
setInner
]
=
useState
([
''
])
const
[
chat
,
setChat
]
=
useState
([
INIT_CHAT
])
//object로 key는 보낸사람 value는 메세지
const
[
chat
,
setChat
]
=
useState
([
INIT_CHAT
])
const
simpleTime
=
new
Date
().
toLocaleTimeString
()
const
simpleTime
=
new
Date
().
toLocaleTimeString
()
const
usualTime
=
simpleTime
.
substring
(
0
,
simpleTime
.
length
-
3
)
const
usualTime
=
simpleTime
.
substring
(
0
,
simpleTime
.
length
-
3
)
...
@@ -63,7 +61,6 @@ function Chat(props) {
...
@@ -63,7 +61,6 @@ function Chat(props) {
recordEntryLog
()
//그냥 새로고침해도 최신화
recordEntryLog
()
//그냥 새로고침해도 최신화
}
}
async
function
recordEntryLog
()
{
async
function
recordEntryLog
()
{
const
leaveInfo
=
{
userId
:
userId
,
roomCode
:
props
.
roomCode
,
leaveTime
:
realTime
}
const
leaveInfo
=
{
userId
:
userId
,
roomCode
:
props
.
roomCode
,
leaveTime
:
realTime
}
try
{
try
{
...
@@ -79,7 +76,6 @@ function Chat(props) {
...
@@ -79,7 +76,6 @@ function Chat(props) {
}
}
function
handleClick
()
{
function
handleClick
()
{
props
.
closeChatRoom
(
props
.
roomCode
)
props
.
closeChatRoom
(
props
.
roomCode
)
props
.
setRecievedMsg
(
''
)
props
.
setRecievedMsg
(
''
)
...
...
client/src/Components/ClosedList.js
View file @
4c6f4efe
...
@@ -62,8 +62,8 @@ function ClosedList(props) {
...
@@ -62,8 +62,8 @@ function ClosedList(props) {
},
[
props
.
unreadnumber
])
},
[
props
.
unreadnumber
])
return
(
return
(
<
div
style
=
{{
height
:
"
80vh
"
}}
>
<
div
style
=
{{
height
:
"
80vh
"
}}
>
<
div
style
=
{{
overflow
:
'
auto
'
,
height
:
"
100%
"
}}
>
<
div
style
=
{{
overflow
:
'
auto
'
,
height
:
"
100%
"
}}
>
{
props
.
closedlist
.
map
((
item
,
index
)
=>
{
props
.
closedlist
.
map
((
item
,
index
)
=>
<
ListGroup
key
=
{
index
}
>
<
ListGroup
key
=
{
index
}
>
<
ListGroup
.
Item
action
onClick
=
{
enterChatRoomCH
}
name
=
{
item
.
roomId
}
value
=
{
item
.
roomName
}
<
ListGroup
.
Item
action
onClick
=
{
enterChatRoomCH
}
name
=
{
item
.
roomId
}
value
=
{
item
.
roomName
}
...
...
client/src/Components/OpenList.js
View file @
4c6f4efe
...
@@ -14,7 +14,8 @@ function OpenList(props) {
...
@@ -14,7 +14,8 @@ function OpenList(props) {
}
}
return
(
return
(
<
div
style
=
{{
overflow
:
'
auto
'
,
height
:
"
80vh
"
}}
>
<
div
style
=
{{
height
:
"
80vh
"
}}
>
<
div
style
=
{{
overflow
:
'
auto
'
,
height
:
"
80vh
"
}}
>
{
props
.
openlist
.
map
((
item
,
index
)
=>
{
props
.
openlist
.
map
((
item
,
index
)
=>
<
ListGroup
key
=
{
index
}
>
<
ListGroup
key
=
{
index
}
>
<
ListGroup
.
Item
action
onClick
=
{
enterChatRoomCH
}
name
=
{
item
.
roomId
}
className
=
'
rounded-0
'
>
<
ListGroup
.
Item
action
onClick
=
{
enterChatRoomCH
}
name
=
{
item
.
roomId
}
className
=
'
rounded-0
'
>
...
@@ -23,6 +24,7 @@ function OpenList(props) {
...
@@ -23,6 +24,7 @@ function OpenList(props) {
<
/ListGroup
>
<
/ListGroup
>
)}
)}
<
/div
>
<
/div
>
<
/div
>
)
)
}
}
...
...
client/src/Components/RoomMake.js
View file @
4c6f4efe
...
@@ -34,7 +34,6 @@ function RoomMake(props) {
...
@@ -34,7 +34,6 @@ function RoomMake(props) {
function
handleChange
(
event
)
{
function
handleChange
(
event
)
{
const
{
name
,
value
}
=
event
.
target
const
{
name
,
value
}
=
event
.
target
setRoom
({
...
room
,
[
name
]:
value
,
member
})
setRoom
({
...
room
,
[
name
]:
value
,
member
})
// console.log(room)
}
}
async
function
handleSubmit
(
event
)
{
async
function
handleSubmit
(
event
)
{
...
@@ -46,7 +45,6 @@ function RoomMake(props) {
...
@@ -46,7 +45,6 @@ function RoomMake(props) {
alert
(
`방암호는
${
Id
}
입니다`
)
alert
(
`방암호는
${
Id
}
입니다`
)
props
.
handleCloseModal
()
props
.
handleCloseModal
()
setRoom
(
INIT_ROOM
)
setRoom
(
INIT_ROOM
)
// setRoomCode(Id)
recordEntryLog
(
Id
)
recordEntryLog
(
Id
)
}
catch
(
error
)
{
}
catch
(
error
)
{
catchErrors
(
error
,
setError
)
catchErrors
(
error
,
setError
)
...
...
client/src/Pages/HomePage.js
View file @
4c6f4efe
...
@@ -4,7 +4,7 @@ import styled from 'styled-components';
...
@@ -4,7 +4,7 @@ import styled from 'styled-components';
import
ClosedList
from
'
../Components/ClosedList
'
;
import
ClosedList
from
'
../Components/ClosedList
'
;
import
OpenList
from
'
../Components/OpenList
'
;
import
OpenList
from
'
../Components/OpenList
'
;
import
Menu
from
'
../Components/Menu
'
;
import
Menu
from
'
../Components/Menu
'
;
import
{
io
}
from
"
socket.io-client
"
;
//모듈 가져오기
import
{
io
}
from
"
socket.io-client
"
;
import
Chat
from
"
../Components/Chat
"
;
import
Chat
from
"
../Components/Chat
"
;
import
RoomMake
from
"
../Components/RoomMake
"
import
RoomMake
from
"
../Components/RoomMake
"
import
EnterRoom
from
"
../Components/EnterRoom
"
import
EnterRoom
from
"
../Components/EnterRoom
"
...
@@ -85,8 +85,6 @@ function Home() {
...
@@ -85,8 +85,6 @@ function Home() {
socket
.
emit
(
'
newUser
'
,
{
rmIf
:
rCode
,
userInfo
:
userName
})
socket
.
emit
(
'
newUser
'
,
{
rmIf
:
rCode
,
userInfo
:
userName
})
setShow
(
true
)
setShow
(
true
)
console
.
log
(
`joinRoom :
${
rCode
}
입장`
)
console
.
log
(
`joinRoom :
${
rCode
}
입장`
)
console
.
log
(
'
show:
'
,
show
)
//여기서 채팅 불러와서 넘겨주던가 해야할거 같은데
console
.
log
(
'
HomePage/enterChatRoom 끝났습니다
'
)
console
.
log
(
'
HomePage/enterChatRoom 끝났습니다
'
)
}
}
...
@@ -107,7 +105,6 @@ function Home() {
...
@@ -107,7 +105,6 @@ function Home() {
async
function
getClosedList
()
{
async
function
getClosedList
()
{
const
userid
=
sessionStorage
.
getItem
(
'
userId
'
)
const
userid
=
sessionStorage
.
getItem
(
'
userId
'
)
let
res
=
await
axios
.
get
(
'
/room/closedlist
'
,
{
params
:
{
'
_id
'
:
userid
}
})
let
res
=
await
axios
.
get
(
'
/room/closedlist
'
,
{
params
:
{
'
_id
'
:
userid
}
})
// console.log('getClosedList',res.data)
setClosedList
(
res
.
data
)
setClosedList
(
res
.
data
)
}
}
...
...
client/src/Pages/ProfilePage.js
View file @
4c6f4efe
...
@@ -84,8 +84,6 @@ function ProfilePage() {
...
@@ -84,8 +84,6 @@ function ProfilePage() {
getProfile
(
userId
)
getProfile
(
userId
)
},
[
userId
])
},
[
userId
])
return
(
return
(
<>
<>
<
Menu
/>
<
Menu
/>
...
...
client/src/index.js
View file @
4c6f4efe
...
@@ -17,6 +17,9 @@ ReactDOM.render(
...
@@ -17,6 +17,9 @@ ReactDOM.render(
<
PrivateRoute
exact
path
=
"
/
"
>
<
PrivateRoute
exact
path
=
"
/
"
>
<
HomePage
/>
<
HomePage
/>
<
/PrivateRoute
>
<
/PrivateRoute
>
<
PrivateRoute
path
=
"
/home
"
>
<
HomePage
/>
<
/PrivateRoute
>
<
Route
path
=
"
/home
"
component
=
{
HomePage
}
/
>
<
Route
path
=
"
/home
"
component
=
{
HomePage
}
/
>
<
Route
path
=
"
/login
"
component
=
{
LogInPage
}
/
>
<
Route
path
=
"
/login
"
component
=
{
LogInPage
}
/
>
<
Route
path
=
"
/signup
"
component
=
{
SignUpPage
}
/
>
<
Route
path
=
"
/signup
"
component
=
{
SignUpPage
}
/
>
...
@@ -25,6 +28,7 @@ ReactDOM.render(
...
@@ -25,6 +28,7 @@ ReactDOM.render(
<
ProfilePage
/>
<
ProfilePage
/>
<
/PrivateRoute
>
<
/PrivateRoute
>
<
/Switch
>
<
/Switch
>
<
/Router>
,
<
/Router>
,
document
.
getElementById
(
'
root
'
)
document
.
getElementById
(
'
root
'
)
...
...
client/src/randCode.js
deleted
100644 → 0
View file @
bd853bc1
import
React
,
{
useState
}
from
'
react
'
;
function
randCode
(){
// const [ranNumArr,setRanNumArr] = useState([]);
const
min
=
1
;
const
max
=
99999
;
let
newNum
=
Math
.
floor
((
Math
.
random
()
*
max
)
+
min
);
// for (let i=0;i<ranNumArr.length;i++){
// if (ranNumArr[i]==newNum){
// newNum = Math.floor((Math.random()*max)+min);
// }
// }
let
zeroSize
=
""
;
for
(
let
j
=
0
;
j
<
5
-
newNum
.
toString
().
length
;
j
++
){
zeroSize
+=
"
0
"
;
}
// setRanNumArr(zeroSize+newNum);
return
(
zeroSize
+
newNum
.
toString
());
}
export
default
randCode
;
\ No newline at end of file
server/controllers/room.controller.js
View file @
4c6f4efe
...
@@ -7,9 +7,7 @@ import EntryLog from "../models/EntryLog.js"
...
@@ -7,9 +7,7 @@ import EntryLog from "../models/EntryLog.js"
const
nanoid
=
customAlphabet
(
'
1234567890abcdef
'
,
10
)
const
nanoid
=
customAlphabet
(
'
1234567890abcdef
'
,
10
)
const
makeRoom
=
async
(
req
,
res
)
=>
{
const
makeRoom
=
async
(
req
,
res
)
=>
{
// console.log(req.body)
const
{
roomName
,
interest
,
isOpen
,
member
}
=
req
.
body
;
const
{
roomName
,
interest
,
isOpen
,
member
}
=
req
.
body
;
// console.log('콘솔확인', roomName, interest, isOpen, member)
const
roomId
=
nanoid
()
const
roomId
=
nanoid
()
const
room
=
await
Room
.
findOne
({
roomId
})
const
room
=
await
Room
.
findOne
({
roomId
})
while
(
room
)
{
while
(
room
)
{
...
@@ -30,7 +28,6 @@ const makeRoom = async (req, res) => {
...
@@ -30,7 +28,6 @@ const makeRoom = async (req, res) => {
isOpen
,
isOpen
,
member
,
member
,
}).
save
()
}).
save
()
// console.log(newRoom)
res
.
json
(
newRoom
)
res
.
json
(
newRoom
)
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
...
@@ -58,11 +55,9 @@ const getOpenList = async (req, res) => {
...
@@ -58,11 +55,9 @@ const getOpenList = async (req, res) => {
const
getRoomName
=
async
(
req
,
res
)
=>
{
const
getRoomName
=
async
(
req
,
res
)
=>
{
const
roomId
=
req
.
query
.
roomCode
const
roomId
=
req
.
query
.
roomCode
// console.log('getRoomName', req.query.roomCode)
try
{
try
{
let
roominfo
=
await
Room
.
findOne
({
roomId
:
roomId
}).
select
(
'
roomName
'
)
let
roominfo
=
await
Room
.
findOne
({
roomId
:
roomId
}).
select
(
'
roomName
'
)
// console.log(roominfo.roomName)
return
res
.
json
(
roominfo
.
roomName
)
return
res
.
json
(
roominfo
.
roomName
)
}
catch
(
error
)
{
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
'
리스트 불러오기를 실패하였습니다!
'
)
res
.
status
(
500
).
send
(
'
리스트 불러오기를 실패하였습니다!
'
)
...
@@ -71,14 +66,12 @@ const getRoomName = async (req, res) => {
...
@@ -71,14 +66,12 @@ const getRoomName = async (req, res) => {
const
changemember
=
async
(
req
,
res
)
=>
{
const
changemember
=
async
(
req
,
res
)
=>
{
const
{
userId
,
roomId
}
=
req
.
body
const
{
userId
,
roomId
}
=
req
.
body
// console.log(roomId)
let
room
=
await
Room
.
findOne
({
roomId
:
roomId
}).
select
(
'
member
'
)
let
room
=
await
Room
.
findOne
({
roomId
:
roomId
}).
select
(
'
member
'
)
const
isPresent
=
room
.
member
.
indexOf
(
userId
)
const
isPresent
=
room
.
member
.
indexOf
(
userId
)
try
{
try
{
if
(
isPresent
<
0
)
{
if
(
isPresent
<
0
)
{
const
memberId
=
room
.
member
.
push
(
userId
)
const
memberId
=
room
.
member
.
push
(
userId
)
await
Room
.
updateOne
({
'
roomId
'
:
roomId
},
{
'
member
'
:
room
.
member
})
await
Room
.
updateOne
({
'
roomId
'
:
roomId
},
{
'
member
'
:
room
.
member
})
// console.log('room.member 업데이트 완료')
return
res
.
json
(
true
)
return
res
.
json
(
true
)
}
}
else
{
else
{
...
@@ -90,15 +83,12 @@ const changemember = async (req, res) => {
...
@@ -90,15 +83,12 @@ const changemember = async (req, res) => {
}
}
const
deleteUserId
=
async
(
req
,
res
)
=>
{
const
deleteUserId
=
async
(
req
,
res
)
=>
{
// console.log(req.body)
const
{
userId
,
roomId
}
=
req
.
body
const
{
userId
,
roomId
}
=
req
.
body
let
room
=
await
Room
.
findOne
({
roomId
:
roomId
}).
select
(
'
member
'
)
let
room
=
await
Room
.
findOne
({
roomId
:
roomId
}).
select
(
'
member
'
)
// console.log('deletetest', room)
const
memIndex
=
room
.
member
.
indexOf
(
userId
)
const
memIndex
=
room
.
member
.
indexOf
(
userId
)
try
{
try
{
room
.
member
.
splice
(
memIndex
,
1
)
room
.
member
.
splice
(
memIndex
,
1
)
await
Room
.
updateOne
({
'
roomId
'
:
roomId
},
{
'
member
'
:
room
.
member
})
await
Room
.
updateOne
({
'
roomId
'
:
roomId
},
{
'
member
'
:
room
.
member
})
// console.log(`${roomId}방 ${userId}삭제완료`)
return
res
.
json
(
true
)
return
res
.
json
(
true
)
}
catch
(
error
)
{
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
'
멤버 업데이트 실패
'
)
res
.
status
(
500
).
send
(
'
멤버 업데이트 실패
'
)
...
...
server/routes/user.routes.js
View file @
4c6f4efe
...
@@ -2,7 +2,6 @@ import express from 'express'
...
@@ -2,7 +2,6 @@ import express from 'express'
import
userCtrl
from
'
../controllers/user.controller.js
'
import
userCtrl
from
'
../controllers/user.controller.js
'
const
router
=
express
.
Router
()
const
router
=
express
.
Router
()
//router의 역할 : './주소'부분을 처리하는 역할함.
router
.
route
(
'
/users/signup
'
)
router
.
route
(
'
/users/signup
'
)
.
post
(
userCtrl
.
signup
)
.
post
(
userCtrl
.
signup
)
...
...
server/server.js
View file @
4c6f4efe
...
@@ -23,21 +23,17 @@ io.on("connection", (socket) => { // 기본 연결
...
@@ -23,21 +23,17 @@ 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했을 때
// console.log('join_data확인', data)
let
roomInfo
=
data
;
let
roomInfo
=
data
;
socket
.
join
(
roomInfo
);
//클라이언트에서 data에 적힌 room으로 참여시킴
socket
.
join
(
roomInfo
);
//클라이언트에서 data에 적힌 room으로 참여시킴
});
});
socket
.
on
(
'
closeRoom
'
,
(
data
)
=>
{
socket
.
on
(
'
closeRoom
'
,
(
data
)
=>
{
// console.log('close_data확인', data)
let
roomInfo
=
data
;
let
roomInfo
=
data
;
socket
.
leave
(
roomInfo
);
//클라이언트에서 data에 적힌 room정보를 브로드캐스팅 받지 않는다.
socket
.
leave
(
roomInfo
);
//클라이언트에서 data에 적힌 room정보를 브로드캐스팅 받지 않는다.
});
});
socket
.
on
(
'
chat
'
,
async
(
data
)
=>
{
socket
.
on
(
'
chat
'
,
async
(
data
)
=>
{
// console.log('roomname확인', data)
const
room
=
await
Room
.
findOne
({
roomId
:
data
.
roomInfo
})
const
room
=
await
Room
.
findOne
({
roomId
:
data
.
roomInfo
})
// console.log('room이 떴나', room)
const
chat
=
await
new
Chat
({
const
chat
=
await
new
Chat
({
room
:
room
.
_id
,
room
:
room
.
_id
,
...
@@ -45,7 +41,6 @@ io.on("connection", (socket) => { // 기본 연결
...
@@ -45,7 +41,6 @@ io.on("connection", (socket) => { // 기본 연결
message
:
data
.
sendInfo
.
msg
,
message
:
data
.
sendInfo
.
msg
,
profileimg
:
data
.
sendInfo
.
img
profileimg
:
data
.
sendInfo
.
img
}).
save
()
}).
save
()
// console.log('resChat확인', chat)
socket
.
broadcast
.
to
(
data
.
roomInfo
).
emit
(
'
sendedMSG
'
,
data
.
sendInfo
);
// sender 제외 특정 방으로
socket
.
broadcast
.
to
(
data
.
roomInfo
).
emit
(
'
sendedMSG
'
,
data
.
sendInfo
);
// sender 제외 특정 방으로
socket
.
broadcast
.
emit
(
'
checking
'
,
data
.
sendInfo
)
// 메세지를 어딘가에서 보냈다는 신호
socket
.
broadcast
.
emit
(
'
checking
'
,
data
.
sendInfo
)
// 메세지를 어딘가에서 보냈다는 신호
...
@@ -70,4 +65,3 @@ server.listen(3030, () => {
...
@@ -70,4 +65,3 @@ server.listen(3030, () => {
})
})
export
default
server
export
default
server
\ No newline at end of file
// module.exports = server;
\ No newline at end of file
uploads/3b8d5577ccb787fffa189ad4b9408e95
0 → 100644
View file @
4c6f4efe
File added
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