feat(mqtt): add publishPeerClientEvent + onClientStatus, retain rx
- onRxUpdate now publishes client/<call>/rx as retained, so a fresh
dashboard subscriber gets last-known rx on subscribe.
- onClientStatus is new: writes retained client/<call>/status from the
rich per-client status blob (today only inside nodes/local).
- onClientDisconnected clears retained client/<call>/{rx,status}.
- publishPeerClientEvent / clearPeerClientRetained are receiver-side
republish helpers for the new MsgPeerClient* messages.
This commit is contained in:
1 parent
bc9b6e7b30
commit
e25ae9caa1
2 files changed
+66
-3
No files matched your search
@@ -280,8 +280,12 @@ void MqttPublisher::onClientDisconnected(const std::string& callsign)
|
|||||||
Json::StreamWriterBuilder wb;
|
Json::StreamWriterBuilder wb;
|
||||||
wb["indentation"] = "";
|
wb["indentation"] = "";
|
||||||
Json::Value payload(Json::objectValue);
|
Json::Value payload(Json::objectValue);
|
||||||
string topic = "client/" + callsign + "/disconnected";
|
publish("client/" + callsign + "/disconnected",
|
||||||
publish(topic, Json::writeString(wb, payload));
|
Json::writeString(wb, payload));
|
||||||
|
// Clear retained per-client topics so a long-disconnected callsign
|
||||||
|
// does not linger in the broker store.
|
||||||
|
publish("client/" + callsign + "/rx", "", true);
|
||||||
|
publish("client/" + callsign + "/status", "", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -316,7 +320,7 @@ void MqttPublisher::onRxUpdate(const std::string& callsign,
|
|||||||
Json::StreamWriterBuilder wb;
|
Json::StreamWriterBuilder wb;
|
||||||
wb["indentation"] = "";
|
wb["indentation"] = "";
|
||||||
string topic = "client/" + callsign + "/rx";
|
string topic = "client/" + callsign + "/rx";
|
||||||
publish(topic, Json::writeString(wb, rx_json));
|
publish(topic, Json::writeString(wb, rx_json), true); // retained
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -373,3 +377,36 @@ void MqttPublisher::publishPeerNodes(const std::string& peer_id,
|
|||||||
publish("nodes/" + peer_id,
|
publish("nodes/" + peer_id,
|
||||||
Json::writeString(wb, nodeListToJson(nodes)), true);
|
Json::writeString(wb, nodeListToJson(nodes)), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MqttPublisher::onClientStatus(const std::string& callsign,
|
||||||
|
const Json::Value& status_json)
|
||||||
|
{
|
||||||
|
Json::StreamWriterBuilder wb;
|
||||||
|
wb["indentation"] = "";
|
||||||
|
publish("client/" + callsign + "/status",
|
||||||
|
Json::writeString(wb, status_json), true); // retained
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MqttPublisher::publishPeerClientEvent(const std::string& peer_id,
|
||||||
|
const std::string& callsign,
|
||||||
|
const std::string& event,
|
||||||
|
const Json::Value& payload,
|
||||||
|
bool retained)
|
||||||
|
{
|
||||||
|
Json::StreamWriterBuilder wb;
|
||||||
|
wb["indentation"] = "";
|
||||||
|
std::string topic =
|
||||||
|
"peer/" + peer_id + "/client/" + callsign + "/" + event;
|
||||||
|
publish(topic, Json::writeString(wb, payload), retained);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MqttPublisher::clearPeerClientRetained(const std::string& peer_id,
|
||||||
|
const std::string& callsign)
|
||||||
|
{
|
||||||
|
std::string base = "peer/" + peer_id + "/client/" + callsign + "/";
|
||||||
|
publish(base + "rx", "", true);
|
||||||
|
publish(base + "status", "", true);
|
||||||
|
}
|
||||||
@@ -40,6 +40,26 @@ class MqttPublisher
|
|||||||
// RX status update (per-client, all receivers)
|
// RX status update (per-client, all receivers)
|
||||||
void onRxUpdate(const std::string& callsign, const Json::Value& rx_json);
|
void onRxUpdate(const std::string& callsign, const Json::Value& rx_json);
|
||||||
|
|
||||||
|
// Rich per-client status blob (retained)
|
||||||
|
void onClientStatus(const std::string& callsign,
|
||||||
|
const Json::Value& status_json);
|
||||||
|
|
||||||
|
// Receiver-side: republish a peer-side per-client event under
|
||||||
|
// peer/<peer_id>/client/<callsign>/<event>. retained controls broker
|
||||||
|
// retention. event must be one of: "connected", "disconnected", "rx",
|
||||||
|
// "status".
|
||||||
|
void publishPeerClientEvent(const std::string& peer_id,
|
||||||
|
const std::string& callsign,
|
||||||
|
const std::string& event,
|
||||||
|
const Json::Value& payload,
|
||||||
|
bool retained);
|
||||||
|
|
||||||
|
// Receiver-side: clear retained payload at peer/<peer_id>/client/<call>/{rx,status}.
|
||||||
|
// Used by snapshot-driven housekeeping when a callsign disappears between
|
||||||
|
// two consecutive MsgPeerNodeList snapshots.
|
||||||
|
void clearPeerClientRetained(const std::string& peer_id,
|
||||||
|
const std::string& callsign);
|
||||||
|
|
||||||
// Periodic full status
|
// Periodic full status
|
||||||
void publishFullStatus(const Json::Value& status);
|
void publishFullStatus(const Json::Value& status);
|
||||||
|
|
||||||
@@ -96,6 +116,12 @@ class MqttPublisher
|
|||||||
const std::string&, uint16_t) {}
|
const std::string&, uint16_t) {}
|
||||||
void onTrunkDown(const std::string&, const std::string&) {}
|
void onTrunkDown(const std::string&, const std::string&) {}
|
||||||
void onRxUpdate(const std::string&, const Json::Value&) {}
|
void onRxUpdate(const std::string&, const Json::Value&) {}
|
||||||
|
void onClientStatus(const std::string&, const Json::Value&) {}
|
||||||
|
void publishPeerClientEvent(const std::string&, const std::string&,
|
||||||
|
const std::string&, const Json::Value&,
|
||||||
|
bool) {}
|
||||||
|
void clearPeerClientRetained(const std::string&,
|
||||||
|
const std::string&) {}
|
||||||
void publishFullStatus(const Json::Value&) {}
|
void publishFullStatus(const Json::Value&) {}
|
||||||
void publishLocalNodes(
|
void publishLocalNodes(
|
||||||
const std::vector<MsgPeerNodeList::NodeEntry>&) {}
|
const std::vector<MsgPeerNodeList::NodeEntry>&) {}
|
||||||
|
|||||||
Reference in new issue
Block a user