Qore DiscordWebSocketClient Module Reference 1.0
Loading...
Searching...
No Matches
DiscordWebSocketClient::DiscordWebSocketClient Class Reference

The Discord WebSocket client class. More...

Public Member Functions

 constructor (*hash< auto > opts)
 creates the object and optionally sets logging targets
 
 destructor ()
 Deletes the object.
 
hash< auto > getInfo ()
 Returns performance statistics for the socket.
 
*string setupUrl (*string url)
 setup URL
 

Static Public Member Functions

static hash< auto > getOptions (*hash< auto > opts)
 Processes options for the DiscordWebSocketClient constructor.
 

Public Attributes

const DefaultApi = 10
 Default API version.
 
const DefaultHeaders = ...
 Default headers to use in the initial HTTP request after connecting.
 
const DefaultOptions = ...
 Default option values.
 
const DOP_DISPATCH = 0
 Receive: An event was dispatched.
 
const DOP_HEARTBEAT = 1
 Send/Receive: Fired periodically by the client to keep the connection alive.
 
const DOP_HEARTBEAT_ACK = 11
 Receive: Sent in response to receiving a heartbeat to acknowledge that it has been received.
 
const DOP_HELLO = 10
 Receive: Sent immediately after connecting, contains the heartbeat_interval to use.
 
const DOP_IDENTIFY = 2
 Send: Starts a new session during the initial handshake.
 
const DOP_INVALID_SESSION = 9
 Receive: The session has been invalidated. You should reconnect and identify/resume accordingly.
 
const DOP_PRESENCE_UPDATE = 3
 Send: Update the client's presence.
 
const DOP_RECONNECT = 7
 Receive: You should attempt to reconnect and resume immediately.
 
const DOP_REQUEST_GUILD_MEMBERS = 8
 Send: Request information about offline guild members in a large guild.
 
const DOP_RESUME = 6
 Send: Resume a previous session that was disconnected.
 
const DOP_VOICE_STATE_UPDATE = 4
 Send: Used to join/leave or move between voice channels.
 
const OpMap = ...
 Opcode to string map.
 

Protected Member Functions

 constructorInit (hash< auto > opts)
 Common constructor code.
 
 doReconnect (reference< hash< auto > > info)
 Connects to the server when reconnecting.
 
int handleEventData (auto msgdata)
 Handles deserialized event data.
 
 handleHeartbeatAck ()
 Handle a Heartbeat ACK.
 
 handleHello (hash< auto > d)
 Handle a HELLO message.
 
int handleMessage (hash< auto > msg)
 Handle a message by raising a data event.
 
int handleMessage (hash< WsMsgInfo > h, reference< data > buf)
 Handles WebSocket protocol messages.
 
 handleReadyMessage (hash< auto > d)
 Handle a READY message.
 
Counter heartbeat_cnt ()
 Heartbeat thread counter.
 
Condition heartbeat_cond ()
 Heartbeat condition.
 
Mutex heartbeat_lock ()
 Heartbeat mutex.
 
 reconnectPostamble ()
 Executes after a reconnect.
 
 reconnectPreamble ()
 Executes before a reconnect.
 
 sendIdentify ()
 Send an Identify message.
 
 sendResume ()
 Send a resume message.
 

Protected Attributes

int api = DefaultApi
 API version.
 
bool hb_stop
 Heartbeat thread stop flag.
 
int hb_tid
 Heartbeat thread ID.
 
int heartbeat_interval
 The heartbeat interval in ms.
 
int intents
 Intents for the identify message.
 
int last_sequence
 The last received sequence number.
 
string resume_gateway_url
 Resume gateway URL.
 
string session_id
 Current session ID.
 
string token
 Bot token.
 

Detailed Description

The Discord WebSocket client class.

Member Function Documentation

◆ constructor()

DiscordWebSocketClient::DiscordWebSocketClient::constructor ( *hash< auto > opts)

creates the object and optionally sets logging targets

Example:
DiscordWebSocketClient ws();
Parameters
optsAll options accepted by WebSocketClient::constructor() with the following differences:
  • token: must be a bot token and is a required option
  • intents: optional integer intent for the identify message
Exceptions
WEBSOCKET-ERRORunknown scheme, missing 'url' key in option hash; invalid option value

◆ getInfo()

hash< auto > DiscordWebSocketClient::DiscordWebSocketClient::getInfo ( )

Returns performance statistics for the socket.

Example:
hash<auto> h = ws.getInfo();
Returns
a hash with the following keys:
  • api: the API in use
  • cid: the current CID
  • heartbeat_tid: the heartbeat TID
  • session_id: the current session ID
  • last_sequence: the last sequence number received
  • resume_gateway_url: the gate URL for resumes