Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Jeongmin Seo
/
favorite_restaurant
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
Jumi Yang
2022-06-05 22:41:23 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
46edde80a76ce532724169b227f4709265e57527
46edde80
1 parent
67f92772
Update chatting feature
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
65 additions
and
35 deletions
chat/app.js → chat/app/app.js
chat/app/package-lock.json
chat/package.json → chat/app/package.json
chat/app/src/css/style.css
chat/app/src/index.html
chat/app/src/js/chat.js
chat/app.js
→
chat/app
/app
.js
View file @
46edde8
...
...
@@ -4,6 +4,8 @@ const app = express();
const
path
=
require
(
"path"
)
const
server
=
http
.
createServer
(
app
);
const
socketIO
=
require
(
"socket.io"
)
const
moment
=
require
(
"moment"
)
const
io
=
socketIO
(
server
);
...
...
@@ -12,7 +14,12 @@ const PORT = process.env.PORT || 3000;
io
.
on
(
'connection'
,
(
socket
)
=>
{
socket
.
on
(
"chatting"
,
(
data
)
=>
{
io
.
emit
(
"chatting"
,
data
)
const
{
name
,
msg
}
=
data
;
io
.
emit
(
"chatting"
,
{
name
,
msg
,
time
:
moment
.
format
(
"h:ss A"
)
})
})
});
...
...
chat/app/package-lock.json
0 → 100644
View file @
46edde8
This diff is collapsed. Click to expand it.
chat/package.json
→
chat/
app/
package.json
View file @
46edde8
...
...
@@ -4,12 +4,14 @@
"description"
:
""
,
"main"
:
"index.js"
,
"scripts"
:
{
"start"
:
"nodemon ./app.js"
,
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
},
"keywords"
:
[],
"author"
:
""
,
"license"
:
"ISC"
,
"dependencies"
:
{
"dayjs"
:
"^1.11.2"
,
"express"
:
"^4.18.1"
,
"moment"
:
"^2.29.3"
,
"socket.io"
:
"^4.5.1"
...
...
chat/app/src/css/style.css
View file @
46edde8
...
...
@@ -16,7 +16,7 @@ html, body {
}
.user-container
{
background
:
#a9bdc
e
;
background
:
rebeccapurpl
e
;
flex
:
1
;
display
:
flex
;
justify-content
:
flex-start
;
...
...
@@ -24,19 +24,21 @@ html, body {
padding
:
0.5rem
;
}
.user-container
label
{
.user-container
.nickname
{
font-size
:
14px
;
margin-right
:
1rem
;
margin-right
:
1.5rem
;
margin-left
:
1rem
;
color
:
#fff
;
}
.user-container
input
{
border-radius
:
3px
;
border
:
none
;
height
:
10
0%
;
height
:
8
0%
;
}
.display-container
{
background
:
#
b2c7d9
;
background
:
#
D2D2FF
;
flex
:
12
;
overflow-y
:
scroll
;
}
...
...
@@ -65,14 +67,15 @@ html, body {
.send-button
{
flex
:
1
;
background
:
#ffeb33
;
background
:
rebeccapurple
;
color
:
#fff
;
border
:
none
;
height
:
100%
;
border-radius
:
3px
;
}
.chatting-list
li
{
width
:
9
0%
;
width
:
5
0%
;
padding
:
0.3rem
;
display
:
flex
;
justify-content
:
flex-start
;
...
...
@@ -105,7 +108,7 @@ html, body {
padding
:
0.5rem
;
font-size
:
12px
;
margin
:
0
5px
;
flex
:
7
;
flex
:
10
;
}
.time
{
...
...
@@ -119,7 +122,8 @@ html, body {
}
.sent
.message
{
background
:
#ffeb33
;
background
:
#9986EE
;
color
:
#fff
;
}
.received
.message
{
...
...
chat/app/src/index.html
View file @
46edde8
...
...
@@ -10,27 +10,12 @@
<body>
<div
class=
"wrapper"
>
<div
class=
"user-container"
>
<lable
for=
"nickname"
>
대화명
</lable>
<lable
class=
"nickname"
for=
"nickname"
>
닉네임설정
</lable>
<input
type=
"text"
id=
"nickname"
>
</div>
<div
class=
"display-container"
>
<ul
class=
"chatting-list"
>
<li
class=
"sent"
>
<span
class=
"profile"
>
<span
class=
"user"
>
깔깔
</span>
<img
class=
"image"
src=
"https://placeimg.com/50/50/any"
alt=
"any"
>
</span>
<span
class=
"message"
>
그래 반가워
</span>
<span
class=
"time"
>
오후 2:10
</span>
</li>
<li
class=
"received"
>
<span
class=
"profile"
>
<span
class=
"user"
>
깔깔
</span>
<img
class=
"image"
src=
"https://placeimg.com/50/50/any"
alt=
"any"
>
</span>
<span
class=
"message"
>
그래 반가워
</span>
<span
class=
"time"
>
오후 2:10
</span>
</li>
</ul>
</div>
<div
class=
"input-container"
>
...
...
@@ -41,7 +26,7 @@
</div>
</div>
<
!-- <
script src="/socket.io/socket.io.js"></script>
<script src="js/chat.js"></script>
-->
<script
src=
"/socket.io/socket.io.js"
></script>
<script
src=
"js/chat.js"
></script>
</body>
</html>
\ No newline at end of file
...
...
chat/app/src/js/chat.js
View file @
46edde8
...
...
@@ -5,18 +5,50 @@ const nickname = document.querySelector("#nickname")
const
chatlist
=
document
.
querySelector
(
".chatting-list"
)
const
chatInput
=
document
.
querySelector
(
".chatting-input"
)
const
sendButton
=
document
.
querySelector
(
".send-button"
)
const
displayContainer
=
document
.
querySelector
(
".display-container"
)
sendButton
.
addEventListener
(
"click"
,
()
=>
{
chatInput
.
addEventListener
(
"keypress"
,
(
event
)
=>
{
if
(
event
.
keyCode
===
13
)
{
send
()
}
})
function
send
()
{
const
param
=
{
name
:
nickname
.
value
,
msg
:
chatInput
.
value
}
socket
.
emit
(
"chatting"
,
param
)
});
}
sendButton
.
addEventListener
(
"click"
,
send
)
socket
.
on
(
"chatting"
,
(
data
)
=>
{
const
li
=
document
.
createElement
(
"li"
);
li
.
innerText
=
`
${
data
.
name
}
님이 -
${
data
.
msg
}
`
;
chatlist
.
appendChild
(
li
)
console
.
log
(
data
)
const
{
name
,
msg
,
time
}
=
data
;
const
item
=
new
LiModel
(
name
,
msg
,
time
);
item
.
makeLi
()
displayContainer
.
scrollTo
(
0
,
displayContainer
.
scrollHeight
)
})
console
.
log
(
socket
);
\ No newline at end of file
//console.log(socket);
function
LiModel
(
name
,
msg
,
time
)
{
this
.
name
=
name
;
this
.
msg
=
msg
;
this
.
time
=
time
;
this
.
makeLi
=
()
=>
{
const
li
=
document
.
createElement
(
"li"
);
li
.
classList
.
add
(
nickname
.
value
===
this
.
name
?
"sent"
:
"received"
)
const
dom
=
`<span class="profile">
<span class="user">
${
this
.
name
}
</span>
<img class="image" src="https://placeimg.com/50/50/any" alt="any">
</span>
<span class="message">
${
this
.
msg
}
</span>
<span class="time">
${
this
.
time
}
</span>`
;
li
.
innerHTML
=
dom
;
chatlist
.
appendChild
(
li
)
}
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment