|
@@ -1535,11 +1535,17 @@ std::string ProtoParser::getMessages(std::string requestJson)
|
|
|
|
|
|
#ifdef USE_WASM
|
|
|
|
|
|
-extern "C"
|
|
|
+void ProtoParser::setOnConnected(int ptr)
|
|
|
{
|
|
|
- extern void onMessage(int r);
|
|
|
- extern void onConnected();
|
|
|
- extern void onDisconnected();
|
|
|
+ _onConnected = (onConnectedCallback)ptr;
|
|
|
+}
|
|
|
+void ProtoParser::setOnDisconnected(int ptr)
|
|
|
+{
|
|
|
+ _onDisconnected = (onDisconnectedCallback)ptr;
|
|
|
+}
|
|
|
+void ProtoParser::setOnMessage(int ptr)
|
|
|
+{
|
|
|
+ _onMessage = (onMessageCallback)ptr;
|
|
|
}
|
|
|
|
|
|
int ProtoParser::reconnectVal()
|
|
@@ -1591,7 +1597,11 @@ int ProtoParser::connectVal(std::string requestJson)
|
|
|
EM_BOOL ProtoParser::onWebSocketClose(int eventType, const EmscriptenWebSocketCloseEvent *websocketEvent, void *userData)
|
|
|
{
|
|
|
MqttLog(MQTT_LOG_ERROR, "web socket closed");
|
|
|
- onDisconnected();
|
|
|
+ ProtoParser *parser = (ProtoParser *)userData;
|
|
|
+ if (parser->_onDisconnected != nullptr)
|
|
|
+ {
|
|
|
+ parser->_onDisconnected();
|
|
|
+ }
|
|
|
return EM_TRUE;
|
|
|
}
|
|
|
EM_BOOL ProtoParser::onWebSocketError(int eventType, const EmscriptenWebSocketErrorEvent *websocketEvent, void *userData)
|
|
@@ -1606,7 +1616,10 @@ EM_BOOL ProtoParser::onWebSocketOpen(int eventType, const EmscriptenWebSocketOpe
|
|
|
auto res = parser->connectPack(parser->_uid);
|
|
|
parser->send(res);
|
|
|
|
|
|
- onConnected();
|
|
|
+ if (parser->_onConnected != nullptr)
|
|
|
+ {
|
|
|
+ parser->_onConnected();
|
|
|
+ }
|
|
|
return EM_TRUE;
|
|
|
}
|
|
|
|
|
@@ -1621,7 +1634,10 @@ EM_BOOL ProtoParser::onWebSocketMessage(int eventType, const EmscriptenWebSocket
|
|
|
ProtoParser *parser = (ProtoParser *)userData;
|
|
|
std::vector<uint8_t> data(websocketEvent->data, websocketEvent->data + websocketEvent->numBytes);
|
|
|
int r = parser->parse(data);
|
|
|
- onMessage(r);
|
|
|
+ if (parser->_onMessage != nullptr)
|
|
|
+ {
|
|
|
+ parser->_onMessage(r, parser->_rc, parser->_respMsgId);
|
|
|
+ }
|
|
|
return EM_TRUE;
|
|
|
}
|
|
|
|