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;
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<std::chrono::milliseconds>(now.time_since_epoch()).count();
{
std::lock_guard<std::mutex> 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 回调