Skip to content
Snippets Groups Projects
Commit 1f5980fa authored by Atanamo's avatar Atanamo
Browse files

Fix socket.io change on room's socket list

This change isn't even listed in the changelog, but fatal:
io.sockets.adapter.rooms[<room name>] seems to be an Object of type Room now, having a the list of its sockets in an property "sockets".
Before version 1.4.0, the map of sockets was directly accessable by the call (there was no Room object)...

Moved logic for iterating the room's sockets to a new method _iterateEachJoinedSocket() though. So future changes to the API (which are very likely) can be modified on one place in the code...
parent e3742ca3
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -192,13 +192,9 @@ class Channel
@_sendToRoom('deleted', deleteInfo, false)
 
# Kick all sockets out of room
clientMetaList = io.sockets.adapter.rooms[@name]
for clientID of clientMetaList
currClientSocket = io.sockets.connected[clientID] # This is the socket of each client in the room
if currClientSocket?
@_unregisterListeners(currClientSocket)
currClientSocket.leave(@name)
@_iterateEachJoinedSocket (currClientSocket) =>
@_unregisterListeners(currClientSocket)
currClientSocket.leave(@name)
 
# Update the list of unique identities (Should now be empty)
@_updateUniqueClientsMap()
Loading
Loading
@@ -365,16 +361,10 @@ class Channel
 
_getUniqueClientsMap: (forceUpdate=false) ->
if forceUpdate
#clientSocketList = io.sockets.clients(@name) # Working till v0.9.x
clientMetaList = io.sockets.adapter.rooms[@name]
clientsMap = {}
for clientID of clientMetaList
clientSocket = io.sockets.connected[clientID] # This is the socket of each client in the room
if clientSocket?
clientIdentity = clientSocket.identity
clientsMap[clientIdentity.getGlobalID()] = clientIdentity if clientIdentity?
@_iterateEachJoinedSocket (clientSocket) =>
clientIdentity = clientSocket.identity
clientsMap[clientIdentity.getGlobalID()] = clientIdentity if clientIdentity?
else
clientsMap = @uniqueClientsMap or {}
 
Loading
Loading
@@ -393,6 +383,17 @@ class Channel
 
return userList
 
_iterateEachJoinedSocket: (iterationCallback) ->
#clientSocketList = io.sockets.clients(@name) # Working till v0.9.x
clientMetaList = io.sockets.adapter.rooms[@name]
clientMetaList = clientMetaList?.sockets or clientMetaList or {} # There's no sockets property till v0.3.x
for clientID of clientMetaList
clientSocket = io.sockets.connected[clientID] # This is the socket of each client in the room
# Call back on every real socket
iterationCallback(clientSocket) if clientSocket?
 
 
## Export class
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment