|
|
@ -12,6 +12,8 @@ wss.broadcast = function(data) {
|
|
12
|
12
|
wss.on('connection', function(ws) {
|
|
13
|
13
|
var name = randomName();
|
|
14
|
14
|
|
|
|
15
|
wss.broadcast({type: "connect", author: name, timestamp: Date.now()});
|
|
|
16
|
|
|
15
|
17
|
ws.on('message', function(msg) {
|
|
16
|
18
|
var msg = JSON.parse(msg);
|
|
17
|
19
|
msg.author = name;
|
|
|
@ -21,12 +23,7 @@ wss.on('connection', function(ws) {
|
|
21
|
23
|
});
|
|
22
|
24
|
|
|
23
|
25
|
ws.on('close', function() {
|
|
24
|
|
var msg = {
|
|
25
|
|
type: "disconnect",
|
|
26
|
|
author: name,
|
|
27
|
|
timestamp: Date.now()
|
|
28
|
|
};
|
|
29
|
|
wss.broadcast(msg);
|
|
|
26
|
wss.broadcast({type: "disconnect", author: name, timestamp: Date.now()});
|
|
30
|
27
|
});
|
|
31
|
28
|
});
|
|
32
|
29
|
|