View Source Nostrum.Shard.Session (Nostrum v0.9.0-alpha2)

Manages a single shard's gateway connection.

purpose

Purpose

Discord's gateway sends us events over websocket. The shard session state machine concerns it self with parsing these events and dispatching them to clients as appropriate.

internal-module

Internal module

This module is intended for exclusive usage inside of nostrum, and is documented for completeness and people curious to look behind the covers.

inner-workings

Inner workings

The session is implemented via :gen_statem and can be in one of the following states:

  • disconnected: when no connection is up at all. On initial connection of the session (e.g. no seq field is available), this will block if we need to wait a moment to respect the session startup concurrency limits. Afterwards, it will transition to connecting_http.

  • connecting_http: We are setting up a HTTP connection to the API. This means that no connection was available previously at all, and we need to open it from scratch. Once :gun notifies us that the connection is up, we transition to the connecting_ws state.

  • connecting_ws: We are turning the HTTP connection into a WebSocket connection. This is used both for the initial connection and also for later gateway-requested reconnections. If this succeeds, we head into the connected state.

  • connected: The WebSocket connection is up. This state actively deals with new data from the gateway, and takes care of heartbeating. If Discord fails to respond to our heartbeats, we close down the full connection and attempt to re-establish and resume events.

Link to this section Summary

Link to this section Functions

Callback implementation for :gen_statem.callback_mode/0.

Link to this function

connected(atom, request, data)

View Source
Link to this function

connecting_http(arg1, from, data)

View Source
Link to this function

connecting_ws(arg1, arg2, data)

View Source
Link to this function

disconnected(arg1, arg2, data)

View Source

Callback implementation for :gen_statem.init/1.

Link to this function

request_guild_members(pid, guild_id, limit \\ 0)

View Source
Link to this function

start_link(shard_opts, statem_opts)

View Source
Link to this function

update_status(pid, status, game, stream, type)

View Source
Link to this function

update_voice_state(pid, guild_id, channel_id, self_mute, self_deaf)

View Source