hardcoded decklink mode fix
This commit is contained in:
@@ -29,17 +29,18 @@ struct ControlServer::Impl {
|
||||
struct lws_context* context = nullptr;
|
||||
};
|
||||
|
||||
static void dispatch_command(ControlServerData* data, const nlohmann::json& msg) {
|
||||
static nlohmann::json dispatch_command(ControlServerData* data, const nlohmann::json& msg) {
|
||||
if (!msg.contains("cmd")) {
|
||||
spdlog::warn("Control: message missing 'cmd' field");
|
||||
return;
|
||||
return {{"error", "missing 'cmd' field"}};
|
||||
}
|
||||
auto cmd = msg["cmd"].get<std::string>();
|
||||
auto it = data->commands.find(cmd);
|
||||
if (it != data->commands.end()) {
|
||||
it->second(msg);
|
||||
return it->second(msg);
|
||||
} else {
|
||||
spdlog::warn("Control: unknown command '{}'", cmd);
|
||||
return {{"error", "unknown command: " + cmd}};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,8 +103,8 @@ static int callback_all(struct lws* wsi, enum lws_callback_reasons reason,
|
||||
}
|
||||
try {
|
||||
auto msg = nlohmann::json::parse(ps->http_body);
|
||||
dispatch_command(ps->data, msg);
|
||||
return send_http_json(wsi, "200 OK", R"({"ok":true})");
|
||||
auto result = dispatch_command(ps->data, msg);
|
||||
return send_http_json(wsi, "200 OK", result.dump());
|
||||
} catch (const nlohmann::json::parse_error& e) {
|
||||
return send_http_json(wsi, "400 Bad Request",
|
||||
nlohmann::json({{"error", e.what()}}).dump());
|
||||
|
||||
Reference in New Issue
Block a user