GatewayServer
Class: GatewayServer
Discord Gateway WebSocket server Handles WebSocket connections and sends Gateway protocol messages
Constructors
new GatewayServer()
new GatewayServer(): GatewayServerReturns
Accessors
connectionCount
Get Signature
get connectionCount(): numberGet number of active connections
Returns
number
Methods
clearControlFlags()
clearControlFlags(sessionId): voidClear control flags for a session
Parameters
| Parameter | Type | Description |
|---|---|---|
sessionId | string | The session ID |
Returns
void
close()
close(): voidClose all connections and shut down the server
Returns
void
disconnectSession()
disconnectSession(
sessionId,
closeCode,
reason?): numberForce disconnect all connections for a session with a specific close code Used for testing reconnection handling
Parameters
| Parameter | Type | Description |
|---|---|---|
sessionId | string | The session ID to disconnect |
closeCode | number | The WebSocket close code to use |
reason? | string | Optional reason string |
Returns
number
Number of connections disconnected
dispatchToSession()
dispatchToSession(
sessionId,
event,
data,
guildId?): numberDispatch an event to all connections in a session Handles intent filtering and sequence number management
Parameters
| Parameter | Type | Description |
|---|---|---|
sessionId | string | The session to dispatch to |
event | string | The event name (e.g., "MESSAGE_CREATE") |
data | unknown | The event payload data (without op/s/t wrapper) |
guildId? | string | Optional guild ID for intent filtering |
Returns
number
Number of connections the event was sent to
getControlFlags()
getControlFlags(sessionId): undefined | ConnectionControlFlagsGet control flags for a session
Parameters
| Parameter | Type | Description |
|---|---|---|
sessionId | string | The session ID |
Returns
undefined | ConnectionControlFlags
The control flags, or undefined if none set
getHeartbeatInterval()
getHeartbeatInterval(): numberGet the current heartbeat interval
Returns
number
handleUpgrade()
handleUpgrade(
req,
socket,
head): voidHandle HTTP upgrade request Called by @robojs/server when a WebSocket upgrade is requested
Parameters
| Parameter | Type |
|---|---|
req | IncomingMessage |
socket | Duplex |
head | Buffer<ArrayBufferLike> |
Returns
void
invalidateSession()
invalidateSession(sessionId): booleanInvalidate a session (clears session data for fresh READY on reconnect) Used for testing session invalidation handling
Parameters
| Parameter | Type | Description |
|---|---|---|
sessionId | string | The session ID to invalidate |
Returns
boolean
true if session was invalidated, false if not found
setHeartbeatInterval()
setHeartbeatInterval(interval): voidSet the heartbeat interval for new connections (in ms) Default is 41250ms (standard Discord interval) Use shorter intervals for testing (e.g., 1000ms)
Parameters
| Parameter | Type |
|---|---|
interval | number |
Returns
void
setStopHeartbeatAcks()
setStopHeartbeatAcks(sessionId, stop): voidSet whether to stop sending heartbeat ACKs for a session Used for testing heartbeat timeout handling
Parameters
| Parameter | Type | Description |
|---|---|---|
sessionId | string | The session ID to control |
stop | boolean | Whether to stop sending ACKs (true) or resume (false) |
Returns
void
