Toast/TriviaBot/bot/ClientConnection.hpp

42 lines
1.1 KiB
C++
Raw Normal View History

#ifndef BOT_CLIENTCONNECTION
#define BOT_CLIENTCONNECTION
2016-07-05 00:51:53 +01:00
#include <websocketpp/client.hpp>
#include <websocketpp/config/asio_client.hpp>
#include "json/json.hpp"
2016-07-05 00:51:53 +01:00
2016-08-15 17:47:34 +01:00
#include "GatewayHandler.hpp"
2016-07-05 00:51:53 +01:00
typedef websocketpp::client<websocketpp::config::asio_tls_client> client;
using websocketpp::lib::bind;
// pull out the type of messages sent by our config
typedef websocketpp::config::asio_tls_client::message_type::ptr message_ptr;
typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr;
typedef client::connection_ptr connection_ptr;
2016-08-15 17:47:34 +01:00
class BotConfig;
2016-07-05 00:51:53 +01:00
class ClientConnection {
public:
2016-08-15 17:47:34 +01:00
ClientConnection(BotConfig &c);
2016-07-05 00:51:53 +01:00
// Open a connection to the URI provided
void start(std::string uri);
2016-07-05 00:51:53 +01:00
2016-08-15 17:47:34 +01:00
private:
client cli;
BotConfig &config;
GatewayHandler gh;
// Event handlers
void on_socket_init(websocketpp::connection_hdl);
context_ptr on_tls_init(websocketpp::connection_hdl);
void on_fail(websocketpp::connection_hdl hdl);
void on_open(websocketpp::connection_hdl hdl);
2016-07-12 21:11:28 +01:00
void on_message(websocketpp::connection_hdl hdl, message_ptr message);
void on_close(websocketpp::connection_hdl);
};
#endif