GatewaySession
Defined in: packages/ws/src/session.ts:55
Session state for one Gateway shard.
Generations. Every connection attempt takes a token from
GatewaySession.beginConnection, and every mutation must present it.
A socket that has been superseded still holds the old token, so a late
dispatch arriving on it cannot advance the new connectionâs sequence or
overwrite its session id. Ownership is therefore structural rather than a
chain of if (this.#ws === ws) checks at each call site.
Constructors
Section titled âConstructorsâConstructor
Section titled âConstructorânew GatewaySession():
GatewaySession
Returns
Section titled âReturnsâGatewaySession
Accessors
Section titled âAccessorsâcanResume
Section titled âcanResumeâGet Signature
Section titled âGet Signatureâget canResume():
boolean
Defined in: packages/ws/src/session.ts:104
Whether a RESUME is possible: a session, a resume host, and a sequence.
Returns
Section titled âReturnsâboolean
generation
Section titled âgenerationâGet Signature
Section titled âGet Signatureâget generation():
number
Defined in: packages/ws/src/session.ts:75
Token of the current connection attempt; mutations must match it.
Returns
Section titled âReturnsânumber
lastInvalidation
Section titled âlastInvalidationâGet Signature
Section titled âGet Signatureâget lastInvalidation():
InvalidationReason|undefined
Defined in: packages/ws/src/session.ts:70
Why the last session was discarded, for diagnostics and reconnect policy.
Returns
Section titled âReturnsâInvalidationReason | undefined
resumeURL
Section titled âresumeURLâGet Signature
Section titled âGet Signatureâget resumeURL():
string|undefined
Defined in: packages/ws/src/session.ts:87
Host to reconnect to for a RESUME, or undefined when none is known.
Returns
Section titled âReturnsâstring | undefined
sequence
Section titled âsequenceâGet Signature
Section titled âGet Signatureâget sequence():
number|null
Defined in: packages/ws/src/session.ts:99
Last sequence number seen, or null when none has been observed.
Null, never zero, marks ânothing seenâ: sequence 0 is a legitimate
value that must survive into a RESUME.
Returns
Section titled âReturnsânumber | null
sessionId
Section titled âsessionIdâGet Signature
Section titled âGet Signatureâget sessionId():
string|undefined
Defined in: packages/ws/src/session.ts:80
Discordâs session id, or undefined when no session is established.
Returns
Section titled âReturnsâstring | undefined
Methods
Section titled âMethodsâactivate()
Section titled âactivate()âactivate(
payload,token):boolean
Defined in: packages/ws/src/session.ts:141
Establishes the session from a READY payload.
Parameters
Section titled âParametersâpayload
Section titled âpayloadâunknown
number
Returns
Section titled âReturnsâboolean
Whether the token owned the session and READY was well-formed.
beginConnection()
Section titled âbeginConnection()âbeginConnection():
number
Defined in: packages/ws/src/session.ts:114
Opens a new connection generation and returns its token.
The session itself is untouched: reconnecting to resume must keep the session id and sequence. Only ownership moves.
Returns
Section titled âReturnsânumber
connectURL()
Section titled âconnectURL()âconnectURL(
fallback):string
Defined in: packages/ws/src/session.ts:202
Host the next connection should dial: the resume host, else fallback.
The resume host comes from READY, so it is used only when it is a wss:
URL on discord.gg (or a subdomain), or on the fallbackâs own host; any
other host would receive the bot token in the RESUME frame.
Parameters
Section titled âParametersâfallback
Section titled âfallbackâstring
Returns
Section titled âReturnsâstring
handshake()
Section titled âhandshake()âhandshake():
HandshakeIntent
Defined in: packages/ws/src/session.ts:191
What the next connection must send: RESUME with material, or IDENTIFY.
Returns
Section titled âReturnsâinvalidate()
Section titled âinvalidate()âinvalidate(
token,reason?):boolean
Defined in: packages/ws/src/session.ts:169
Discards the session so the next connection must IDENTIFY.
Resumable invalidation (op 9 with d: true) is not an invalidation:
the session survives and the caller simply reconnects, so this is only
called for the non-resumable cases.
Parameters
Section titled âParametersânumber
reason?
Section titled âreason?âInvalidationReason = "explicit"
Returns
Section titled âReturnsâboolean
Whether the token owned the session and state was discarded.
owns(
token):boolean
Defined in: packages/ws/src/session.ts:119
Whether token still owns this session.
Parameters
Section titled âParametersânumber
Returns
Section titled âReturnsâboolean
recordSequence()
Section titled ârecordSequence()ârecordSequence(
sequence,token):boolean
Defined in: packages/ws/src/session.ts:127
Records a sequence number from a payload.
Parameters
Section titled âParametersâsequence
Section titled âsequenceânumber
number
Returns
Section titled âReturnsâboolean
Whether the token owned the session and the value was stored.
resumeInfo()
Section titled âresumeInfo()âresumeInfo():
ResumeInfo|undefined
Defined in: packages/ws/src/session.ts:183
Resume material, or undefined when a RESUME is not possible.
Returns
Section titled âReturnsâResumeInfo | undefined