mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
RequestHandler: Add GetInputList
This commit is contained in:
parent
9af7216891
commit
aac06b101e
@ -90,6 +90,7 @@ set(obs-websocket_SOURCES
|
||||
src/requesthandler/RequestHandler_Config.cpp
|
||||
src/requesthandler/RequestHandler_Sources.cpp
|
||||
src/requesthandler/RequestHandler_Scenes.cpp
|
||||
src/requesthandler/RequestHandler_Inputs.cpp
|
||||
src/requesthandler/rpc/Request.cpp
|
||||
src/requesthandler/rpc/RequestResult.cpp
|
||||
src/forms/SettingsDialog.cpp
|
||||
|
@ -36,6 +36,9 @@ const std::map<std::string, RequestMethodHandler> RequestHandler::_handlerMap
|
||||
{"SetSceneName", &RequestHandler::SetSceneName},
|
||||
{"CreateScene", &RequestHandler::CreateScene},
|
||||
{"RemoveScene", &RequestHandler::RemoveScene},
|
||||
|
||||
// Inputs
|
||||
{"GetInputList", &RequestHandler::GetInputList},
|
||||
};
|
||||
|
||||
RequestResult RequestHandler::ProcessRequest(const Request& request)
|
||||
|
@ -51,5 +51,8 @@ class RequestHandler {
|
||||
RequestResult CreateScene(const Request&);
|
||||
RequestResult RemoveScene(const Request&);
|
||||
|
||||
// Inputs
|
||||
RequestResult GetInputList(const Request&);
|
||||
|
||||
static const std::map<std::string, RequestMethodHandler> _handlerMap;
|
||||
};
|
||||
|
49
src/requesthandler/RequestHandler_Inputs.cpp
Normal file
49
src/requesthandler/RequestHandler_Inputs.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include "RequestHandler.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
struct EnumInputInfo {
|
||||
std::string inputKind;
|
||||
std::vector<json> inputs;
|
||||
};
|
||||
|
||||
RequestResult RequestHandler::GetInputList(const Request& request)
|
||||
{
|
||||
EnumInputInfo inputInfo;
|
||||
|
||||
if (request.RequestData.contains("inputKind") && !request.RequestData["inputKind"].is_null()) {
|
||||
RequestStatus::RequestStatus statusCode;
|
||||
std::string comment;
|
||||
if (!request.ValidateString("inputKind", statusCode, comment)) {
|
||||
return RequestResult::Error(statusCode, comment);
|
||||
}
|
||||
|
||||
inputInfo.inputKind = request.RequestData["inputKind"];
|
||||
}
|
||||
|
||||
auto inputEnumProc = [](void *param, obs_source_t *input) {
|
||||
// Sanity check in case the API changes
|
||||
if (obs_source_get_type(input) != OBS_SOURCE_TYPE_INPUT)
|
||||
return true;
|
||||
|
||||
auto inputInfo = reinterpret_cast<EnumInputInfo*>(param);
|
||||
|
||||
std::string inputKind = obs_source_get_id(input);
|
||||
|
||||
if (!inputInfo->inputKind.empty() && inputInfo->inputKind != inputKind)
|
||||
return true;
|
||||
|
||||
json inputJson;
|
||||
inputJson["inputName"] = obs_source_get_name(input);
|
||||
inputJson["inputKind"] = inputKind;
|
||||
|
||||
inputInfo->inputs.push_back(inputJson);
|
||||
return true;
|
||||
};
|
||||
// Actually enumerates only public inputs, despite the name
|
||||
obs_enum_sources(inputEnumProc, &inputInfo);
|
||||
|
||||
json responseData;
|
||||
responseData["inputs"] = inputInfo.inputs;
|
||||
return RequestResult::Success(responseData);
|
||||
}
|
Loading…
Reference in New Issue
Block a user