mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
Merge pull request #354 from julijane/4.x-current
Make it possible to broadcast messages (data) to other websocket clients
This commit is contained in:
commit
add307577d
@ -1505,6 +1505,25 @@ void WSEvents::OnStudioModeSwitched(bool checked) {
|
||||
broadcastUpdate("StudioModeSwitched", data);
|
||||
}
|
||||
|
||||
/**
|
||||
* A custom broadcast message was received
|
||||
*
|
||||
* @param {String} `realm` Identifier provided by the sender
|
||||
* @param {Object} `data` User-defined data
|
||||
*
|
||||
* @api events
|
||||
* @name BroadcastCustomMessage
|
||||
* @category general
|
||||
* @since 4.7.0
|
||||
*/
|
||||
void WSEvents::OnBroadcastCustomMessage(QString realm, obs_data_t* data) {
|
||||
OBSDataAutoRelease broadcastData = obs_data_create();
|
||||
obs_data_set_string(broadcastData, "realm", realm.toUtf8().constData());
|
||||
obs_data_set_obj(broadcastData, "data", data);
|
||||
|
||||
broadcastUpdate("BroadcastCustomMessage", broadcastData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} `OBSStats`
|
||||
* @property {double} `fps` Current framerate.
|
||||
|
@ -49,6 +49,8 @@ public:
|
||||
const char* GetRecordingTimecode();
|
||||
obs_data_t* GetStats();
|
||||
|
||||
void OnBroadcastCustomMessage(QString realm, obs_data_t* data);
|
||||
|
||||
bool HeartbeatIsActive;
|
||||
|
||||
private slots:
|
||||
|
@ -36,6 +36,8 @@ QHash<QString, HandlerResponse(*)(WSRequestHandler*)> WSRequestHandler::messageM
|
||||
{ "SetFilenameFormatting", WSRequestHandler::HandleSetFilenameFormatting },
|
||||
{ "GetFilenameFormatting", WSRequestHandler::HandleGetFilenameFormatting },
|
||||
|
||||
{ "BroadcastCustomMessage", WSRequestHandler::HandleBroadcastCustomMessage },
|
||||
|
||||
{ "SetCurrentScene", WSRequestHandler::HandleSetCurrentScene },
|
||||
{ "GetCurrentScene", WSRequestHandler::HandleGetCurrentScene },
|
||||
{ "GetSceneList", WSRequestHandler::HandleGetSceneList },
|
||||
|
@ -74,6 +74,8 @@ class WSRequestHandler : public QObject {
|
||||
static HandlerResponse HandleSetFilenameFormatting(WSRequestHandler* req);
|
||||
static HandlerResponse HandleGetFilenameFormatting(WSRequestHandler* req);
|
||||
|
||||
static HandlerResponse HandleBroadcastCustomMessage(WSRequestHandler* req);
|
||||
|
||||
static HandlerResponse HandleSetCurrentScene(WSRequestHandler* req);
|
||||
static HandlerResponse HandleGetCurrentScene(WSRequestHandler* req);
|
||||
static HandlerResponse HandleGetSceneList(WSRequestHandler* req);
|
||||
|
@ -231,6 +231,40 @@ HandlerResponse WSRequestHandler::HandleGetStats(WSRequestHandler* req) {
|
||||
return req->SendOKResponse(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast custom message to all connected WebSocket clients
|
||||
*
|
||||
* @param {String} `realm` Identifier to be choosen by the client
|
||||
* @param {Object} `data` User-defined data
|
||||
*
|
||||
* @api general
|
||||
* @name BroadcastCustomMessage
|
||||
* @category general
|
||||
* @since 4.7.0
|
||||
*/
|
||||
HandlerResponse WSRequestHandler::HandleBroadcastCustomMessage(WSRequestHandler* req) {
|
||||
if (!req->hasField("realm") || !req->hasField("data")) {
|
||||
return req->SendErrorResponse("missing request parameters");
|
||||
}
|
||||
|
||||
QString realm = obs_data_get_string(req->data, "realm");
|
||||
OBSDataAutoRelease data = obs_data_get_obj(req->data, "data");
|
||||
|
||||
if (realm.isEmpty()) {
|
||||
return req->SendErrorResponse("realm not specified!");
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return req->SendErrorResponse("data not specified!");
|
||||
}
|
||||
|
||||
auto events = GetEventsSystem();
|
||||
events->OnBroadcastCustomMessage(realm, data);
|
||||
|
||||
return req->SendOKResponse();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get basic OBS video information
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user