   removeSocketFromRoom : (id, roomName) ->
     roomsset = @socketsToRooms.get id
     socketsset = @roomsToSockets.get roomName
-    roomsset.delete roomName
+    roomsset?.delete roomName
     socketsset?.delete id
     njoined = socketsset?.length || 0
     Promise.resolve njoined

    sockets = @socketsToRooms.keys()
    for id in sockets
      socketsset = @socketsToRooms.get id
      result[id] = socketsset.toArray()
    Promise.resolve result

  # @private

  removeAllSocketsFromRoom : (roomName) ->
    sockets = @socketsToRooms.keys()
    socketsset = @roomsToSockets.get roomName
    removedSockets = socketsset?.toArray() || []
    for id in removedSockets
      roomsset = @socketsToRooms.get id
      roomsset.delete roomName
    if socketsset
      socketsset = socketsset.difference sockets
      @roomsToSockets.set roomName, socketsset
    Promise.resolve removedSockets

  # @private
  removeSocket : (id) ->
    rooms = @roomsToSockets.toArray()
    roomsset = @socketsToRooms.get id
    removedRooms = roomsset?.toArray() || []
    joinedSockets = []
    for roomName, idx in removedRooms
      socketsset = @roomsToSockets.get roomName
