Sockets

server. Sockets

Manage all server.Socket instances.

Important: In most cases, you should consider using a client.SharedState rather than directly using the Socket instance.

Constructor

new Sockets()

Source:

Methods

addToRoom(socket, roomId)

Description:
  • Add a socket to a room.

    Note that in most cases, you should use a shared state instead

Source:
Parameters:
Name Type Description
socket server.Socket

Socket to add to the room.

roomId String

Id of the room.

broadcast(roomsIds, excludeSocket, channel, …args)

Description:
  • Send a message to all clients os given room(s). If no room is specified, the message is sent to all clients.

    Note that in most cases, you should use a shared state instead

Source:
Parameters:
Name Type Attributes Description
roomsIds String | Array

Ids of the rooms that must receive the message. If null the message is sent to all clients.

excludeSocket server.Socket

Optionnal socket to ignore when broadcasting the message, typically the client at the origin of the message.

channel String

Channel name.

args * <repeatable>

Payload of the message. As many arguments as needed, of JSON compatible data types (i.e. string, number, boolean, object, array and null).

kSocketsRemoveFromAllRooms()

Description:
  • Remove given socket from all rooms.

Source:

removeFromRoom(socket, roomId)

Description:
  • Remove a socket from a room.

    Note that in most cases, you should use a shared state instead

Source:
Parameters:
Name Type Description
socket server.Socket

Socket to remove from the room.

roomId String

Id of the room.