Requests: Reorder some requests

This commit is contained in:
tt2468 2021-08-26 23:29:55 -07:00
parent bd289ae751
commit 251e3a28c1
4 changed files with 94 additions and 94 deletions

View File

@ -38,13 +38,15 @@ const std::map<std::string, RequestMethodHandler> RequestHandler::_handlerMap
{"SetCurrentProgramScene", &RequestHandler::SetCurrentProgramScene},
{"GetCurrentPreviewScene", &RequestHandler::GetCurrentPreviewScene},
{"SetCurrentPreviewScene", &RequestHandler::SetCurrentPreviewScene},
{"SetSceneName", &RequestHandler::SetSceneName},
{"CreateScene", &RequestHandler::CreateScene},
{"RemoveScene", &RequestHandler::RemoveScene},
{"SetSceneName", &RequestHandler::SetSceneName},
// Inputs
{"GetInputList", &RequestHandler::GetInputList},
{"GetInputKindList", &RequestHandler::GetInputKindList},
{"CreateInput", &RequestHandler::CreateInput},
{"SetInputName", &RequestHandler::SetInputName},
{"GetInputDefaultSettings", &RequestHandler::GetInputDefaultSettings},
{"GetInputSettings", &RequestHandler::GetInputSettings},
{"SetInputSettings", &RequestHandler::SetInputSettings},
@ -53,8 +55,6 @@ const std::map<std::string, RequestMethodHandler> RequestHandler::_handlerMap
{"ToggleInputMute", &RequestHandler::ToggleInputMute},
{"GetInputVolume", &RequestHandler::GetInputVolume},
{"SetInputVolume", &RequestHandler::SetInputVolume},
{"SetInputName", &RequestHandler::SetInputName},
{"CreateInput", &RequestHandler::CreateInput},
// Stream
{"GetStreamStatus", &RequestHandler::GetStreamStatus},

View File

