diff --git a/src/WSRequestHandler.cpp b/src/WSRequestHandler.cpp index 10e1c3b6..fdfc2e1e 100644 --- a/src/WSRequestHandler.cpp +++ b/src/WSRequestHandler.cpp @@ -24,7 +24,7 @@ #include "WSRequestHandler.h" -QHash WSRequestHandler::messageMap { +QHash WSRequestHandler::messageMap { { "GetVersion", WSRequestHandler::HandleGetVersion }, { "GetAuthRequired", WSRequestHandler::HandleGetAuthRequired }, { "Authenticate", WSRequestHandler::HandleAuthenticate }, @@ -136,7 +136,7 @@ WSRequestHandler::WSRequestHandler(QVariantHash& connProperties) : { } -std::string WSRequestHandler::processIncomingMessage(std::string& textMessage) { +obs_data_t* WSRequestHandler::processIncomingMessage(std::string& textMessage) { std::string msgContainer(textMessage); const char* msg = msgContainer.c_str(); @@ -164,7 +164,7 @@ std::string WSRequestHandler::processIncomingMessage(std::string& textMessage) { return SendErrorResponse("Not Authenticated"); } - std::string (*handlerFunc)(WSRequestHandler*) = (messageMap[_requestType]); + HandlerResponse (*handlerFunc)(WSRequestHandler*) = (messageMap[_requestType]); if (!handlerFunc) { return SendErrorResponse("invalid request type"); } @@ -175,45 +175,31 @@ std::string WSRequestHandler::processIncomingMessage(std::string& textMessage) { WSRequestHandler::~WSRequestHandler() { } -std::string WSRequestHandler::SendOKResponse(obs_data_t* additionalFields) { - OBSDataAutoRelease response = obs_data_create(); - obs_data_set_string(response, "status", "ok"); - obs_data_set_string(response, "message-id", _messageId); - - if (additionalFields) - obs_data_apply(response, additionalFields); - - return SendResponse(response); +HandlerResponse WSRequestHandler::SendOKResponse(obs_data_t* additionalFields) { + return SendResponse("ok", additionalFields); } -std::string WSRequestHandler::SendErrorResponse(const char* errorMessage) { - OBSDataAutoRelease response = obs_data_create(); - obs_data_set_string(response, "status", "error"); - obs_data_set_string(response, "error", errorMessage); - obs_data_set_string(response, "message-id", _messageId); +HandlerResponse WSRequestHandler::SendErrorResponse(const char* errorMessage) { + OBSDataAutoRelease fields = obs_data_create(); + obs_data_set_string(fields, "error", errorMessage); - return SendResponse(response); + return SendResponse("error", fields); } -std::string WSRequestHandler::SendErrorResponse(obs_data_t* additionalFields) { - OBSDataAutoRelease response = obs_data_create(); - obs_data_set_string(response, "status", "error"); - obs_data_set_string(response, "message-id", _messageId); - - if (additionalFields) - obs_data_set_obj(response, "error", additionalFields); - - return SendResponse(response); +HandlerResponse WSRequestHandler::SendErrorResponse(obs_data_t* additionalFields) { + return SendResponse("error", additionalFields); } -std::string WSRequestHandler::SendResponse(obs_data_t* response) { - std::string responseStr = obs_data_get_json(response); +HandlerResponse WSRequestHandler::SendResponse(const char* status, obs_data_t* fields) { + obs_data_t* response = obs_data_create(); + obs_data_set_string(response, "message-id", _messageId); + obs_data_set_string(response, "status", status); - if (Config::Current()->DebugEnabled) { - blog(LOG_DEBUG, "Response << '%s'", responseStr.c_str()); + if (fields) { + obs_data_apply(response, fields); } - return responseStr; + return response; } bool WSRequestHandler::hasField(QString name) { diff --git a/src/WSRequestHandler.h b/src/WSRequestHandler.h index d0175a90..19aa22bc 100644 --- a/src/WSRequestHandler.h +++ b/src/WSRequestHandler.h @@ -29,13 +29,15 @@ with this program. If not, see #include "obs-websocket.h" +typedef obs_data_t* HandlerResponse; + class WSRequestHandler : public QObject { Q_OBJECT public: explicit WSRequestHandler(QVariantHash& connProperties); ~WSRequestHandler(); - std::string processIncomingMessage(std::string& textMessage); + obs_data_t* processIncomingMessage(std::string& textMessage); bool hasField(QString name); private: @@ -44,109 +46,109 @@ class WSRequestHandler : public QObject { QVariantHash& _connProperties; OBSDataAutoRelease data; - std::string SendOKResponse(obs_data_t* additionalFields = NULL); - std::string SendErrorResponse(const char* errorMessage); - std::string SendErrorResponse(obs_data_t* additionalFields = NULL); - std::string SendResponse(obs_data_t* response); + HandlerResponse SendOKResponse(obs_data_t* additionalFields = nullptr); + HandlerResponse SendErrorResponse(const char* errorMessage); + HandlerResponse SendErrorResponse(obs_data_t* additionalFields = nullptr); + HandlerResponse SendResponse(const char* status, obs_data_t* additionalFields = nullptr); - static QHash messageMap; + static QHash messageMap; static QSet authNotRequired; - static std::string HandleGetVersion(WSRequestHandler* req); - static std::string HandleGetAuthRequired(WSRequestHandler* req); - static std::string HandleAuthenticate(WSRequestHandler* req); + static HandlerResponse HandleGetVersion(WSRequestHandler* req); + static HandlerResponse HandleGetAuthRequired(WSRequestHandler* req); + static HandlerResponse HandleAuthenticate(WSRequestHandler* req); - static std::string HandleSetHeartbeat(WSRequestHandler* req); + static HandlerResponse HandleSetHeartbeat(WSRequestHandler* req); - static std::string HandleSetFilenameFormatting(WSRequestHandler* req); - static std::string HandleGetFilenameFormatting(WSRequestHandler* req); + static HandlerResponse HandleSetFilenameFormatting(WSRequestHandler* req); + static HandlerResponse HandleGetFilenameFormatting(WSRequestHandler* req); - static std::string HandleSetCurrentScene(WSRequestHandler* req); - static std::string HandleGetCurrentScene(WSRequestHandler* req); - static std::string HandleGetSceneList(WSRequestHandler* req); + static HandlerResponse HandleSetCurrentScene(WSRequestHandler* req); + static HandlerResponse HandleGetCurrentScene(WSRequestHandler* req); + static HandlerResponse HandleGetSceneList(WSRequestHandler* req); - static std::string HandleSetSceneItemRender(WSRequestHandler* req); - static std::string HandleSetSceneItemPosition(WSRequestHandler* req); - static std::string HandleSetSceneItemTransform(WSRequestHandler* req); - static std::string HandleSetSceneItemCrop(WSRequestHandler* req); - static std::string HandleGetSceneItemProperties(WSRequestHandler* req); - static std::string HandleSetSceneItemProperties(WSRequestHandler* req); - static std::string HandleResetSceneItem(WSRequestHandler* req); - static std::string HandleDuplicateSceneItem(WSRequestHandler* req); - static std::string HandleDeleteSceneItem(WSRequestHandler* req); - static std::string HandleReorderSceneItems(WSRequestHandler* req); + static HandlerResponse HandleSetSceneItemRender(WSRequestHandler* req); + static HandlerResponse HandleSetSceneItemPosition(WSRequestHandler* req); + static HandlerResponse HandleSetSceneItemTransform(WSRequestHandler* req); + static HandlerResponse HandleSetSceneItemCrop(WSRequestHandler* req); + static HandlerResponse HandleGetSceneItemProperties(WSRequestHandler* req); + static HandlerResponse HandleSetSceneItemProperties(WSRequestHandler* req); + static HandlerResponse HandleResetSceneItem(WSRequestHandler* req); + static HandlerResponse HandleDuplicateSceneItem(WSRequestHandler* req); + static HandlerResponse HandleDeleteSceneItem(WSRequestHandler* req); + static HandlerResponse HandleReorderSceneItems(WSRequestHandler* req); - static std::string HandleGetStreamingStatus(WSRequestHandler* req); - static std::string HandleStartStopStreaming(WSRequestHandler* req); - static std::string HandleStartStopRecording(WSRequestHandler* req); - static std::string HandleStartStreaming(WSRequestHandler* req); - static std::string HandleStopStreaming(WSRequestHandler* req); - static std::string HandleStartRecording(WSRequestHandler* req); - static std::string HandleStopRecording(WSRequestHandler* req); + static HandlerResponse HandleGetStreamingStatus(WSRequestHandler* req); + static HandlerResponse HandleStartStopStreaming(WSRequestHandler* req); + static HandlerResponse HandleStartStopRecording(WSRequestHandler* req); + static HandlerResponse HandleStartStreaming(WSRequestHandler* req); + static HandlerResponse HandleStopStreaming(WSRequestHandler* req); + static HandlerResponse HandleStartRecording(WSRequestHandler* req); + static HandlerResponse HandleStopRecording(WSRequestHandler* req); - static std::string HandleStartStopReplayBuffer(WSRequestHandler* req); - static std::string HandleStartReplayBuffer(WSRequestHandler* req); - static std::string HandleStopReplayBuffer(WSRequestHandler* req); - static std::string HandleSaveReplayBuffer(WSRequestHandler* req); + static HandlerResponse HandleStartStopReplayBuffer(WSRequestHandler* req); + static HandlerResponse HandleStartReplayBuffer(WSRequestHandler* req); + static HandlerResponse HandleStopReplayBuffer(WSRequestHandler* req); + static HandlerResponse HandleSaveReplayBuffer(WSRequestHandler* req); - static std::string HandleSetRecordingFolder(WSRequestHandler* req); - static std::string HandleGetRecordingFolder(WSRequestHandler* req); + static HandlerResponse HandleSetRecordingFolder(WSRequestHandler* req); + static HandlerResponse HandleGetRecordingFolder(WSRequestHandler* req); - static std::string HandleGetTransitionList(WSRequestHandler* req); - static std::string HandleGetCurrentTransition(WSRequestHandler* req); - static std::string HandleSetCurrentTransition(WSRequestHandler* req); + static HandlerResponse HandleGetTransitionList(WSRequestHandler* req); + static HandlerResponse HandleGetCurrentTransition(WSRequestHandler* req); + static HandlerResponse HandleSetCurrentTransition(WSRequestHandler* req); - static std::string HandleSetVolume(WSRequestHandler* req); - static std::string HandleGetVolume(WSRequestHandler* req); - static std::string HandleToggleMute(WSRequestHandler* req); - static std::string HandleSetMute(WSRequestHandler* req); - static std::string HandleGetMute(WSRequestHandler* req); - static std::string HandleSetSyncOffset(WSRequestHandler* req); - static std::string HandleGetSyncOffset(WSRequestHandler* req); - static std::string HandleGetSpecialSources(WSRequestHandler* req); - static std::string HandleGetSourcesList(WSRequestHandler* req); - static std::string HandleGetSourceTypesList(WSRequestHandler* req); - static std::string HandleGetSourceSettings(WSRequestHandler* req); - static std::string HandleSetSourceSettings(WSRequestHandler* req); + static HandlerResponse HandleSetVolume(WSRequestHandler* req); + static HandlerResponse HandleGetVolume(WSRequestHandler* req); + static HandlerResponse HandleToggleMute(WSRequestHandler* req); + static HandlerResponse HandleSetMute(WSRequestHandler* req); + static HandlerResponse HandleGetMute(WSRequestHandler* req); + static HandlerResponse HandleSetSyncOffset(WSRequestHandler* req); + static HandlerResponse HandleGetSyncOffset(WSRequestHandler* req); + static HandlerResponse HandleGetSpecialSources(WSRequestHandler* req); + static HandlerResponse HandleGetSourcesList(WSRequestHandler* req); + static HandlerResponse HandleGetSourceTypesList(WSRequestHandler* req); + static HandlerResponse HandleGetSourceSettings(WSRequestHandler* req); + static HandlerResponse HandleSetSourceSettings(WSRequestHandler* req); - static std::string HandleGetSourceFilters(WSRequestHandler* req); - static std::string HandleAddFilterToSource(WSRequestHandler* req); - static std::string HandleRemoveFilterFromSource(WSRequestHandler* req); - static std::string HandleReorderSourceFilter(WSRequestHandler* req); - static std::string HandleMoveSourceFilter(WSRequestHandler* req); - static std::string HandleSetSourceFilterSettings(WSRequestHandler* req); + static HandlerResponse HandleGetSourceFilters(WSRequestHandler* req); + static HandlerResponse HandleAddFilterToSource(WSRequestHandler* req); + static HandlerResponse HandleRemoveFilterFromSource(WSRequestHandler* req); + static HandlerResponse HandleReorderSourceFilter(WSRequestHandler* req); + static HandlerResponse HandleMoveSourceFilter(WSRequestHandler* req); + static HandlerResponse HandleSetSourceFilterSettings(WSRequestHandler* req); - static std::string HandleSetCurrentSceneCollection(WSRequestHandler* req); - static std::string HandleGetCurrentSceneCollection(WSRequestHandler* req); - static std::string HandleListSceneCollections(WSRequestHandler* req); + static HandlerResponse HandleSetCurrentSceneCollection(WSRequestHandler* req); + static HandlerResponse HandleGetCurrentSceneCollection(WSRequestHandler* req); + static HandlerResponse HandleListSceneCollections(WSRequestHandler* req); - static std::string HandleSetCurrentProfile(WSRequestHandler* req); - static std::string HandleGetCurrentProfile(WSRequestHandler* req); - static std::string HandleListProfiles(WSRequestHandler* req); + static HandlerResponse HandleSetCurrentProfile(WSRequestHandler* req); + static HandlerResponse HandleGetCurrentProfile(WSRequestHandler* req); + static HandlerResponse HandleListProfiles(WSRequestHandler* req); - static std::string HandleSetStreamSettings(WSRequestHandler* req); - static std::string HandleGetStreamSettings(WSRequestHandler* req); - static std::string HandleSaveStreamSettings(WSRequestHandler* req); + static HandlerResponse HandleSetStreamSettings(WSRequestHandler* req); + static HandlerResponse HandleGetStreamSettings(WSRequestHandler* req); + static HandlerResponse HandleSaveStreamSettings(WSRequestHandler* req); - static std::string HandleSetTransitionDuration(WSRequestHandler* req); - static std::string HandleGetTransitionDuration(WSRequestHandler* req); + static HandlerResponse HandleSetTransitionDuration(WSRequestHandler* req); + static HandlerResponse HandleGetTransitionDuration(WSRequestHandler* req); - static std::string HandleGetStudioModeStatus(WSRequestHandler* req); - static std::string HandleGetPreviewScene(WSRequestHandler* req); - static std::string HandleSetPreviewScene(WSRequestHandler* req); - static std::string HandleTransitionToProgram(WSRequestHandler* req); - static std::string HandleEnableStudioMode(WSRequestHandler* req); - static std::string HandleDisableStudioMode(WSRequestHandler* req); - static std::string HandleToggleStudioMode(WSRequestHandler* req); + static HandlerResponse HandleGetStudioModeStatus(WSRequestHandler* req); + static HandlerResponse HandleGetPreviewScene(WSRequestHandler* req); + static HandlerResponse HandleSetPreviewScene(WSRequestHandler* req); + static HandlerResponse HandleTransitionToProgram(WSRequestHandler* req); + static HandlerResponse HandleEnableStudioMode(WSRequestHandler* req); + static HandlerResponse HandleDisableStudioMode(WSRequestHandler* req); + static HandlerResponse HandleToggleStudioMode(WSRequestHandler* req); - static std::string HandleSetTextGDIPlusProperties(WSRequestHandler* req); - static std::string HandleGetTextGDIPlusProperties(WSRequestHandler* req); + static HandlerResponse HandleSetTextGDIPlusProperties(WSRequestHandler* req); + static HandlerResponse HandleGetTextGDIPlusProperties(WSRequestHandler* req); - static std::string HandleSetTextFreetype2Properties(WSRequestHandler* req); - static std::string HandleGetTextFreetype2Properties(WSRequestHandler* req); + static HandlerResponse HandleSetTextFreetype2Properties(WSRequestHandler* req); + static HandlerResponse HandleGetTextFreetype2Properties(WSRequestHandler* req); - static std::string HandleSetBrowserSourceProperties(WSRequestHandler* req); - static std::string HandleGetBrowserSourceProperties(WSRequestHandler* req); + static HandlerResponse HandleSetBrowserSourceProperties(WSRequestHandler* req); + static HandlerResponse HandleGetBrowserSourceProperties(WSRequestHandler* req); }; #endif // WSPROTOCOL_H diff --git a/src/WSRequestHandler_General.cpp b/src/WSRequestHandler_General.cpp index c56fe011..b28ac633 100644 --- a/src/WSRequestHandler_General.cpp +++ b/src/WSRequestHandler_General.cpp @@ -19,7 +19,7 @@ * @category general * @since 0.3 */ -std::string WSRequestHandler::HandleGetVersion(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleGetVersion(WSRequestHandler* req) { QString obsVersion = Utils::OBSVersionString(); QList names = req->messageMap.keys(); @@ -53,7 +53,7 @@ std::string WSRequestHandler::HandleGetVersion(WSRequestHandler* req) { * @category general * @since 0.3 */ -std::string WSRequestHandler::HandleGetAuthRequired(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleGetAuthRequired(WSRequestHandler* req) { bool authRequired = Config::Current()->AuthRequired; OBSDataAutoRelease data = obs_data_create(); @@ -79,7 +79,7 @@ std::string WSRequestHandler::HandleGetAuthRequired(WSRequestHandler* req) { * @category general * @since 0.3 */ -std::string WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) { if (!req->hasField("auth")) { return req->SendErrorResponse("missing request parameters"); } @@ -111,7 +111,7 @@ std::string WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) { * @category general * @since 4.3.0 */ -std::string WSRequestHandler::HandleSetHeartbeat(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleSetHeartbeat(WSRequestHandler* req) { if (!req->hasField("enable")) { return req->SendErrorResponse("Heartbeat parameter missing"); } @@ -134,7 +134,7 @@ std::string WSRequestHandler::HandleSetHeartbeat(WSRequestHandler* req) { * @category general * @since 4.3.0 */ -std::string WSRequestHandler::HandleSetFilenameFormatting(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleSetFilenameFormatting(WSRequestHandler* req) { if (!req->hasField("filename-formatting")) { return req->SendErrorResponse(" parameter missing"); } @@ -158,7 +158,7 @@ std::string WSRequestHandler::HandleSetFilenameFormatting(WSRequestHandler* req) * @category general * @since 4.3.0 */ -std::string WSRequestHandler::HandleGetFilenameFormatting(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleGetFilenameFormatting(WSRequestHandler* req) { OBSDataAutoRelease response = obs_data_create(); obs_data_set_string(response, "filename-formatting", Utils::GetFilenameFormatting()); return req->SendOKResponse(response); diff --git a/src/WSRequestHandler_Profiles.cpp b/src/WSRequestHandler_Profiles.cpp index b658cd54..0d90ac5f 100644 --- a/src/WSRequestHandler_Profiles.cpp +++ b/src/WSRequestHandler_Profiles.cpp @@ -13,7 +13,7 @@ * @category profiles * @since 4.0.0 */ -std::string WSRequestHandler::HandleSetCurrentProfile(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleSetCurrentProfile(WSRequestHandler* req) { if (!req->hasField("profile-name")) { return req->SendErrorResponse("missing request parameters"); } @@ -38,7 +38,7 @@ std::string WSRequestHandler::HandleSetCurrentProfile(WSRequestHandler* req) { * @category profiles * @since 4.0.0 */ -std::string WSRequestHandler::HandleGetCurrentProfile(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleGetCurrentProfile(WSRequestHandler* req) { OBSDataAutoRelease response = obs_data_create(); obs_data_set_string(response, "profile-name", obs_frontend_get_current_profile()); return req->SendOKResponse(response); @@ -54,7 +54,7 @@ std::string WSRequestHandler::HandleGetCurrentProfile(WSRequestHandler* req) { * @category profiles * @since 4.0.0 */ -std::string WSRequestHandler::HandleListProfiles(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleListProfiles(WSRequestHandler* req) { char** profiles = obs_frontend_get_profiles(); OBSDataArrayAutoRelease list = Utils::StringListToArray(profiles, "profile-name"); bfree(profiles); diff --git a/src/WSRequestHandler_Recording.cpp b/src/WSRequestHandler_Recording.cpp index 3b157091..3c2bff6f 100644 --- a/src/WSRequestHandler_Recording.cpp +++ b/src/WSRequestHandler_Recording.cpp @@ -11,7 +11,7 @@ * @category recording * @since 0.3 */ -std::string WSRequestHandler::HandleStartStopRecording(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleStartStopRecording(WSRequestHandler* req) { if (obs_frontend_recording_active()) obs_frontend_recording_stop(); else @@ -29,7 +29,7 @@ std::string WSRequestHandler::HandleStartStopRecording(WSRequestHandler* req) { * @category recording * @since 4.1.0 */ - std::string WSRequestHandler::HandleStartRecording(WSRequestHandler* req) { + HandlerResponse WSRequestHandler::HandleStartRecording(WSRequestHandler* req) { if (obs_frontend_recording_active() == false) { obs_frontend_recording_start(); return req->SendOKResponse(); @@ -47,7 +47,7 @@ std::string WSRequestHandler::HandleStartStopRecording(WSRequestHandler* req) { * @category recording * @since 4.1.0 */ - std::string WSRequestHandler::HandleStopRecording(WSRequestHandler* req) { + HandlerResponse WSRequestHandler::HandleStopRecording(WSRequestHandler* req) { if (obs_frontend_recording_active() == true) { obs_frontend_recording_stop(); return req->SendOKResponse(); @@ -66,7 +66,7 @@ std::string WSRequestHandler::HandleStartStopRecording(WSRequestHandler* req) { * @category recording * @since 4.1.0 */ -std::string WSRequestHandler::HandleSetRecordingFolder(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleSetRecordingFolder(WSRequestHandler* req) { if (!req->hasField("rec-folder")) { return req->SendErrorResponse("missing request parameters"); } @@ -90,7 +90,7 @@ std::string WSRequestHandler::HandleSetRecordingFolder(WSRequestHandler* req) { * @category recording * @since 4.1.0 */ -std::string WSRequestHandler::HandleGetRecordingFolder(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleGetRecordingFolder(WSRequestHandler* req) { const char* recFolder = Utils::GetRecordingFolder(); OBSDataAutoRelease response = obs_data_create(); diff --git a/src/WSRequestHandler_ReplayBuffer.cpp b/src/WSRequestHandler_ReplayBuffer.cpp index f5104dc0..cb699535 100644 --- a/src/WSRequestHandler_ReplayBuffer.cpp +++ b/src/WSRequestHandler_ReplayBuffer.cpp @@ -11,7 +11,7 @@ * @category replay buffer * @since 4.2.0 */ -std::string WSRequestHandler::HandleStartStopReplayBuffer(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleStartStopReplayBuffer(WSRequestHandler* req) { if (obs_frontend_replay_buffer_active()) { obs_frontend_replay_buffer_stop(); } else { @@ -32,7 +32,7 @@ std::string WSRequestHandler::HandleStartStopReplayBuffer(WSRequestHandler* req) * @category replay buffer * @since 4.2.0 */ -std::string WSRequestHandler::HandleStartReplayBuffer(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleStartReplayBuffer(WSRequestHandler* req) { if (!Utils::ReplayBufferEnabled()) { return req->SendErrorResponse("replay buffer disabled in settings"); } @@ -54,7 +54,7 @@ std::string WSRequestHandler::HandleStartReplayBuffer(WSRequestHandler* req) { * @category replay buffer * @since 4.2.0 */ -std::string WSRequestHandler::HandleStopReplayBuffer(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleStopReplayBuffer(WSRequestHandler* req) { if (obs_frontend_replay_buffer_active() == true) { obs_frontend_replay_buffer_stop(); return req->SendOKResponse(); @@ -73,7 +73,7 @@ std::string WSRequestHandler::HandleStopReplayBuffer(WSRequestHandler* req) { * @category replay buffer * @since 4.2.0 */ -std::string WSRequestHandler::HandleSaveReplayBuffer(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleSaveReplayBuffer(WSRequestHandler* req) { if (!obs_frontend_replay_buffer_active()) { return req->SendErrorResponse("replay buffer not active"); } diff --git a/src/WSRequestHandler_SceneCollections.cpp b/src/WSRequestHandler_SceneCollections.cpp index 70829de9..2862e681 100644 --- a/src/WSRequestHandler_SceneCollections.cpp +++ b/src/WSRequestHandler_SceneCollections.cpp @@ -13,7 +13,7 @@ * @category scene collections * @since 4.0.0 */ -std::string WSRequestHandler::HandleSetCurrentSceneCollection(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleSetCurrentSceneCollection(WSRequestHandler* req) { if (!req->hasField("sc-name")) { return req->SendErrorResponse("missing request parameters"); } @@ -38,7 +38,7 @@ std::string WSRequestHandler::HandleSetCurrentSceneCollection(WSRequestHandler* * @category scene collections * @since 4.0.0 */ -std::string WSRequestHandler::HandleGetCurrentSceneCollection(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleGetCurrentSceneCollection(WSRequestHandler* req) { OBSDataAutoRelease response = obs_data_create(); obs_data_set_string(response, "sc-name", obs_frontend_get_current_scene_collection()); @@ -56,7 +56,7 @@ std::string WSRequestHandler::HandleGetCurrentSceneCollection(WSRequestHandler* * @category scene collections * @since 4.0.0 */ -std::string WSRequestHandler::HandleListSceneCollections(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleListSceneCollections(WSRequestHandler* req) { char** sceneCollections = obs_frontend_get_scene_collections(); OBSDataArrayAutoRelease list = Utils::StringListToArray(sceneCollections, "sc-name"); diff --git a/src/WSRequestHandler_SceneItems.cpp b/src/WSRequestHandler_SceneItems.cpp index 8d5424b4..ddc8d336 100644 --- a/src/WSRequestHandler_SceneItems.cpp +++ b/src/WSRequestHandler_SceneItems.cpp @@ -31,7 +31,7 @@ * @category scene items * @since 4.3.0 */ -std::string WSRequestHandler::HandleGetSceneItemProperties(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleGetSceneItemProperties(WSRequestHandler* req) { if (!req->hasField("item")) { return req->SendErrorResponse("missing request parameters"); } @@ -153,7 +153,7 @@ std::string WSRequestHandler::HandleGetSceneItemProperties(WSRequestHandler* req * @category scene items * @since 4.3.0 */ -std::string WSRequestHandler::HandleSetSceneItemProperties(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleSetSceneItemProperties(WSRequestHandler* req) { if (!req->hasField("item")) { return req->SendErrorResponse("missing request parameters"); } @@ -321,7 +321,7 @@ std::string WSRequestHandler::HandleSetSceneItemProperties(WSRequestHandler* req * @category scene items * @since 4.2.0 */ -std::string WSRequestHandler::HandleResetSceneItem(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleResetSceneItem(WSRequestHandler* req) { // TODO: remove this request, or refactor it to ResetSource if (!req->hasField("item")) { @@ -365,7 +365,7 @@ std::string WSRequestHandler::HandleResetSceneItem(WSRequestHandler* req) { * @since 0.3 * @deprecated Since 4.3.0. Prefer the use of SetSceneItemProperties. */ -std::string WSRequestHandler::HandleSetSceneItemRender(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleSetSceneItemRender(WSRequestHandler* req) { if (!req->hasField("source") || !req->hasField("render")) { @@ -410,7 +410,7 @@ std::string WSRequestHandler::HandleSetSceneItemRender(WSRequestHandler* req) { * @since 4.0.0 * @deprecated Since 4.3.0. Prefer the use of SetSceneItemProperties. */ -std::string WSRequestHandler::HandleSetSceneItemPosition(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleSetSceneItemPosition(WSRequestHandler* req) { if (!req->hasField("item") || !req->hasField("x") || !req->hasField("y")) { return req->SendErrorResponse("missing request parameters"); @@ -455,7 +455,7 @@ std::string WSRequestHandler::HandleSetSceneItemPosition(WSRequestHandler* req) * @since 4.0.0 * @deprecated Since 4.3.0. Prefer the use of SetSceneItemProperties. */ -std::string WSRequestHandler::HandleSetSceneItemTransform(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleSetSceneItemTransform(WSRequestHandler* req) { if (!req->hasField("item") || !req->hasField("x-scale") || !req->hasField("y-scale") || @@ -506,7 +506,7 @@ std::string WSRequestHandler::HandleSetSceneItemTransform(WSRequestHandler* req) * @since 4.1.0 * @deprecated Since 4.3.0. Prefer the use of SetSceneItemProperties. */ -std::string WSRequestHandler::HandleSetSceneItemCrop(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleSetSceneItemCrop(WSRequestHandler* req) { if (!req->hasField("item")) { return req->SendErrorResponse("missing request parameters"); } @@ -551,7 +551,7 @@ std::string WSRequestHandler::HandleSetSceneItemCrop(WSRequestHandler* req) { * @category scene items * @since 4.5.0 */ -std::string WSRequestHandler::HandleDeleteSceneItem(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleDeleteSceneItem(WSRequestHandler* req) { if (!req->hasField("item")) { return req->SendErrorResponse("missing request parameters"); } @@ -604,7 +604,7 @@ static void DuplicateSceneItem(void *_data, obs_scene_t *scene) { * @category scene items * @since 4.5.0 */ -std::string WSRequestHandler::HandleDuplicateSceneItem(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleDuplicateSceneItem(WSRequestHandler* req) { if (!req->hasField("item")) { return req->SendErrorResponse("missing request parameters"); } diff --git a/src/WSRequestHandler_Scenes.cpp b/src/WSRequestHandler_Scenes.cpp index c9afa3c1..3cdbf8ad 100644 --- a/src/WSRequestHandler_Scenes.cpp +++ b/src/WSRequestHandler_Scenes.cpp @@ -19,7 +19,7 @@ * @category scenes * @since 0.3 */ -std::string WSRequestHandler::HandleSetCurrentScene(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleSetCurrentScene(WSRequestHandler* req) { if (!req->hasField("scene-name")) { return req->SendErrorResponse("missing request parameters"); } @@ -46,7 +46,7 @@ std::string WSRequestHandler::HandleSetCurrentScene(WSRequestHandler* req) { * @category scenes * @since 0.3 */ -std::string WSRequestHandler::HandleGetCurrentScene(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleGetCurrentScene(WSRequestHandler* req) { OBSSourceAutoRelease currentScene = obs_frontend_get_current_scene(); OBSDataArrayAutoRelease sceneItems = Utils::GetSceneItems(currentScene); @@ -68,7 +68,7 @@ std::string WSRequestHandler::HandleGetCurrentScene(WSRequestHandler* req) { * @category scenes * @since 0.3 */ -std::string WSRequestHandler::HandleGetSceneList(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleGetSceneList(WSRequestHandler* req) { OBSSourceAutoRelease currentScene = obs_frontend_get_current_scene(); OBSDataArrayAutoRelease scenes = Utils::GetScenes(); @@ -93,7 +93,7 @@ std::string WSRequestHandler::HandleGetSceneList(WSRequestHandler* req) { * @category scenes * @since 4.5.0 */ -std::string WSRequestHandler::HandleReorderSceneItems(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleReorderSceneItems(WSRequestHandler* req) { QString sceneName = obs_data_get_string(req->data, "scene"); OBSSourceAutoRelease scene = Utils::GetSceneFromNameOrCurrent(sceneName); if (!scene) { diff --git a/src/WSRequestHandler_Sources.cpp b/src/WSRequestHandler_Sources.cpp index 6d5c553e..7372b3f5 100644 --- a/src/WSRequestHandler_Sources.cpp +++ b/src/WSRequestHandler_Sources.cpp @@ -30,7 +30,7 @@ * @category sources * @since 4.3.0 */ -std::string WSRequestHandler::HandleGetSourcesList(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleGetSourcesList(WSRequestHandler* req) { OBSDataArrayAutoRelease sourcesArray = obs_data_array_create(); @@ -98,7 +98,7 @@ std::string WSRequestHandler::HandleGetSourcesList(WSRequestHandler* req) * @category sources * @since 4.3.0 */ -std::string WSRequestHandler::HandleGetSourceTypesList(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleGetSourceTypesList(WSRequestHandler* req) { OBSDataArrayAutoRelease idsArray = obs_data_array_create(); @@ -168,7 +168,7 @@ std::string WSRequestHandler::HandleGetSourceTypesList(WSRequestHandler* req) * @category sources * @since 4.0.0 */ -std::string WSRequestHandler::HandleGetVolume(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleGetVolume(WSRequestHandler* req) { if (!req->hasField("source")) { return req->SendErrorResponse("missing request parameters"); @@ -203,7 +203,7 @@ std::string WSRequestHandler::HandleGetVolume(WSRequestHandler* req) * @category sources * @since 4.0.0 */ -std::string WSRequestHandler::HandleSetVolume(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleSetVolume(WSRequestHandler* req) { if (!req->hasField("source") || !req->hasField("volume")) { return req->SendErrorResponse("missing request parameters"); @@ -238,7 +238,7 @@ std::string WSRequestHandler::HandleSetVolume(WSRequestHandler* req) * @category sources * @since 4.0.0 */ -std::string WSRequestHandler::HandleGetMute(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleGetMute(WSRequestHandler* req) { if (!req->hasField("source")) { return req->SendErrorResponse("missing request parameters"); @@ -272,7 +272,7 @@ std::string WSRequestHandler::HandleGetMute(WSRequestHandler* req) * @category sources * @since 4.0.0 */ -std::string WSRequestHandler::HandleSetMute(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleSetMute(WSRequestHandler* req) { if (!req->hasField("source") || !req->hasField("mute")) { return req->SendErrorResponse("missing request parameters"); @@ -304,7 +304,7 @@ std::string WSRequestHandler::HandleSetMute(WSRequestHandler* req) * @category sources * @since 4.0.0 */ -std::string WSRequestHandler::HandleToggleMute(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleToggleMute(WSRequestHandler* req) { if (!req->hasField("source")) { return req->SendErrorResponse("missing request parameters"); @@ -335,7 +335,7 @@ std::string WSRequestHandler::HandleToggleMute(WSRequestHandler* req) * @category sources * @since 4.2.0 */ -std::string WSRequestHandler::HandleSetSyncOffset(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleSetSyncOffset(WSRequestHandler* req) { if (!req->hasField("source") || !req->hasField("offset")) { return req->SendErrorResponse("missing request parameters"); @@ -370,7 +370,7 @@ std::string WSRequestHandler::HandleSetSyncOffset(WSRequestHandler* req) * @category sources * @since 4.2.0 */ -std::string WSRequestHandler::HandleGetSyncOffset(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleGetSyncOffset(WSRequestHandler* req) { if (!req->hasField("source")) { return req->SendErrorResponse("missing request parameters"); @@ -408,7 +408,7 @@ std::string WSRequestHandler::HandleGetSyncOffset(WSRequestHandler* req) * @category sources * @since 4.3.0 */ -std::string WSRequestHandler::HandleGetSourceSettings(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleGetSourceSettings(WSRequestHandler* req) { if (!req->hasField("sourceName")) { return req->SendErrorResponse("missing request parameters"); @@ -455,7 +455,7 @@ std::string WSRequestHandler::HandleGetSourceSettings(WSRequestHandler* req) * @category sources * @since 4.3.0 */ -std::string WSRequestHandler::HandleSetSourceSettings(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleSetSourceSettings(WSRequestHandler* req) { if (!req->hasField("sourceName") || !req->hasField("sourceSettings")) { return req->SendErrorResponse("missing request parameters"); @@ -533,7 +533,7 @@ std::string WSRequestHandler::HandleSetSourceSettings(WSRequestHandler* req) * @category sources * @since 4.1.0 */ -std::string WSRequestHandler::HandleGetTextGDIPlusProperties(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleGetTextGDIPlusProperties(WSRequestHandler* req) { const char* sourceName = obs_data_get_string(req->data, "source"); if (!sourceName) { @@ -594,7 +594,7 @@ std::string WSRequestHandler::HandleGetTextGDIPlusProperties(WSRequestHandler* r * @category sources * @since 4.1.0 */ -std::string WSRequestHandler::HandleSetTextGDIPlusProperties(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleSetTextGDIPlusProperties(WSRequestHandler* req) { if (!req->hasField("source")) { return req->SendErrorResponse("missing request parameters"); @@ -764,7 +764,7 @@ std::string WSRequestHandler::HandleSetTextGDIPlusProperties(WSRequestHandler* r * @category sources * @since 4.5.0 */ -std::string WSRequestHandler::HandleGetTextFreetype2Properties(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleGetTextFreetype2Properties(WSRequestHandler* req) { const char* sourceName = obs_data_get_string(req->data, "source"); if (!sourceName) { @@ -812,7 +812,7 @@ std::string WSRequestHandler::HandleGetTextFreetype2Properties(WSRequestHandler* * @category sources * @since 4.5.0 */ -std::string WSRequestHandler::HandleSetTextFreetype2Properties(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleSetTextFreetype2Properties(WSRequestHandler* req) { const char* sourceName = obs_data_get_string(req->data, "source"); if (!sourceName) { @@ -919,7 +919,7 @@ std::string WSRequestHandler::HandleSetTextFreetype2Properties(WSRequestHandler* * @category sources * @since 4.1.0 */ -std::string WSRequestHandler::HandleGetBrowserSourceProperties(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleGetBrowserSourceProperties(WSRequestHandler* req) { const char* sourceName = obs_data_get_string(req->data, "source"); if (!sourceName) { @@ -961,7 +961,7 @@ std::string WSRequestHandler::HandleGetBrowserSourceProperties(WSRequestHandler* * @category sources * @since 4.1.0 */ -std::string WSRequestHandler::HandleSetBrowserSourceProperties(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleSetBrowserSourceProperties(WSRequestHandler* req) { if (!req->hasField("source")) { return req->SendErrorResponse("missing request parameters"); @@ -1039,7 +1039,7 @@ std::string WSRequestHandler::HandleSetBrowserSourceProperties(WSRequestHandler* * @category sources * @since 4.1.0 */ -std::string WSRequestHandler::HandleGetSpecialSources(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleGetSpecialSources(WSRequestHandler* req) { OBSDataAutoRelease response = obs_data_create(); @@ -1079,7 +1079,7 @@ std::string WSRequestHandler::HandleGetSpecialSources(WSRequestHandler* req) * @category sources * @since 4.5.0 */ -std::string WSRequestHandler::HandleGetSourceFilters(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleGetSourceFilters(WSRequestHandler* req) { if (!req->hasField("sourceName")) { return req->SendErrorResponse("missing request parameters"); @@ -1120,7 +1120,7 @@ std::string WSRequestHandler::HandleGetSourceFilters(WSRequestHandler* req) * @category sources * @since 4.5.0 */ -std::string WSRequestHandler::HandleAddFilterToSource(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleAddFilterToSource(WSRequestHandler* req) { if (!req->hasField("sourceName") || !req->hasField("filterName") || !req->hasField("filterType") || !req->hasField("filterSettings")) @@ -1167,7 +1167,7 @@ std::string WSRequestHandler::HandleAddFilterToSource(WSRequestHandler* req) * @category sources * @since 4.5.0 */ -std::string WSRequestHandler::HandleRemoveFilterFromSource(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleRemoveFilterFromSource(WSRequestHandler* req) { if (!req->hasField("sourceName") || !req->hasField("filterName")) { return req->SendErrorResponse("missing request parameters"); @@ -1203,7 +1203,7 @@ std::string WSRequestHandler::HandleRemoveFilterFromSource(WSRequestHandler* req * @category sources * @since 4.5.0 */ -std::string WSRequestHandler::HandleReorderSourceFilter(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleReorderSourceFilter(WSRequestHandler* req) { if (!req->hasField("sourceName") || !req->hasField("filterName") || !req->hasField("newIndex")) { return req->SendErrorResponse("missing request parameters"); @@ -1276,7 +1276,7 @@ std::string WSRequestHandler::HandleReorderSourceFilter(WSRequestHandler* req) * @category sources * @since 4.5.0 */ -std::string WSRequestHandler::HandleMoveSourceFilter(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleMoveSourceFilter(WSRequestHandler* req) { if (!req->hasField("sourceName") || !req->hasField("filterName") || !req->hasField("movementType")) { return req->SendErrorResponse("missing request parameters"); @@ -1330,7 +1330,7 @@ std::string WSRequestHandler::HandleMoveSourceFilter(WSRequestHandler* req) * @category sources * @since 4.5.0 */ -std::string WSRequestHandler::HandleSetSourceFilterSettings(WSRequestHandler* req) +HandlerResponse WSRequestHandler::HandleSetSourceFilterSettings(WSRequestHandler* req) { if (!req->hasField("sourceName") || !req->hasField("filterName") || !req->hasField("filterSettings")) { return req->SendErrorResponse("missing request parameters"); diff --git a/src/WSRequestHandler_Streaming.cpp b/src/WSRequestHandler_Streaming.cpp index 79808584..3a5e29f8 100644 --- a/src/WSRequestHandler_Streaming.cpp +++ b/src/WSRequestHandler_Streaming.cpp @@ -20,7 +20,7 @@ * @category streaming * @since 0.3 */ -std::string WSRequestHandler::HandleGetStreamingStatus(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleGetStreamingStatus(WSRequestHandler* req) { auto events = WSEvents::Current(); OBSDataAutoRelease data = obs_data_create(); @@ -52,7 +52,7 @@ std::string WSRequestHandler::HandleGetStreamingStatus(WSRequestHandler* req) { * @category streaming * @since 0.3 */ -std::string WSRequestHandler::HandleStartStopStreaming(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleStartStopStreaming(WSRequestHandler* req) { if (obs_frontend_streaming_active()) return HandleStopStreaming(req); else @@ -78,7 +78,7 @@ std::string WSRequestHandler::HandleStartStopStreaming(WSRequestHandler* req) { * @category streaming * @since 4.1.0 */ -std::string WSRequestHandler::HandleStartStreaming(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleStartStreaming(WSRequestHandler* req) { if (obs_frontend_streaming_active() == false) { OBSService configuredService = obs_frontend_get_streaming_service(); OBSService newService = nullptr; @@ -174,7 +174,7 @@ std::string WSRequestHandler::HandleStartStreaming(WSRequestHandler* req) { * @category streaming * @since 4.1.0 */ -std::string WSRequestHandler::HandleStopStreaming(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleStopStreaming(WSRequestHandler* req) { if (obs_frontend_streaming_active() == true) { obs_frontend_streaming_stop(); return req->SendOKResponse(); @@ -200,7 +200,7 @@ std::string WSRequestHandler::HandleStopStreaming(WSRequestHandler* req) { * @category streaming * @since 4.1.0 */ -std::string WSRequestHandler::HandleSetStreamSettings(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleSetStreamSettings(WSRequestHandler* req) { OBSService service = obs_frontend_get_streaming_service(); OBSDataAutoRelease requestSettings = obs_data_get_obj(req->data, "settings"); @@ -262,7 +262,7 @@ std::string WSRequestHandler::HandleSetStreamSettings(WSRequestHandler* req) { * @category streaming * @since 4.1.0 */ -std::string WSRequestHandler::HandleGetStreamSettings(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleGetStreamSettings(WSRequestHandler* req) { OBSService service = obs_frontend_get_streaming_service(); const char* serviceType = obs_service_get_type(service); @@ -283,7 +283,7 @@ std::string WSRequestHandler::HandleGetStreamSettings(WSRequestHandler* req) { * @category streaming * @since 4.1.0 */ -std::string WSRequestHandler::HandleSaveStreamSettings(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleSaveStreamSettings(WSRequestHandler* req) { obs_frontend_save_streaming_service(); return req->SendOKResponse(); } diff --git a/src/WSRequestHandler_StudioMode.cpp b/src/WSRequestHandler_StudioMode.cpp index d8a614f8..12d0a0bd 100644 --- a/src/WSRequestHandler_StudioMode.cpp +++ b/src/WSRequestHandler_StudioMode.cpp @@ -13,7 +13,7 @@ * @category studio mode * @since 4.1.0 */ -std::string WSRequestHandler::HandleGetStudioModeStatus(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleGetStudioModeStatus(WSRequestHandler* req) { bool previewActive = obs_frontend_preview_program_mode_active(); OBSDataAutoRelease response = obs_data_create(); @@ -34,7 +34,7 @@ std::string WSRequestHandler::HandleGetStudioModeStatus(WSRequestHandler* req) { * @category studio mode * @since 4.1.0 */ -std::string WSRequestHandler::HandleGetPreviewScene(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleGetPreviewScene(WSRequestHandler* req) { if (!obs_frontend_preview_program_mode_active()) { return req->SendErrorResponse("studio mode not enabled"); } @@ -60,7 +60,7 @@ std::string WSRequestHandler::HandleGetPreviewScene(WSRequestHandler* req) { * @category studio mode * @since 4.1.0 */ -std::string WSRequestHandler::HandleSetPreviewScene(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleSetPreviewScene(WSRequestHandler* req) { if (!obs_frontend_preview_program_mode_active()) { return req->SendErrorResponse("studio mode not enabled"); } @@ -92,7 +92,7 @@ std::string WSRequestHandler::HandleSetPreviewScene(WSRequestHandler* req) { * @category studio mode * @since 4.1.0 */ -std::string WSRequestHandler::HandleTransitionToProgram(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleTransitionToProgram(WSRequestHandler* req) { if (!obs_frontend_preview_program_mode_active()) { return req->SendErrorResponse("studio mode not enabled"); } @@ -133,7 +133,7 @@ std::string WSRequestHandler::HandleTransitionToProgram(WSRequestHandler* req) { * @category studio mode * @since 4.1.0 */ -std::string WSRequestHandler::HandleEnableStudioMode(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleEnableStudioMode(WSRequestHandler* req) { obs_frontend_set_preview_program_mode(true); return req->SendOKResponse(); } @@ -146,7 +146,7 @@ std::string WSRequestHandler::HandleEnableStudioMode(WSRequestHandler* req) { * @category studio mode * @since 4.1.0 */ -std::string WSRequestHandler::HandleDisableStudioMode(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleDisableStudioMode(WSRequestHandler* req) { obs_frontend_set_preview_program_mode(false); return req->SendOKResponse(); } @@ -159,7 +159,7 @@ std::string WSRequestHandler::HandleDisableStudioMode(WSRequestHandler* req) { * @category studio mode * @since 4.1.0 */ -std::string WSRequestHandler::HandleToggleStudioMode(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleToggleStudioMode(WSRequestHandler* req) { bool previewProgramMode = obs_frontend_preview_program_mode_active(); obs_frontend_set_preview_program_mode(!previewProgramMode); return req->SendOKResponse(); diff --git a/src/WSRequestHandler_Transitions.cpp b/src/WSRequestHandler_Transitions.cpp index e3717e2a..41b0f81a 100644 --- a/src/WSRequestHandler_Transitions.cpp +++ b/src/WSRequestHandler_Transitions.cpp @@ -15,7 +15,7 @@ * @category transitions * @since 4.1.0 */ -std::string WSRequestHandler::HandleGetTransitionList(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleGetTransitionList(WSRequestHandler* req) { OBSSourceAutoRelease currentTransition = obs_frontend_get_current_transition(); obs_frontend_source_list transitionList = {}; obs_frontend_get_transitions(&transitionList); @@ -49,7 +49,7 @@ std::string WSRequestHandler::HandleGetTransitionList(WSRequestHandler* req) { * @category transitions * @since 0.3 */ -std::string WSRequestHandler::HandleGetCurrentTransition(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleGetCurrentTransition(WSRequestHandler* req) { OBSSourceAutoRelease currentTransition = obs_frontend_get_current_transition(); OBSDataAutoRelease response = obs_data_create(); @@ -72,7 +72,7 @@ std::string WSRequestHandler::HandleGetCurrentTransition(WSRequestHandler* req) * @category transitions * @since 0.3 */ -std::string WSRequestHandler::HandleSetCurrentTransition(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleSetCurrentTransition(WSRequestHandler* req) { if (!req->hasField("transition-name")) { return req->SendErrorResponse("missing request parameters"); } @@ -96,7 +96,7 @@ std::string WSRequestHandler::HandleSetCurrentTransition(WSRequestHandler* req) * @category transitions * @since 4.0.0 */ -std::string WSRequestHandler::HandleSetTransitionDuration(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleSetTransitionDuration(WSRequestHandler* req) { if (!req->hasField("duration")) { return req->SendErrorResponse("missing request parameters"); } @@ -116,7 +116,7 @@ std::string WSRequestHandler::HandleSetTransitionDuration(WSRequestHandler* req) * @category transitions * @since 4.1.0 */ -std::string WSRequestHandler::HandleGetTransitionDuration(WSRequestHandler* req) { +HandlerResponse WSRequestHandler::HandleGetTransitionDuration(WSRequestHandler* req) { OBSDataAutoRelease response = obs_data_create(); obs_data_set_int(response, "transition-duration", Utils::GetTransitionDuration()); return req->SendOKResponse(response); diff --git a/src/WSServer.cpp b/src/WSServer.cpp index b3dc834e..64c67348 100644 --- a/src/WSServer.cpp +++ b/src/WSServer.cpp @@ -139,7 +139,13 @@ void WSServer::onMessage(connection_hdl hdl, server::message_ptr message) locker.unlock(); WSRequestHandler handler(connProperties); - std::string response = handler.processIncomingMessage(payload); + OBSDataAutoRelease responseData = handler.processIncomingMessage(payload); + + std::string response = obs_data_get_json(responseData); + + if (Config::Current()->DebugEnabled) { + blog(LOG_DEBUG, "Response << '%s'", response.c_str()); + } _server.send(hdl, response, websocketpp::frame::opcode::text);