v0.9.5
Class: WebSocketManager
Table of contents
Constructors
Methods
- disconnectPlayer
- distributePlayerUpdate
- distributePlayerUpdates
- getConnectedPlayerCount
- getDisconnectedPlayers
- getPlayer
- getReconnectionTimeout
- setReconnectionTimeout
Constructors
constructor
⢠new WebSocketManager(server, eventBus, messageRouter, gameManager, authModule?, reconnectionTimeoutMs?, lobby?, tableFactory?): WebSocketManager
Parameters
| Name | Type | Default value |
|---|---|---|
server | Server<typeof IncomingMessage, typeof ServerResponse> | undefined |
eventBus | EventBus | undefined |
messageRouter | MessageRouter | undefined |
gameManager | GameManager | undefined |
authModule? | AuthModule | undefined |
reconnectionTimeoutMs | number | 0 |
lobby? | Lobby | undefined |
tableFactory? | TableFactory | undefined |
Returns
Methods
disconnectPlayer
⸠disconnectPlayer(playerId): void
Disconnects a player by their ID without waiting for timeout. This bypasses the reconnection timeout and immediately removes the player.
Parameters
| Name | Type | Description |
|---|---|---|
playerId | string | The ID of the player to disconnect. |
Returns
void
distributePlayerUpdate
⸠distributePlayerUpdate(player, key, value, updateTableState?): void
Distribute player updates to relevant players. This notifies the player about their own changes and also updates any tables theyâre part of.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
player | Player | undefined | The player whose state changed |
key | string | undefined | The attribute that changed |
value | any | undefined | The new value |
updateTableState | boolean | true | Whether to update the table state |
Returns
void
distributePlayerUpdates
⸠distributePlayerUpdates(player, attributes, updateTableState?): void
Distribute multiple player updates to relevant players.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
player | Player | undefined | The player whose state changed |
attributes | Record<string, any> | undefined | The attributes that changed |
updateTableState | boolean | true | Whether to update the table state |
Returns
void
getConnectedPlayerCount
⸠getConnectedPlayerCount(): number
Gets the current number of connected players.
Returns
number
The number of connected players
getDisconnectedPlayers
⸠getDisconnectedPlayers(): { disconnectedAt: number ; id: string ; reconnectionAvailableUntil: number ; timeLeftMs: number }[]
Gets information about temporarily disconnected players. This is useful for monitoring and debugging connection issues.
Returns
{ disconnectedAt: number ; id: string ; reconnectionAvailableUntil: number ; timeLeftMs: number }[]
Array of objects containing information about disconnected players
getPlayer
⸠getPlayer(playerId): undefined | Player
Gets a player by their ID.
Parameters
| Name | Type | Description |
|---|---|---|
playerId | string | The ID of the player to get. |
Returns
undefined | Player
The player object or undefined if the player does not exist.
getReconnectionTimeout
⸠getReconnectionTimeout(): number
Gets the current reconnection timeout in milliseconds
Returns
number
setReconnectionTimeout
⸠setReconnectionTimeout(timeoutMs): void
Sets the reconnection timeout in milliseconds
Parameters
| Name | Type | Description |
|---|---|---|
timeoutMs | number | The timeout in milliseconds (0 to disable reconnection) |
Returns
void