Skip to content

GatewayAction

GatewayAction = { heartbeatInterval: number; type: "hello"; } | { data: unknown; event: string | null; type: "dispatch"; } | { type: "heartbeat"; } | { data: unknown; type: "heartbeat-ack"; } | { type: "reconnect"; } | { resumable: boolean; type: "invalid-session"; } | { opcode: number; type: "unknown"; } | { cause?: unknown; message: string; type: "invalid"; violation: ProtocolViolation; }

Defined in: packages/ws/src/protocol.ts:24

What a received frame means.

{ heartbeatInterval: number; type: "hello"; }

op 10: begin heartbeating and hand shake.


{ data: unknown; event: string | null; type: "dispatch"; }

op 0: an event. event is null only if Discord omitted t.


{ type: "heartbeat"; }

op 1: Discord asks for a heartbeat now.


{ data: unknown; type: "heartbeat-ack"; }

op 11: the last heartbeat was acknowledged.


{ type: "reconnect"; }

op 7: Discord asks the client to reconnect.


{ resumable: boolean; type: "invalid-session"; }

op 9: the session is gone. resumable decides RESUME vs IDENTIFY.


{ opcode: number; type: "unknown"; }

An opcode this version does not handle.

Ignored rather than treated as an error: Discord adds opcodes, and a client that fails on an unfamiliar one breaks itself on every addition.


{ cause?: unknown; message: string; type: "invalid"; violation: ProtocolViolation; }

The frame was malformed. Never silently swallowed.