mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
requests(pause recording): runtime feature detection
This commit is contained in:
@ -1,6 +1,28 @@
|
|||||||
|
#include "WSRequestHandler.h"
|
||||||
|
|
||||||
|
#include <util/platform.h>
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
#include "WSRequestHandler.h"
|
typedef void(*pauseRecordingFunction)(bool);
|
||||||
|
typedef bool(*recordingPausedFunction)();
|
||||||
|
|
||||||
|
HandlerResponse ifCanPause(WSRequestHandler* req, std::function<HandlerResponse(recordingPausedFunction, pauseRecordingFunction)> callback)
|
||||||
|
{
|
||||||
|
void* frontendApi = os_dlopen("obs-frontend-api");
|
||||||
|
|
||||||
|
bool (*recordingPaused)() = (bool(*)())os_dlsym(frontendApi, "obs_frontend_recording_paused");
|
||||||
|
void (*pauseRecording)(bool) = (void(*)(bool))os_dlsym(frontendApi, "obs_frontend_recording_pause");
|
||||||
|
|
||||||
|
if (!recordingPaused || !pauseRecording) {
|
||||||
|
return req->SendErrorResponse("recording pause not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!obs_frontend_recording_active()) {
|
||||||
|
return req->SendErrorResponse("recording is not active");
|
||||||
|
}
|
||||||
|
|
||||||
|
return callback(recordingPaused, pauseRecording);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle recording on or off.
|
* Toggle recording on or off.
|
||||||
@ -65,22 +87,14 @@ HandlerResponse WSRequestHandler::HandleStartRecording(WSRequestHandler* req) {
|
|||||||
* @since 4.7.0
|
* @since 4.7.0
|
||||||
*/
|
*/
|
||||||
HandlerResponse WSRequestHandler::HandlePauseRecording(WSRequestHandler* req) {
|
HandlerResponse WSRequestHandler::HandlePauseRecording(WSRequestHandler* req) {
|
||||||
// TODO runtime check
|
return ifCanPause(req, [req](recordingPausedFunction recordingPaused, pauseRecordingFunction pauseRecording) {
|
||||||
#if LIBOBS_API_VER < MAKE_SEMANTIC_VERSION(23, 2, 2)
|
if (recordingPaused()) {
|
||||||
return req->SendErrorResponse("recording pause not supported");
|
|
||||||
#else
|
|
||||||
if (!obs_frontend_recording_active()) {
|
|
||||||
return req->SendErrorResponse("recording is not active");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obs_frontend_recording_paused()) {
|
|
||||||
return req->SendErrorResponse("recording already paused");
|
return req->SendErrorResponse("recording already paused");
|
||||||
}
|
}
|
||||||
|
|
||||||
obs_frontend_recording_pause(true);
|
pauseRecording(true);
|
||||||
|
|
||||||
return req->SendOKResponse();
|
return req->SendOKResponse();
|
||||||
#endif
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,22 +107,14 @@ HandlerResponse WSRequestHandler::HandlePauseRecording(WSRequestHandler* req) {
|
|||||||
* @since 4.7.0
|
* @since 4.7.0
|
||||||
*/
|
*/
|
||||||
HandlerResponse WSRequestHandler::HandleResumeRecording(WSRequestHandler* req) {
|
HandlerResponse WSRequestHandler::HandleResumeRecording(WSRequestHandler* req) {
|
||||||
// TODO runtime check
|
return ifCanPause(req, [req](recordingPausedFunction recordingPaused, pauseRecordingFunction pauseRecording) {
|
||||||
#if LIBOBS_API_VER < MAKE_SEMANTIC_VERSION(23, 2, 2)
|
if (!recordingPaused()) {
|
||||||
return req->SendErrorResponse("recording resume not supported");
|
|
||||||
#else
|
|
||||||
if (!obs_frontend_recording_active()) {
|
|
||||||
return req->SendErrorResponse("recording is not active");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!obs_frontend_recording_paused()) {
|
|
||||||
return req->SendErrorResponse("recording is not paused");
|
return req->SendErrorResponse("recording is not paused");
|
||||||
}
|
}
|
||||||
|
|
||||||
obs_frontend_recording_pause(false);
|
pauseRecording(false);
|
||||||
|
|
||||||
return req->SendOKResponse();
|
return req->SendOKResponse();
|
||||||
#endif
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user