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
devsho
2021-11-26 16:35:59 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
93c81f0188e1c460fdb785f4a6bc55ccac296fec
93c81f01
2 parents
2befeb6d
a071ea18
Merge branch 'master' of
http://khuhub.khu.ac.kr/2017104034/Singer-Composer
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
34 deletions
app.js
js/chat.js
readme.md
router/board/index.js
app.js
View file @
93c81f0
...
...
@@ -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 @
93c81f0
...
...
@@ -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 @
93c81f0
...
...
@@ -70,8 +70,9 @@ create table comment(
>UPDATE board SET idx = @COUNT:=@COUNT+1;
---
### 최종 수정: 2021-11-26
04:42
<br>
### 최종 수정: 2021-11-26
16:26
<br>
### 수정 내용:
0.
채팅 중 서버 재시작시 기존 참여자들 리셋시키기 이슈
1.
채팅 구현
2.
시간 실시간 반영
3.
프로필 사진 추가
...
...
router/board/index.js
View file @
93c81f0
...
...
@@ -147,6 +147,7 @@ router.post('/read/commentwrite', function(req,res,next){
board
.
query
(
sql
,
datas
,
function
(
err
,
row
){
if
(
err
)
console
.
error
(
"err : "
+
err
);
})
console
.
log
(
logString
+
req
.
user
.
ID
+
'('
+
nickname
+
') 유저가 '
+
idx
+
'번 게시물에 댓글을 작성했습니다.('
+
ip
+
')'
)
res
.
redirect
(
'/board/read/'
+
idx
);
})
...
...
Please
register
or
login
to post a comment