diff options
| author | Patrick Schönberger | 2022-01-10 14:58:11 +0100 |
|---|---|---|
| committer | Patrick Schönberger | 2022-01-10 14:58:11 +0100 |
| commit | f0e7eee62c3b7c71a7accfb7a2cb6e1ed1f566bc (patch) | |
| tree | 484b45dd7256ee9f46aba56191d7ccadcfd64296 /src/ws.h | |
| parent | e00ad6704b8538b1a553960531af7b50d367fe73 (diff) | |
| download | autorec-f0e7eee62c3b7c71a7accfb7a2cb6e1ed1f566bc.tar.gz autorec-f0e7eee62c3b7c71a7accfb7a2cb6e1ed1f566bc.zip | |
Icons
Diffstat (limited to 'src/ws.h')
| -rw-r--r-- | src/ws.h | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -4,6 +4,7 @@ using json = nlohmann::json;
#include <string>
+#include <functional>
namespace ws
{
@@ -12,10 +13,14 @@ namespace ws bool done = false;
+ std::function<void()> onConnect;
+
static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
if (ev == MG_EV_WS_OPEN) {
+ puts("Open");
} else if (ev == MG_EV_WS_MSG) {
struct mg_ws_message *wm = (struct mg_ws_message *) ev_data;
+ printf("Msg: %.*s\n", (int)wm->data.len, wm->data.ptr);
std::string jsonStr(wm->data.ptr, wm->data.len);
auto msg = json::parse(jsonStr);
int op = msg["op"].get<int>();
@@ -32,16 +37,18 @@ namespace ws }
else if (op == 2)
{
- MessageBoxA(NULL, "hura", "connected", MB_OK);
+ puts("Connected");
+ if (onConnect)
+ onConnect();
}
}
if (ev == MG_EV_ERROR) {
- MessageBoxA(NULL, "", "Error", MB_OK);
+ puts("Error");
done = true;
}
if (ev == MG_EV_CLOSE) {
- MessageBoxA(NULL, "", "Close", MB_OK);
+ puts("Close");
done = true;
}
}
|
