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:
Stéphane Lepin 2019-07-26 05:51:42 +02:00 committed by GitHub
commit add307577d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 0 deletions

View File

@ -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.

View File

@ -49,6 +49,8 @@ public:
const char* GetRecordingTimecode();
obs_data_t* GetStats();
void OnBroadcastCustomMessage(QString realm, obs_data_t* data);
bool HeartbeatIsActive;
private slots:

View File

@ -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 },

View File

@ -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);

View File

@ -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
*