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_urlfrom the prior READY payload. - On INVALID_SESSION(resumable=false) or RECONNECT, drop session and re-IDENTIFY.
Heartbeat:
- HELLO provides
heartbeat_intervalin 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§
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 🔒