Skip to main content

Module gateway

Module gateway 

Source
Expand description

Discord Gateway WebSocket client.

Protocol flow: connect → HELLO → IDENTIFY (or RESUME) → READY → event loop.

On disconnect:

  • If we have a stored session_id + last_seq, attempt RESUME using the resume_gateway_url from the prior READY payload.
  • On INVALID_SESSION(resumable=false) or RECONNECT, drop session and re-IDENTIFY.

Heartbeat:

  • HELLO provides heartbeat_interval in milliseconds.
  • We send HEARTBEAT every interval, tracking ACK. If the prior heartbeat was not ACK’d, the connection is a zombie — close and reconnect.

Structs§

Ctx 🔒
What the session loop needs from its caller, fixed for the whole session.
Heartbeat 🔒
Heartbeat timing. The sleep starts as pending and is replaced with a timed one on HELLO; a boxed future keeps the select! arms free of pinning.
Session 🔒
State 🔒
What changes while a session runs.

Enums§

Step 🔒
What the session loop does after one event.

Constants§

GATEWAY_URL 🔒
MAX_RECONNECT_DELAY_SECS 🔒
RECONNECT_DELAY_SECS 🔒

Functions§

handle_dispatch 🔒
heartbeat_text 🔒
identify_text 🔒
on_frame 🔒
One frame from the Gateway.
on_heartbeat_tick 🔒
The heartbeat timer fired: a connection that never acknowledged the last one is a zombie.
on_hello 🔒
HELLO: start the heartbeat clock, then RESUME the session we had or IDENTIFY.
on_outbound 🔒
A message from an agent, to go to Discord over REST; a closed queue ends the session.
on_payload 🔒
A parsed Gateway payload, by opcode.
resume_text 🔒
run_gateway_loop
run_session 🔒
Run a single Gateway session. Returns: Ok(Some(session)) — clean disconnect, can attempt RESUME Ok(None) — clean disconnect, session is invalid (re-IDENTIFY) Err(e) — unexpected error, will re-IDENTIFY after backoff
unix_secs 🔒

Type Aliases§

WsError 🔒