summaryrefslogtreecommitdiff
path: root/discord/websocket.cpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2020-08-17 02:40:03 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2020-08-17 02:40:03 -0400
commit18af78e6af49821f8c7adb5b4325d75c8bf4fd03 (patch)
tree2a2812d604fa0b00891613e868a79972159886aa /discord/websocket.cpp
parent212511e29d01af9b096e91371956b28de834bd13 (diff)
downloadabaddon-portaudio-18af78e6af49821f8c7adb5b4325d75c8bf4fd03.tar.gz
abaddon-portaudio-18af78e6af49821f8c7adb5b4325d75c8bf4fd03.zip
connect and heartbeat
Diffstat (limited to 'discord/websocket.cpp')
-rw-r--r--discord/websocket.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/discord/websocket.cpp b/discord/websocket.cpp
new file mode 100644
index 0000000..3590db3
--- /dev/null
+++ b/discord/websocket.cpp
@@ -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;
+ }
+}