@@ -12,7 +12,7 @@ module.exports = (io, socket) => {
12
12
return data ;
13
13
}
14
14
15
- // When the client emits 'sockets'
15
+ // When the client emits 'sockets'.
16
16
const onSockets = ( ) => {
17
17
let data = getSockets ( ) ;
18
18
socket . emit ( constants . SOCKETS , {
@@ -21,30 +21,30 @@ module.exports = (io, socket) => {
21
21
} ) ;
22
22
} ;
23
23
24
- // When the client connects
25
- const onConnect = ( username ) => {
24
+ // When the client connects.
25
+ const onClientConnected = ( username ) => {
26
26
27
- // store the username in the socket session for the client
27
+ // Store the username in the socket session for the client.
28
28
socket . data . username = username ;
29
29
30
30
socket . emit ( constants . USER_LOGIN , {
31
31
socketId : socket . id ,
32
32
data : getSockets ( )
33
33
} ) ;
34
34
35
- // broadcast globally that the client has joined
35
+ // Broadcast globally that the client has joined.
36
36
console . log ( 'User %s has connected; socketId %s' , socket . data . username , socket . id ) ;
37
37
socket . broadcast . emit ( constants . USER_JOINED , {
38
38
socketId : socket . id ,
39
- usercount : io . sockets . sockets . size ,
40
- username : socket . data . username
39
+ username : socket . data . username ,
40
+ usercount : io . sockets . sockets . size
41
41
} ) ;
42
42
}
43
43
44
- // when the client disconnects
44
+ // When the client disconnects.
45
45
const onDisconnect = ( ) => {
46
46
47
- // broadcast globally that the client has disconnected
47
+ // Broadcast globally that the client has disconnected.
48
48
console . log ( 'User %s has disconnected; socketId %s' , socket . data . username , socket . id ) ;
49
49
socket . broadcast . emit ( constants . USER_LEFT , {
50
50
socketId : socket . id ,
@@ -53,7 +53,7 @@ module.exports = (io, socket) => {
53
53
} ) ;
54
54
}
55
55
56
- socket . on ( constants . SOCKETS , onSockets ) ;
56
+ socket . on ( constants . USER_ADD , onClientConnected ) ;
57
57
socket . on ( constants . DISCONNECT , onDisconnect ) ;
58
- socket . on ( constants . USER_ADD , onConnect ) ;
58
+ socket . on ( constants . SOCKETS , onSockets ) ;
59
59
}
0 commit comments