|
@@ -150,6 +150,16 @@ void ProtoParser::setLogType(int type)
|
|
|
MqttSetLogType((LOG_TYPE)type);
|
|
|
}
|
|
|
|
|
|
+int ProtoParser::getLogLevel() const
|
|
|
+{
|
|
|
+ return MqttGetLogLevel();
|
|
|
+}
|
|
|
+
|
|
|
+int ProtoParser::getLogType() const
|
|
|
+{
|
|
|
+ return MqttGetLogType();
|
|
|
+}
|
|
|
+
|
|
|
bool ProtoParser::isConnected() const
|
|
|
{
|
|
|
#ifdef USE_WASM
|
|
@@ -309,6 +319,17 @@ 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(); )
|
|
|
+ {
|
|
|
+ if (it2->second == it->first)
|
|
|
+ {
|
|
|
+ it2 = _pullIds.erase(it2);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ it2++;
|
|
|
+ }
|
|
|
+ }
|
|
|
MqttLog(LOG_WARN, LOG_TYPE_FUNC, "remove too early publish, topic: %s, msgId: %d, time: %lld", it->second->topic.c_str(), it->first, it->second->time);
|
|
|
it = _publishes.erase(it);
|
|
|
continue;
|
|
@@ -317,7 +338,7 @@ std::string ProtoParser::publish(const std::string &topic, const std::string &pa
|
|
|
{
|
|
|
msgId = it->first;
|
|
|
#ifdef DUMP
|
|
|
- MqttLog(LOG_INFO, LOG_TYPE_MQTT, "already send topic: %s, msgId: %d, request: %s", topic.c_str(), msgId, request.c_str());
|
|
|
+ MqttLog(LOG_DEBUG, LOG_TYPE_MQTT, "already send topic: %s, msgId: %d, request: %s", topic.c_str(), msgId, request.c_str());
|
|
|
#endif
|
|
|
return "";
|
|
|
}
|
|
@@ -488,6 +509,17 @@ int ProtoParser::parse(std::vector<uint8_t> &data)
|
|
|
MqttLog(LOG_DEBUG, LOG_TYPE_MQTT, "_publishes size: %d", _publishes.size());
|
|
|
#endif
|
|
|
}
|
|
|
+ for (auto it2 = _pullIds.begin(); it2 != _pullIds.end();)
|
|
|
+ {
|
|
|
+ if (it2->second == pack.msgId)
|
|
|
+ {
|
|
|
+ it2 = _pullIds.erase(it2);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ it2++;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
if (_topic.length() > 0 && pack.payload.length() > 0)
|
|
|
{
|
|
@@ -699,7 +731,11 @@ unsigned char ProtoParser::parsePayload(std::string &payload, bool pub)
|
|
|
if (r.ParseFromArray(str.c_str(), str.length()))
|
|
|
{
|
|
|
if (_topic.compare("MN") == 0)
|
|
|
+ {
|
|
|
p->update(r, _uid, _msgCurrent);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
toJson(r, _payload);
|
|
|
}
|
|
|
else
|
|
@@ -900,16 +936,45 @@ std::string ProtoParser::dismissGroupPack(std::string requestJson, uint32_t &msg
|
|
|
std::string ProtoParser::getGroupInfoPack(std::string requestJson, uint32_t &msgId)
|
|
|
{
|
|
|
PullUserRequest par;
|
|
|
- if (!parseJson(requestJson, par))
|
|
|
+ if (!parseJson(requestJson, _pullIds, par))
|
|
|
{
|
|
|
MqttLog(LOG_ERROR, LOG_TYPE_FUNC, "getGroupInfoPack paseJson failed");
|
|
|
msgId = 0;
|
|
|
return "";
|
|
|
}
|
|
|
+ if (par.request_size() == 0)
|
|
|
+ return "";
|
|
|
+
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
- str = dataEncrypt(str);
|
|
|
- return publish("GPGI", str, requestJson, msgId);
|
|
|
+ str = dataEncrypt(str);
|
|
|
+ auto ret = publish("GPGI", str, requestJson, msgId);
|
|
|
+ if (ret.length() > 0)
|
|
|
+ {
|
|
|
+ for (auto it = _pullIds.begin(); it != _pullIds.end(); it++)
|
|
|
+ {
|
|
|
+ if (it->second == 0)
|
|
|
+ {
|
|
|
+ it->second = msgId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ for (auto it = _pullIds.begin(); it != _pullIds.end(); )
|
|
|
+ {
|
|
|
+ if (it->second == 0)
|
|
|
+ {
|
|
|
+ it = _pullIds.erase(it);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ it++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::getGroupMemberPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -931,12 +996,15 @@ std::string ProtoParser::getGroupMemberPack(std::string requestJson, uint32_t &m
|
|
|
std::string ProtoParser::getUserInfoPack(std::string requestJson, uint32_t &msgId)
|
|
|
{
|
|
|
PullUserRequest par;
|
|
|
- if (!parseJson(requestJson, par) || par.request().size() == 0)
|
|
|
+ if (!parseJson(requestJson, _pullIds, par))
|
|
|
{
|
|
|
MqttLog(LOG_ERROR, LOG_TYPE_FUNC, "getUserInfoPack paseJson failed");
|
|
|
msgId = 0;
|
|
|
return "";
|
|
|
}
|
|
|
+ if(par.request_size()==0)
|
|
|
+ return "";
|
|
|
+
|
|
|
#ifdef DUMP
|
|
|
MqttLog(LOG_DEBUG, LOG_TYPE_FUNC, "getUserInfoPack: size: %d, first uid: %s", par.request().size(), par.request().at(0).uid().c_str());
|
|
|
#endif
|
|
@@ -945,6 +1013,30 @@ std::string ProtoParser::getUserInfoPack(std::string requestJson, uint32_t &msgI
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
auto ret = publish("UPUI", str, requestJson, msgId);
|
|
|
+ if (ret.length() > 0)
|
|
|
+ {
|
|
|
+ for (auto it = _pullIds.begin(); it != _pullIds.end(); it++)
|
|
|
+ {
|
|
|
+ if (it->second == 0)
|
|
|
+ {
|
|
|
+ it->second = msgId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ for (auto it = _pullIds.begin(); it != _pullIds.end();)
|
|
|
+ {
|
|
|
+ if (it->second == 0)
|
|
|
+ {
|
|
|
+ it = _pullIds.erase(it);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ it++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -1920,6 +2012,10 @@ void ProtoParser::setOnMessage(int ptr)
|
|
|
{
|
|
|
_onMessage = (onMessageCallback)ptr;
|
|
|
}
|
|
|
+void ProtoParser::setOnNotify(int ptr)
|
|
|
+{
|
|
|
+ _onNotify = (onNotifyCallback)ptr;
|
|
|
+}
|
|
|
|
|
|
int ProtoParser::reconnectVal()
|
|
|
{
|
|
@@ -1989,6 +2085,7 @@ EM_BOOL ProtoParser::onWebSocketOpen(int eventType, const EmscriptenWebSocketOpe
|
|
|
{
|
|
|
std::lock_guard<std::mutex> l(parser->_publishLock);
|
|
|
parser->_publishes.clear();
|
|
|
+ parser->_pullIds.clear();
|
|
|
}
|
|
|
//MqttLog(MQTT_LOG_INFO, "ProtoParser::onWebSocketOpen, uid: %s", parser->_uid.c_str());
|
|
|
auto res = parser->connectPack(parser->_uid);
|