summaryrefslogtreecommitdiff
path: root/src/discord/websocket.hpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-11-28 22:48:30 -0500
committerouwou <26526779+ouwou@users.noreply.github.com>2021-11-28 22:48:30 -0500
commite1703aea3fd597b23bde90e6c505278c517be611 (patch)
tree37d98fc90c9cd0844388bfb79beda2204f44af92 /src/discord/websocket.hpp
parentfd53a76bf6f53a095a639765923a30f2206b2cd6 (diff)
parente02107feea8214a045e6faa969f00dcbc0d2b072 (diff)
downloadabaddon-portaudio-e1703aea3fd597b23bde90e6c505278c517be611.tar.gz
abaddon-portaudio-e1703aea3fd597b23bde90e6c505278c517be611.zip
merge master
Diffstat (limited to 'src/discord/websocket.hpp')
-rw-r--r--src/discord/websocket.hpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/discord/websocket.hpp b/src/discord/websocket.hpp
new file mode 100644
index 0000000..26cd5d4
--- /dev/null
+++ b/src/discord/websocket.hpp
@@ -0,0 +1,46 @@
+#pragma once
+#include <ixwebsocket/IXNetSystem.h>
+#include <ixwebsocket/IXWebSocket.h>
+#include <string>
+#include <functional>
+#include <nlohmann/json.hpp>
+#include <sigc++/sigc++.h>
+
+class Websocket {
+public:
+ Websocket();
+ void StartConnection(std::string url);
+
+ void SetUserAgent(std::string agent);
+
+ bool GetPrintMessages() const noexcept;
+ void SetPrintMessages(bool show) noexcept;
+
+ void Send(const std::string &str);
+ void Send(const nlohmann::json &j);
+ void Stop();
+ void Stop(uint16_t code);
+ bool IsOpen() const;
+
+private:
+ void OnMessage(const ix::WebSocketMessagePtr &msg);
+
+ ix::WebSocket m_websocket;
+ std::string m_agent;
+
+public:
+ using type_signal_open = sigc::signal<void>;
+ using type_signal_close = sigc::signal<void, uint16_t>;
+ using type_signal_message = sigc::signal<void, std::string>;
+
+ type_signal_open signal_open();
+ type_signal_close signal_close();
+ type_signal_message signal_message();
+
+private:
+ type_signal_open m_signal_open;
+ type_signal_close m_signal_close;
+ type_signal_message m_signal_message;
+
+ bool m_print_messages = true;
+};