1 | var io = require('socket.io').listen(5000); |
||
2 | var clients = {}; |
||
3 | |||
4 | var verboseServer = false; //Good for debugging the server |
||
5 | |||
6 | verboseServer && console.log("ChatServer Started"); //If Verbose Debug |
||
0 ignored issues
–
show
Debugging Code
introduced
by
![]() |
|||
7 | io.sockets.on('connection', function (socket) { |
||
8 | verboseServer && console.log("New Connection"); //If Verbose Debug |
||
0 ignored issues
–
show
|
|||
9 | var userName; |
||
10 | socket.on('connection name',function(user){ |
||
11 | verboseServer && console.log("Connection Name"); //If Verbose Debug |
||
0 ignored issues
–
show
|
|||
12 | userName = user.name; |
||
13 | clients[user.name] = socket; |
||
14 | io.sockets.emit('new user', user.name + " has joined."); |
||
15 | }); |
||
16 | |||
17 | |||
18 | socket.on('message', function(msg){ |
||
19 | verboseServer && console.log("New msg"); //If Verbose Debug |
||
0 ignored issues
–
show
|
|||
20 | io.sockets.emit('message', msg); |
||
21 | }); |
||
22 | |||
23 | socket.on('private message', function(msg){ |
||
24 | verboseServer && console.log("New PM"); //If Verbose Debug |
||
0 ignored issues
–
show
|
|||
25 | fromMsg = {from:userName, txt:msg.txt} |
||
0 ignored issues
–
show
|
|||
26 | clients[msg.to].emit('private message', fromMsg); |
||
27 | }); |
||
28 | |||
29 | socket.on('disconnect', function(){ |
||
30 | verboseServer && console.log("disconnect"); //If Verbose Debug |
||
0 ignored issues
–
show
|
|||
31 | delete clients[userName]; |
||
32 | }); |
||
33 | }); |
||
34 |