|
@@ -319,7 +319,7 @@ std::string ProtoParser::publish(const std::string &topic, const std::string &pa
|
|
|
{
|
|
|
if ((now - it->second->time) > 60 * 1000)
|
|
|
{
|
|
|
- for (auto it2 = _pullIds.begin(); it2 != _pullIds.end(); )
|
|
|
+ for (auto it2 = _pullIds.begin(); it2 != _pullIds.end();)
|
|
|
{
|
|
|
if (it2->second == it->first)
|
|
|
{
|
|
@@ -735,8 +735,6 @@ unsigned char ProtoParser::parsePayload(std::string &payload, bool pub)
|
|
|
if (_topic.compare("MN") == 0)
|
|
|
{
|
|
|
p->update(r, _uid, _msgCurrent);
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
toJson(r, _payload);
|
|
|
}
|
|
@@ -963,7 +961,7 @@ std::string ProtoParser::getGroupInfoPack(std::string requestJson, uint32_t &msg
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- for (auto it = _pullIds.begin(); it != _pullIds.end(); )
|
|
|
+ for (auto it = _pullIds.begin(); it != _pullIds.end();)
|
|
|
{
|
|
|
if (it->second == 0)
|
|
|
{
|
|
@@ -1004,7 +1002,7 @@ std::string ProtoParser::getUserInfoPack(std::string requestJson, uint32_t &msgI
|
|
|
msgId = 0;
|
|
|
return "";
|
|
|
}
|
|
|
- if(par.request_size()==0)
|
|
|
+ if (par.request_size() == 0)
|
|
|
return "";
|
|
|
|
|
|
#ifdef DUMP
|
|
@@ -1118,7 +1116,7 @@ std::string ProtoParser::pullMessagePack(std::string requestJson, uint32_t &msgI
|
|
|
msgId = 0;
|
|
|
return "";
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
@@ -1325,7 +1323,7 @@ std::string ProtoParser::kickoffGroupMemberPack(std::string requestJson, uint32_
|
|
|
for (int i = 0; i < arr.Size(); i++)
|
|
|
{
|
|
|
auto &item = arr[i];
|
|
|
- par.add_removed_member( item.GetString());
|
|
|
+ par.add_removed_member(item.GetString());
|
|
|
}
|
|
|
}
|
|
|
{
|
|
@@ -2069,6 +2067,30 @@ int ProtoParser::connectVal(std::string requestJson)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+std::string ProtoParser::getRespTopic(int msgId)
|
|
|
+{
|
|
|
+ std::lock_guard<std::recursive_mutex> l(_recvLock);
|
|
|
+ auto it = _respMessages.find((uint32_t)msgId);
|
|
|
+ if (it == _respMessages.end())
|
|
|
+ return "";
|
|
|
+ return it->second.topic;
|
|
|
+}
|
|
|
+
|
|
|
+void ProtoParser::removeResp(int msgId)
|
|
|
+{
|
|
|
+ std::lock_guard<std::recursive_mutex> l(_recvLock);
|
|
|
+ _respMessages.erase((uint32_t)msgId);
|
|
|
+}
|
|
|
+
|
|
|
+std::string ProtoParser::getRespPayload(int msgId)
|
|
|
+{
|
|
|
+ std::lock_guard<std::recursive_mutex> l(_recvLock);
|
|
|
+ auto it = _respMessages.find((uint32_t)msgId);
|
|
|
+ if (it == _respMessages.end())
|
|
|
+ return "";
|
|
|
+ return it->second.payload;
|
|
|
+}
|
|
|
+
|
|
|
EM_BOOL ProtoParser::onWebSocketClose(int eventType, const EmscriptenWebSocketCloseEvent *websocketEvent, void *userData)
|
|
|
{
|
|
|
MqttLog(LOG_WARN, LOG_TYPE_FUNC, "web socket closed");
|
|
@@ -2107,17 +2129,32 @@ EM_BOOL ProtoParser::onWebSocketOpen(int eventType, const EmscriptenWebSocketOpe
|
|
|
EM_BOOL ProtoParser::onWebSocketMessage(int eventType, const EmscriptenWebSocketMessageEvent *websocketEvent, void *userData)
|
|
|
{
|
|
|
#ifdef DUMP
|
|
|
- MqttLog(LOG_DEBUG, LOG_TYPE_FUNC, "ProtoParser::onWebSocketMessage, bin: %d, len: %d", !websocketEvent->isText, websocketEvent->numBytes);
|
|
|
+ MqttLog(LOG_DEBUG, LOG_TYPE_FUNC, "ProtoParser::onWebSocketMessage, bin: %d, len: %d", websocketEvent->isText ? 0 : 1, websocketEvent->numBytes);
|
|
|
#endif
|
|
|
/*if (websocketEvent->isText)
|
|
|
return EM_TRUE;*/
|
|
|
|
|
|
- ProtoParser *parser = (ProtoParser *)userData;
|
|
|
- std::vector<uint8_t> data(websocketEvent->data, websocketEvent->data + websocketEvent->numBytes);
|
|
|
- int r = parser->parse(data);
|
|
|
- if (parser->_onMessage != nullptr)
|
|
|
+ ProtoParser *parser = (ProtoParser *)userData;
|
|
|
+ std::lock_guard<std::recursive_mutex> l(parser->_recvLock);
|
|
|
{
|
|
|
- parser->_onMessage(r, parser->_rc, parser->_respMsgId);
|
|
|
+ std::vector<uint8_t> data(websocketEvent->data, websocketEvent->data + websocketEvent->numBytes);
|
|
|
+ int r = parser->parse(data);
|
|
|
+ if (parser->_respMessages.size() > 100)
|
|
|
+ {
|
|
|
+ parser->_respMessages.erase(parser->_respMessages.begin());
|
|
|
+ }
|
|
|
+ WasmMessage msg;
|
|
|
+ msg.r = r;
|
|
|
+ msg.rc = parser->_rc;
|
|
|
+ msg.msgId = parser->_respMsgId;
|
|
|
+ msg.topic = parser->_topic;
|
|
|
+ msg.payload = parser->_payload;
|
|
|
+ parser->_respMessages.emplace(std::make_pair(msg.msgId, msg));
|
|
|
+
|
|
|
+ if (parser->_onMessage != nullptr)
|
|
|
+ {
|
|
|
+ parser->_onMessage(r, parser->_rc, parser->_respMsgId);
|
|
|
+ }
|
|
|
}
|
|
|
return EM_TRUE;
|
|
|
}
|