diff --git a/src/mqtt_client_wrapper.cpp b/src/mqtt_client_wrapper.cpp index acb9bf9..dcb6d64 100644 --- a/src/mqtt_client_wrapper.cpp +++ b/src/mqtt_client_wrapper.cpp @@ -20,21 +20,17 @@ static void send_heartbeat() { if (!mqtt_client || !mqtt_client->isConnected()) return; - nlohmann::json hb_data; - hb_data["time"] = Logger::get_current_time_utc8(); - hb_data["status"] = g_streaming ? 0 : 2; + // 获取当前时间戳(13位毫秒) + auto now = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(now.time_since_epoch()).count(); - { - std::lock_guard lock(g_dispatch_id_mutex); - hb_data["dispatchId"] = g_streaming ? g_dispatch_id : ""; - } + g_streaming.store(RTMPManager::is_any_streaming()); - nlohmann::json msg; - msg["data"] = hb_data; - msg["isEnc"] = 0; - msg["type"] = 0; + nlohmann::json hb; + hb["timestamp"] = ms; + hb["status"] = g_streaming ? 1 : 0; // 0:等待中,1:推流中 - 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 回调