X-Git-Url: https://gitweb.ps.run/autorec/blobdiff_plain/e90fc8a9809127820252a09dd7bfbbbc7a6f295d..4264345d06a81cb561047d0973c44a129db934aa:/src/ws.h diff --git a/src/ws.h b/src/ws.h index ecc88b3..058f69b 100644 --- a/src/ws.h +++ b/src/ws.h @@ -4,6 +4,7 @@ using json = nlohmann::json; #include +#include namespace ws { @@ -12,10 +13,14 @@ namespace ws bool done = false; + std::function 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(); @@ -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; } }