Discord.C++ 0.13.0
Loading...
Searching...
No Matches
DiscordCPP::Gateway Class Referenceabstract

#include <Gateway.h>

Inheritance diagram for DiscordCPP::Gateway:
DiscordCPP::MainGateway DiscordCPP::VoiceGateway

Public Member Functions

 Gateway (std::string token, const std::shared_ptr< Threadpool > &threadpool)
 
virtual ~Gateway ()
 
void set_message_handler (const std::function< void(json payload)> &handler)
 
virtual SharedFuture< void > connect (const std::string &url)
 
SharedFuture< void > send (const json &message)
 
SharedFuture< void > close ()
 

Protected Member Functions

void start_heartbeating ()
 
virtual json get_heartbeat_payload ()=0
 
virtual void identify ()=0
 
virtual void on_websocket_incoming_message (const std::string &message)=0
 
void on_websocket_disconnnect ()
 

Protected Attributes

std::shared_ptr< Threadpoolthreadpool
 the threadpool used for tasks handling messages
 
boost::asio::io_context io_context
 boost io context used by the websocket client
 
boost::asio::ssl::context ssl_context
 ssl context used by the websocket client
 
std::unique_ptr< boost::beast::websocket::stream< boost::beast::ssl_stream< boost::asio::ip::tcp::socket > > > _client
 websocket client
 
std::string _url
 the url of the gateway
 
std::string _resume_url
 the url used for reconnecting
 
std::string _token
 token to identify with the gateway
 
unsigned int _heartbeat_interval
 heartbeat interval in milliseconds
 
bool _keepalive
 wether to keep the websocket alive or not
 
unsigned int _reconnect_timeout
 sometimes it is better a few seconds before reconnecting...
 
time_t _last_heartbeat_ack = 0
 timestamp of last heartbeat ack
 
std::thread _heartbeat_task
 heartbeat task
 
bool _connected
 indicator if Gateway is connected
 
Logger _log
 logging instance
 
std::function< void(json payload)> _message_handler
 the message handler set by using set_message_handler
 

Constructor & Destructor Documentation

◆ Gateway()

DiscordCPP::Gateway::Gateway ( std::string token,
const std::shared_ptr< Threadpool > & threadpool )

◆ ~Gateway()

DiscordCPP::Gateway::~Gateway ( )
virtual

Member Function Documentation

◆ close()

DiscordCPP::SharedFuture< void > DiscordCPP::Gateway::close ( )

◆ connect()

DiscordCPP::SharedFuture< void > DiscordCPP::Gateway::connect ( const std::string & url)
virtual

Reimplemented in DiscordCPP::MainGateway.

◆ get_heartbeat_payload()

virtual json DiscordCPP::Gateway::get_heartbeat_payload ( )
protectedpure virtual

◆ identify()

virtual void DiscordCPP::Gateway::identify ( )
protectedpure virtual

◆ on_websocket_disconnnect()

void DiscordCPP::Gateway::on_websocket_disconnnect ( )
protected

◆ on_websocket_incoming_message()

virtual void DiscordCPP::Gateway::on_websocket_incoming_message ( const std::string & message)
protectedpure virtual

◆ send()

DiscordCPP::SharedFuture< void > DiscordCPP::Gateway::send ( const json & message)
Exceptions
ClientException

◆ set_message_handler()

void DiscordCPP::Gateway::set_message_handler ( const std::function< void(json payload)> & handler)

◆ start_heartbeating()

void DiscordCPP::Gateway::start_heartbeating ( )
protected

Member Data Documentation

◆ _client

std::unique_ptr<boost::beast::websocket::stream<boost::beast::ssl_stream<boost::asio::ip::tcp::socket> > > DiscordCPP::Gateway::_client
protected

websocket client

◆ _connected

bool DiscordCPP::Gateway::_connected
protected

indicator if Gateway is connected

◆ _heartbeat_interval

unsigned int DiscordCPP::Gateway::_heartbeat_interval
protected

heartbeat interval in milliseconds

◆ _heartbeat_task

std::thread DiscordCPP::Gateway::_heartbeat_task
protected

heartbeat task

◆ _keepalive

bool DiscordCPP::Gateway::_keepalive
protected

wether to keep the websocket alive or not

◆ _last_heartbeat_ack

time_t DiscordCPP::Gateway::_last_heartbeat_ack = 0
protected

timestamp of last heartbeat ack

◆ _log

Logger DiscordCPP::Gateway::_log
protected

logging instance

◆ _message_handler

std::function<void(json payload)> DiscordCPP::Gateway::_message_handler
protected

the message handler set by using set_message_handler

◆ _reconnect_timeout

unsigned int DiscordCPP::Gateway::_reconnect_timeout
protected

sometimes it is better a few seconds before reconnecting...

◆ _resume_url

std::string DiscordCPP::Gateway::_resume_url
protected

the url used for reconnecting

◆ _token

std::string DiscordCPP::Gateway::_token
protected

token to identify with the gateway

◆ _url

std::string DiscordCPP::Gateway::_url
protected

the url of the gateway

◆ io_context

boost::asio::io_context DiscordCPP::Gateway::io_context
protected

boost io context used by the websocket client

◆ ssl_context

boost::asio::ssl::context DiscordCPP::Gateway::ssl_context
protected

ssl context used by the websocket client

◆ threadpool

std::shared_ptr<Threadpool> DiscordCPP::Gateway::threadpool
protected

the threadpool used for tasks handling messages


The documentation for this class was generated from the following files: