-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathindex.js
44 lines (30 loc) · 900 Bytes
/
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
'use strict';
const io = require('socket.io').listen(50000);
io.sockets.on('connection', socket => {
socket.emit('connection', {
type : 'connected'
});
socket.on('connection', data => {
if(data.type === 'join') {
socket.join(data.room);
// depracated
// socket.set('room', data.room);
socket.room = data.room;
socket.emit('system', {
message : 'welcome to chat room'
});
socket.broadcast.to(data.room).emit('system', {
message : `${data.name} is connected`
});
}
});
socket.on('user', data => {
// depracated
// socket.get('room', (error, room) => {
// });
var room = socket.room;
if(room) {
socket.broadcast.to(room).emit('message', data);
}
});
});