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§

Session 🔒

Constants§

GATEWAY_URL 🔒
MAX_RECONNECT_DELAY_SECS 🔒
RECONNECT_DELAY_SECS 🔒

Functions§

handle_dispatch 🔒
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 🔒