Toggle navigation
Toggle navigation
This project
Loading...
Sign in
최시원
/
Singer-Composer
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Mukho
2021-11-26 16:22:40 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8b0b097e816dc5798ff3b97ad4b104292e9e4ea0
8b0b097e
1 parent
6bae359b
fix before pull
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
33 deletions
app.js
js/chat.js
readme.md
app.js
View file @
8b0b097
...
...
@@ -24,7 +24,7 @@ var LocalStrategy = require('passport-local').Strategy
var
session
=
require
(
'express-session'
)
var
flash
=
require
(
'connect-flash'
)
var
path
=
require
(
'path'
)
const
PORT
=
300
3
const
PORT
=
300
0
var
jsdom
=
require
(
'jsdom'
);
const
{
JSDOM
}
=
jsdom
;
...
...
@@ -74,6 +74,7 @@ var session = session({
app
.
use
(
session
);
var
sharedsession
=
require
(
"express-socket.io-session"
);
const
{
createSocket
}
=
require
(
'dgram'
)
io
.
use
(
sharedsession
(
session
,
{
autoSave
:
true
}));
app
.
use
(
passport
.
initialize
())
...
...
@@ -113,16 +114,16 @@ io.sockets.on('connection', function(socket) {
}
else
{
console
.
log
(
logString
+
'익명 유저의 채팅 전송을 거부했습니다.('
+
ip
+
')'
)
//
//
}
})
/* 접속 종료 */
socket
.
on
(
'disconnect'
,
function
()
{
if
(
socket
.
name
!=
undefined
){
console
.
log
(
logString
+
socket
.
name
+
' 님이 나가셨습니다.'
)
/* 나가는 사람을 제외한 나머지 유저에게 메시지 전송 */
socket
.
broadcast
.
emit
(
'update'
,
{
type
:
'disconnect'
,
name
:
'SERVER'
,
message
:
socket
.
name
+
'님이 나가셨습니다.'
});
socket
.
broadcast
.
emit
(
'update'
,
{
type
:
'disconnect'
,
name
:
'SERVER'
,
message
:
socket
.
name
+
'님이 나가셨습니다.'
});
}
})
})
...
...
js/chat.js
View file @
8b0b097
...
...
@@ -10,41 +10,42 @@ socket.on('connect', function() {
/* 서버로부터 데이터 받은 경우 */
socket
.
on
(
'update'
,
function
(
data
)
{
var
chat
=
document
.
getElementById
(
'chat'
)
var
chat
=
document
.
getElementById
(
'chat'
)
var
message
=
document
.
createElement
(
'div'
)
var
node
;
if
(
data
.
name
!=
"SERVER"
){
node
=
document
.
createTextNode
(
`
${
data
.
name
}
:
${
data
.
message
}
`
)
}
else
{
node
=
document
.
createTextNode
(
`
${
data
.
message
}
`
)
}
var
className
=
''
var
message
=
document
.
createElement
(
'div'
)
var
node
;
if
(
data
.
name
!=
"SERVER"
){
node
=
document
.
createTextNode
(
`
${
data
.
name
}
:
${
data
.
message
}
`
)
}
else
{
node
=
document
.
createTextNode
(
`
${
data
.
message
}
`
)
}
var
className
=
''
// 타입에 따라 적용할 클래스를 다르게 지정
switch
(
data
.
type
)
{
case
'message'
:
className
=
'other'
break
// 타입에 따라 적용할 클래스를 다르게 지정
switch
(
data
.
type
)
{
case
'message'
:
className
=
'other'
break
case
'connect'
:
className
=
'connect'
break
case
'connect'
:
className
=
'connect'
break
case
'disconnect'
:
className
=
'disconnect'
break
}
case
'disconnect'
:
className
=
'disconnect'
break
}
message
.
classList
.
add
(
className
)
message
.
appendChild
(
node
)
chat
.
appendChild
(
message
)
message
.
classList
.
add
(
className
)
message
.
appendChild
(
node
)
chat
.
appendChild
(
message
)
function
a
(
chat
=
'chat'
){
var
element
=
document
.
getElementById
(
chat
);
element
.
scrollTop
=
element
.
scrollHeight
-
element
.
clientHeight
;
}
a
();
function
a
(
chat
=
'chat'
){
var
element
=
document
.
getElementById
(
chat
);
element
.
scrollTop
=
element
.
scrollHeight
-
element
.
clientHeight
;
}
a
();
})
/* 메시지 전송 함수 */
...
...
readme.md
View file @
8b0b097
...
...
@@ -63,6 +63,7 @@ create table board(
---
### 최종 수정: 2021-11-25 20:24<br>
### 수정 내용:
0.
채팅 중 서버 재시작시 기존 참여자들 리셋시키기 이슈
1.
채팅 구현
2.
시간 실시간 반영
3.
프로필 사진 추가
...
...
Please
register
or
login
to post a comment