Class: WebSocketShard

WebSocketShard

Represents a Shard's WebSocket connection

Constructor

new WebSocketShard()

Source:

Members

(private) closeSequence :number

The sequence of the shard after close
Type:
  • number
Source:

(private) connectedAt :number

Time when the WebSocket connection was opened
Type:
  • number
Source:

(private, nullable) connection :WebSocket

The WebSocket connection for the current shard
Type:
  • WebSocket
Source:

(private) eventsAttached :boolean

If the manager attached its event handlers on the shard
Type:
  • boolean
Source:

(private, nullable) expectedGuilds :Set.<string>

A set of guild IDs this shard expects to receive
Type:
  • Set.<string>
Source:

(private, nullable) helloTimeout :NodeJS.Timeout

The HELLO timeout
Type:
  • NodeJS.Timeout
Source:

id :number

The ID of the shard
Type:
  • number
Source:

(private, nullable) inflate :Inflate

The compression to use
Type:
  • Inflate
Source:

(private) lastHeartbeatAcked :boolean

If we received a heartbeat ack back. Used to identify zombie connections
Type:
  • boolean
Source:

(private) lastPingTimestamp :number

The last time a ping was sent (a timestamp)
Type:
  • number
Source:

manager :WebSocketManager

The WebSocketManager of the shard
Type:
Source:

ping :number

The previous heartbeat ping of the shard
Type:
  • number
Source:

(private) ratelimit :Object

Contains the rate limit queue and metadata
Type:
  • Object
Source:

(private, nullable) readyTimeout :NodeJS.Timeout

The ready timeout
Type:
  • NodeJS.Timeout
Source:

(private) sequence :number

The current sequence of the shard
Type:
  • number
Source:

(private) sessionID :string

The current session ID of the shard
Type:
  • string
Source:

status :Status

The current status of the shard
Type:
Source:

Methods

(private) _cleanupConnection()

Cleans up the WebSocket connection listeners.
Source:

(private) _emitDestroyed()

Emits the DESTROYED event on the shard
Source:

(private) _send(data) → {void}

Sends data, bypassing the queue.
Parameters:
Name Type Description
data Object Packet to send
Source:
Returns:
Type
void

(private) ackHeartbeat()

Acknowledges a heartbeat.
Source:

(private) checkReady()

Checks if the shard can be marked as ready
Source:

(private) connect() → {Promise.<void>}

Connects the shard to the gateway.
Source:
Returns:
A promise that will resolve if the shard turns ready successfully, or reject if we couldn't connect
Type
Promise.<void>

(private) debug(message)

Emits a debug event.
Parameters:
Name Type Description
message string The debug message
Source:

(private) destroy(optionsopt)

Destroys this shard and closes its WebSocket connection.
Parameters:
Name Type Attributes Default Description
options Object <optional>
{ closeCode: 1000, reset: false, emit: true, log: true } Options for destroying the shard
Source:

(private) identify() → {void}

Identifies the client on the connection.
Source:
Returns:
Type
void

(private) identifyNew()

Identifies as a new connection on the gateway.
Source:

(private) identifyResume()

Resumes a session on the gateway.
Source:

(private) onClose(event)

Called whenever a connection to the gateway is closed.
Parameters:
Name Type Description
event CloseEvent Close event that was received
Source:

(private) onError(event)

Called whenever an error occurs with the WebSocket.
Parameters:
Name Type Description
event ErrorEvent The error that occurred
Source:

(private) onMessage(event)

Called whenever a message is received.
Parameters:
Name Type Description
event MessageEvent Event received
Source:

(private) onOpen()

Called whenever a connection is opened to the gateway.
Source:

(private) onPacket(packet)

Called whenever a packet is received.
Parameters:
Name Type Description
packet Object The received packet
Source:

(private) processQueue() → {void}

Processes the current WebSocket queue.
Source:
Returns:
Type
void

send(data, importantopt)

Adds a packet to the queue to be sent to the gateway. If you use this method, make sure you understand that you need to provide a full [Payload](https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-commands). Do not use this method if you don't know what you're doing.
Parameters:
Name Type Attributes Default Description
data Object The full packet to send
important boolean <optional>
false If this packet should be added first in queue
Source:

(private) sendHeartbeat(tagopt, ignoreHeartbeatAckopt)

Sends a heartbeat to the WebSocket. If this shard didn't receive a heartbeat last time, it will destroy it and reconnect
Parameters:
Name Type Attributes Default Description
tag string <optional>
'HeartbeatTimer' What caused this heartbeat to be sent
ignoreHeartbeatAck boolean <optional>
If we should send the heartbeat forcefully.
Source:

(private) setHeartbeatTimer(time)

Sets the heartbeat timer for this shard.
Parameters:
Name Type Description
time number If -1, clears the interval, any other number sets an interval
Source:

(private) setHelloTimeout(timeopt)

Sets the HELLO packet timeout.
Parameters:
Name Type Attributes Description
time number <optional>
If set to -1, it will clear the hello timeout timeout
Source:

Events

allReady

Emitted when the shard is fully ready. This event is emitted if: * all guilds were received by this shard * the ready timeout expired, and some guilds are unavailable
Parameters:
Name Type Attributes Description
unavailableGuilds Set.<string> <nullable>
Set of unavailable guilds, if any
Source:

close

Emitted when a shard's WebSocket closes.
Parameters:
Name Type Description
event CloseEvent The received event
Source:

destroyed

Emitted when a shard is destroyed, but no WebSocket connection was present.
Source:

ready

Emitted when the shard receives the READY payload and is now waiting for guilds
Source:

resumed

Emitted when the shard resumes successfully
Source: