requesthandler: Add GetSceneItemSourceName request

Closes #1122
This commit is contained in:
tt2468 2024-01-18 16:01:41 -08:00
parent 690726d281
commit 1d0db34bb2
3 changed files with 33 additions and 0 deletions

View File

@ -126,6 +126,7 @@ const std::unordered_map<std::string, RequestMethodHandler> RequestHandler::_han
{"GetSceneItemList", &RequestHandler::GetSceneItemList},
{"GetGroupSceneItemList", &RequestHandler::GetGroupSceneItemList},
{"GetSceneItemId", &RequestHandler::GetSceneItemId},
{"GetSceneItemSourceName", &RequestHandler::GetSceneItemSourceName},
{"CreateSceneItem", &RequestHandler::CreateSceneItem},
{"RemoveSceneItem", &RequestHandler::RemoveSceneItem},
{"DuplicateSceneItem", &RequestHandler::DuplicateSceneItem},

View File

@ -145,6 +145,7 @@ private:
RequestResult GetSceneItemList(const Request &);
RequestResult GetGroupSceneItemList(const Request &);
RequestResult GetSceneItemId(const Request &);
RequestResult GetSceneItemSourceName(const Request &);
RequestResult CreateSceneItem(const Request &);
RequestResult RemoveSceneItem(const Request &);
RequestResult DuplicateSceneItem(const Request &);

View File

@ -128,6 +128,37 @@ RequestResult RequestHandler::GetSceneItemId(const Request &request)
return RequestResult::Success(responseData);
}
/**
* Gets the source name of a scene item.
*
* @requestField sceneName | String | Name of the scene the item is in
* @requestField sceneItemId | Number | Numeric ID of the scene item | >= 0
*
* @responseField sourceName | String | Name of the source associated with the scene item
*
* @requestType GetSceneItemSourceName
* @complexity 3
* @rpcVersion -1
* @initialVersion 5.4.0
* @api requests
* @category scene items
*/
RequestResult RequestHandler::GetSceneItemSourceName(const Request &request)
{
RequestStatus::RequestStatus statusCode;
std::string comment;
OBSSceneItemAutoRelease sceneItem = request.ValidateSceneItem("sceneName", "sceneItemId", statusCode, comment);
if (!sceneItem)
return RequestResult::Error(statusCode, comment);
OBSSource source = obs_sceneitem_get_source(sceneItem);
json responseData;
responseData["sourceName"] = obs_source_get_name(source);
return RequestResult::Success(responseData);
}
/**
* Creates a new scene item using a source.
*