增加视频播放地址请求
This commit is contained in:
parent
1790f7b318
commit
c6736e4d0b
@ -77,8 +77,52 @@ static void on_mqtt_message_received(const std::string& topic, const std::string
|
||||
{
|
||||
auto j = nlohmann::json::parse(message);
|
||||
|
||||
// -------- 判断字段 type 是否为 "request" --------
|
||||
if (j.contains("type") && j["type"].is_string() && j["type"] == "request")
|
||||
{
|
||||
LOG_INFO("[MQTT] Received message on topic [" + topic + "], len = " + std::to_string(message.size()));
|
||||
LOG_INFO("[MQTT] Message content: " + j.dump(-1));
|
||||
|
||||
// -------- 判断 data.switch 是否为 1 --------
|
||||
if (j.contains("data") && j["data"].is_object())
|
||||
{
|
||||
const auto& d = j["data"];
|
||||
|
||||
if (d.contains("switch") && d["switch"].is_number_integer())
|
||||
{
|
||||
int sw = d["switch"];
|
||||
|
||||
if (sw == 1)
|
||||
{
|
||||
// ---- 获取 RTMP 状态 ----
|
||||
auto channels_info = RTMPManager::get_all_channels_status();
|
||||
|
||||
// ---- 构造 response ----
|
||||
nlohmann::json resp;
|
||||
resp["type"] = "response";
|
||||
resp["seqNo"] = j.value("seqNo", "0");
|
||||
|
||||
resp["data"] = nlohmann::json::array();
|
||||
|
||||
int loc = 0;
|
||||
|
||||
for (const auto& ch : channels_info)
|
||||
{
|
||||
resp["data"].push_back({{"loc", loc}, {"url", ch.url}});
|
||||
loc++;
|
||||
}
|
||||
|
||||
// ---- 发布 MQTT 响应 ----
|
||||
std::string out = resp.dump(-1);
|
||||
mqtt_client->publish(g_app_config.mqtt.topics.video_down, out, 1, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO("[MQTT] Message is NOT a request.");
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user