mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-19 20:11:59 +03:00
connect and heartbeat
This commit is contained in:
30
discord/websocket.cpp
Normal file
30
discord/websocket.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "websocket.hpp"
|
||||
#include <functional>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
Websocket::Websocket() {}
|
||||
|
||||
void Websocket::StartConnection(std::string url) {
|
||||
m_websocket.setUrl(url);
|
||||
m_websocket.setOnMessageCallback(std::bind(&Websocket::OnMessage, this, std::placeholders::_1));
|
||||
m_websocket.start();
|
||||
}
|
||||
|
||||
void Websocket::SetJSONCallback(JSONCallback_t func) {
|
||||
m_json_callback = func;
|
||||
}
|
||||
|
||||
void Websocket::Send(const std::string &str) {
|
||||
m_websocket.sendText(str);
|
||||
}
|
||||
|
||||
void Websocket::OnMessage(const ix::WebSocketMessagePtr &msg) {
|
||||
switch (msg->type) {
|
||||
case ix::WebSocketMessageType::Message:
|
||||
printf("%s\n", msg->str.c_str());
|
||||
auto obj = nlohmann::json::parse(msg->str);
|
||||
if (m_json_callback)
|
||||
m_json_callback(obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user