-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·49 lines (32 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var txt = "2137"
const express = require('express'),
http = require('http'),
app = express(),
server = http.createServer(app),
io = require('socket.io').listen(server);
app.get('/', (req, res) => {
res.send('Chat Server is running on port 2137')
});
io.on('connection', (socket) => {
socket.on('join', function(userNickname) {
//console log
console.log("user has joined the chat");
//text on join
let message = {"message":"txt: "+ "dołączył(a) do serwera! Uważaj!"}
io.emit('message', message);
//restore message to user who's joined
message = {"message":txt}
io.emit('message', message);
})
socket.on('messagedetection', (senderNickname,messageContent) => {
//log the message in console
console.log(messageContent)
//create a message object
let message = {"message":messageContent}
io.emit('message', message )
txt = messageContent;
})
})
server.listen(2137,()=>{
console.log('Node app is running on port 2137')
})