Class: WebsocketRouter

WebsocketRouter(websocket, routerId)

Class for websocket funcionalities associated with routers.

Constructor

new WebsocketRouter(websocket, routerId)

Create a WebsocketRouter.

Parameters:
Name Type Description
websocket object

The websocket server that the router will be attahced to.

routerId string

The id of the router 'usually its name'. Had to be known by the client user to be able to sucessfully connect.

Source:

Methods

disconnect(error)

Forcefully disconnects all connected users (they got a notification).

Parameters:
Name Type Description
error Error

The error that describes the reason for disconnect.

Source:

getRoomId() → {string}

Returns the websocket room id.

Source:
Returns:

The full id of the websocket room that is used to separate users of this router.

Type
string

getRouterId() → {string}

Returns the websocket router id.

Source:
Returns:

The router id of the router.

Type
string

onConnect(handleFn)

Sets the event handling function of user connect.

Parameters:
Name Type Description
handleFn function

The function that needs to be called when a user connects. The function should handle two arguments. The first will be a WebsocketRouterUser object, while the second is a callback (highlighting with an error object if we accept the connection).

Source:

send(payload)

Broadcasts a message to all connected users.

Parameters:
Name Type Description
payload object

The content object of the message (has to be stringifiable!).

Source: