This commit is contained in:
cxh 2025-10-16 13:19:58 +08:00
parent 6d606c618e
commit 643b64d828

View File

@ -20,21 +20,17 @@ static void send_heartbeat()
{ {
if (!mqtt_client || !mqtt_client->isConnected()) return; if (!mqtt_client || !mqtt_client->isConnected()) return;
nlohmann::json hb_data; // 获取当前时间戳13位毫秒
hb_data["time"] = Logger::get_current_time_utc8(); auto now = std::chrono::system_clock::now();
hb_data["status"] = g_streaming ? 0 : 2; auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
{ g_streaming.store(RTMPManager::is_any_streaming());
std::lock_guard<std::mutex> lock(g_dispatch_id_mutex);
hb_data["dispatchId"] = g_streaming ? g_dispatch_id : "";
}
nlohmann::json msg; nlohmann::json hb;
msg["data"] = hb_data; hb["timestamp"] = ms;
msg["isEnc"] = 0; hb["status"] = g_streaming ? 1 : 0; // 0等待中1推流中
msg["type"] = 0;
mqtt_client->publish(g_app_config.mqtt.topics.heartbeat_up, msg.dump()); mqtt_client->publish(g_app_config.mqtt.topics.heartbeat_up, hb.dump());
} }
// MQTT 回调 // MQTT 回调