@ -53,13 +53,15 @@ class RequestHandler {
RequestResult SetCurrentProgramScene(const Request&);
RequestResult GetCurrentPreviewScene(const Request&);
RequestResult SetCurrentPreviewScene(const Request&);
RequestResult SetSceneName(const Request&);
RequestResult CreateScene(const Request&);
RequestResult RemoveScene(const Request&);
RequestResult SetSceneName(const Request&);
// Inputs
RequestResult GetInputList(const Request&);
RequestResult GetInputKindList(const Request&);
RequestResult CreateInput(const Request&);
RequestResult SetInputName(const Request&);
RequestResult GetInputDefaultSettings(const Request&);
RequestResult GetInputSettings(const Request&);
RequestResult SetInputSettings(const Request&);
@ -68,8 +70,6 @@ class RequestHandler {
RequestResult ToggleInputMute(const Request&);
RequestResult GetInputVolume(const Request&);
RequestResult SetInputVolume(const Request&);
RequestResult SetInputName(const Request&);
RequestResult CreateInput(const Request&);
// Stream
RequestResult GetStreamStatus(const Request&);

View File

@ -37,6 +37,75 @@ RequestResult RequestHandler::GetInputKindList(const Request& request)
return RequestResult::Success(responseData);
}
RequestResult RequestHandler::CreateInput(const Request& request)
{
RequestStatus::RequestStatus statusCode;
std::string comment;
OBSSourceAutoRelease sceneSource = request.ValidateScene("sceneName", statusCode, comment);
if (!(request.ValidateString("inputName", statusCode, comment) &&
request.ValidateString("inputKind", statusCode, comment) &&
sceneSource))
return RequestResult::Error(statusCode, comment);
std::string inputName = request.RequestData["inputName"];
OBSSourceAutoRelease existingInput = obs_get_source_by_name(inputName.c_str());
if (existingInput)
return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that input name.");
std::string inputKind = request.RequestData["inputKind"];
auto kinds = Utils::Obs::ListHelper::GetInputKindList();
if (std::find(kinds.begin(), kinds.end(), inputKind) == kinds.end())
return RequestResult::Error(RequestStatus::InvalidInputKind, "Your specified input kind is not supported by OBS. Check that your specified kind is properly versioned and that any necessary plugins are loaded.");
OBSDataAutoRelease inputSettings = nullptr;
if (request.RequestData.contains("inputSettings") && !request.RequestData["inputSettings"].is_null()) {
if (!request.ValidateObject("inputSettings", statusCode, comment, true))
return RequestResult::Error(statusCode, comment);
inputSettings = Utils::Json::JsonToObsData(request.RequestData["inputSettings"]);
}
OBSScene scene = obs_scene_from_source(sceneSource);
bool sceneItemEnabled = true;
if (request.RequestData.contains("sceneItemEnabled") && !request.RequestData["sceneItemEnabled"].is_null()) {
if (!request.ValidateBoolean("sceneItemEnabled", statusCode, comment))
return RequestResult::Error(statusCode, comment);
sceneItemEnabled = request.RequestData["sceneItemEnabled"];
}
// Create the input and add it as a scene item to the destination scene
obs_sceneitem_t *sceneItem = Utils::Obs::ActionHelper::CreateInput(inputName, inputKind, inputSettings, scene, sceneItemEnabled);
if (!sceneItem)
return RequestResult::Error(RequestStatus::RequestProcessingFailed, "Creation of the input or scene item failed.");
json responseData;
responseData["sceneItemId"] = obs_sceneitem_get_id(sceneItem);
return RequestResult::Success(responseData);
}
RequestResult RequestHandler::SetInputName(const Request& request)
{
RequestStatus::RequestStatus statusCode;
std::string comment;
OBSSourceAutoRelease input = request.ValidateInput("inputName", statusCode, comment);
if (!(input && request.ValidateString("newInputName", statusCode, comment)))
return RequestResult::Error(statusCode, comment);
std::string newInputName = request.RequestData["newInputName"];
OBSSourceAutoRelease existingSource = obs_get_source_by_name(newInputName.c_str());
if (existingSource)
return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that new input name.");
obs_source_set_name(input, newInputName.c_str());
return RequestResult::Success();
}
RequestResult RequestHandler::GetInputDefaultSettings(const Request& request)
{
RequestStatus::RequestStatus statusCode;
@ -199,72 +268,3 @@ RequestResult RequestHandler::SetInputVolume(const Request& request)
return RequestResult::Success();
}
RequestResult RequestHandler::SetInputName(const Request& request)
{
RequestStatus::RequestStatus statusCode;
std::string comment;
OBSSourceAutoRelease input = request.ValidateInput("inputName", statusCode, comment);
if (!(input && request.ValidateString("newInputName", statusCode, comment)))
return RequestResult::Error(statusCode, comment);
std::string newInputName = request.RequestData["newInputName"];
OBSSourceAutoRelease existingSource = obs_get_source_by_name(newInputName.c_str());
if (existingSource)
return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that new input name.");
obs_source_set_name(input, newInputName.c_str());
return RequestResult::Success();
}
RequestResult RequestHandler::CreateInput(const Request& request)
{
RequestStatus::RequestStatus statusCode;
std::string comment;
OBSSourceAutoRelease sceneSource = request.ValidateScene("sceneName", statusCode, comment);
if (!(request.ValidateString("inputName", statusCode, comment) &&
request.ValidateString("inputKind", statusCode, comment) &&
sceneSource))
return RequestResult::Error(statusCode, comment);
std::string inputName = request.RequestData["inputName"];
OBSSourceAutoRelease existingInput = obs_get_source_by_name(inputName.c_str());
if (existingInput)
return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that input name.");
std::string inputKind = request.RequestData["inputKind"];
auto kinds = Utils::Obs::ListHelper::GetInputKindList();
if (std::find(kinds.begin(), kinds.end(), inputKind) == kinds.end())
return RequestResult::Error(RequestStatus::InvalidInputKind, "Your specified input kind is not supported by OBS. Check that your specified kind is properly versioned and that any necessary plugins are loaded.");
OBSDataAutoRelease inputSettings = nullptr;
if (request.RequestData.contains("inputSettings") && !request.RequestData["inputSettings"].is_null()) {
if (!request.ValidateObject("inputSettings", statusCode, comment, true))
return RequestResult::Error(statusCode, comment);
inputSettings = Utils::Json::JsonToObsData(request.RequestData["inputSettings"]);
}
OBSScene scene = obs_scene_from_source(sceneSource);
bool sceneItemEnabled = true;
if (request.RequestData.contains("sceneItemEnabled") && !request.RequestData["sceneItemEnabled"].is_null()) {
if (!request.ValidateBoolean("sceneItemEnabled", statusCode, comment))
return RequestResult::Error(statusCode, comment);
sceneItemEnabled = request.RequestData["sceneItemEnabled"];
}
// Create the input and add it as a scene item to the destination scene
obs_sceneitem_t *sceneItem = Utils::Obs::ActionHelper::CreateInput(inputName, inputKind, inputSettings, scene, sceneItemEnabled);
if (!sceneItem)
return RequestResult::Error(RequestStatus::RequestProcessingFailed, "Creation of the input or scene item failed.");
json responseData;
responseData["sceneItemId"] = obs_sceneitem_get_id(sceneItem);
return RequestResult::Success(responseData);
}

View File

@ -68,25 +68,6 @@ RequestResult RequestHandler::SetCurrentPreviewScene(const Request& request)
return RequestResult::Success();
}
RequestResult RequestHandler::SetSceneName(const Request& request)
{
RequestStatus::RequestStatus statusCode;
std::string comment;
OBSSourceAutoRelease scene = request.ValidateScene("sceneName", statusCode, comment);
if (!(scene && request.ValidateString("newSceneName", statusCode, comment)))
return RequestResult::Error(statusCode, comment);
std::string newSceneName = request.RequestData["newSceneName"];
OBSSourceAutoRelease existingSource = obs_get_source_by_name(newSceneName.c_str());
if (existingSource)
return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that new scene name.");
obs_source_set_name(scene, newSceneName.c_str());
return RequestResult::Success();
}
RequestResult RequestHandler::CreateScene(const Request& request)
{
RequestStatus::RequestStatus statusCode;
@ -118,3 +99,22 @@ RequestResult RequestHandler::RemoveScene(const Request& request)
return RequestResult::Success();
}
RequestResult RequestHandler::SetSceneName(const Request& request)
{
RequestStatus::RequestStatus statusCode;
std::string comment;
OBSSourceAutoRelease scene = request.ValidateScene("sceneName", statusCode, comment);
if (!(scene && request.ValidateString("newSceneName", statusCode, comment)))
return RequestResult::Error(statusCode, comment);
std::string newSceneName = request.RequestData["newSceneName"];
OBSSourceAutoRelease existingSource = obs_get_source_by_name(newSceneName.c_str());
if (existingSource)
return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that new scene name.");
obs_source_set_name(scene, newSceneName.c_str());
return RequestResult::Success();
}