mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
Merge pull request #638 from Palakis/feature/getsourcedefaultsettings
Requests: Add GetSourceDefaultSettings
This commit is contained in:
commit
83e23c9c41
@ -24,6 +24,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
|||||||
#include <obs-frontend-api.h>
|
#include <obs-frontend-api.h>
|
||||||
#include <obs.hpp>
|
#include <obs.hpp>
|
||||||
#include <util/platform.h>
|
#include <util/platform.h>
|
||||||
|
#include <obs-data.h>
|
||||||
|
|
||||||
#include "obs-websocket.h"
|
#include "obs-websocket.h"
|
||||||
|
|
||||||
@ -905,3 +906,38 @@ void Utils::AddSourceHelper(void *_data, obs_scene_t *scene)
|
|||||||
data->sceneItem = obs_scene_add(scene, data->source);
|
data->sceneItem = obs_scene_add(scene, data->source);
|
||||||
obs_sceneitem_set_visible(data->sceneItem, data->setVisible);
|
obs_sceneitem_set_visible(data->sceneItem, data->setVisible);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
obs_data_t *Utils::OBSDataGetDefaults(obs_data_t *data)
|
||||||
|
{
|
||||||
|
obs_data_t *returnData = obs_data_create();
|
||||||
|
obs_data_item_t *item = NULL;
|
||||||
|
|
||||||
|
for (item = obs_data_first(data); item; obs_data_item_next(&item)) {
|
||||||
|
enum obs_data_type type = obs_data_item_gettype(item);
|
||||||
|
const char *name = obs_data_item_get_name(item);
|
||||||
|
|
||||||
|
if (type == OBS_DATA_STRING) {
|
||||||
|
const char *val = obs_data_item_get_string(item);
|
||||||
|
obs_data_set_string(returnData, name, val);
|
||||||
|
} else if (type == OBS_DATA_NUMBER) {
|
||||||
|
enum obs_data_number_type type = obs_data_item_numtype(item);
|
||||||
|
if (type == OBS_DATA_NUM_INT) {
|
||||||
|
long long val = obs_data_item_get_int(item);
|
||||||
|
obs_data_set_int(returnData, name, val);
|
||||||
|
} else {
|
||||||
|
double val = obs_data_item_get_double(item);
|
||||||
|
obs_data_set_double(returnData, name, val);
|
||||||
|
}
|
||||||
|
} else if (type == OBS_DATA_BOOLEAN) {
|
||||||
|
bool val = obs_data_item_get_bool(item);
|
||||||
|
obs_data_set_bool(returnData, name, val);
|
||||||
|
} else if (type == OBS_DATA_OBJECT) {
|
||||||
|
OBSDataAutoRelease obj = obs_data_item_get_obj(item);
|
||||||
|
obs_data_set_obj(returnData, name, obj);
|
||||||
|
} else if (type == OBS_DATA_ARRAY) {
|
||||||
|
OBSDataArrayAutoRelease array = obs_data_item_get_array(item);
|
||||||
|
obs_data_set_array(returnData, name, array);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return returnData;
|
||||||
|
}
|
||||||
|
@ -94,4 +94,6 @@ namespace Utils {
|
|||||||
bool setVisible;
|
bool setVisible;
|
||||||
};
|
};
|
||||||
void AddSourceHelper(void *_data, obs_scene_t *scene);
|
void AddSourceHelper(void *_data, obs_scene_t *scene);
|
||||||
|
|
||||||
|
obs_data_t *OBSDataGetDefaults(obs_data_t *data);
|
||||||
};
|
};
|
||||||
|
@ -118,6 +118,7 @@ const QHash<QString, RpcMethodHandler> WSRequestHandler::messageMap{
|
|||||||
{ "SetSourceSettings", &WSRequestHandler::SetSourceSettings },
|
{ "SetSourceSettings", &WSRequestHandler::SetSourceSettings },
|
||||||
{ "GetAudioMonitorType", &WSRequestHandler::GetAudioMonitorType },
|
{ "GetAudioMonitorType", &WSRequestHandler::GetAudioMonitorType },
|
||||||
{ "SetAudioMonitorType", &WSRequestHandler::SetAudioMonitorType },
|
{ "SetAudioMonitorType", &WSRequestHandler::SetAudioMonitorType },
|
||||||
|
{ "GetSourceDefaultSettings", &WSRequestHandler::GetSourceDefaultSettings },
|
||||||
{ "TakeSourceScreenshot", &WSRequestHandler::TakeSourceScreenshot },
|
{ "TakeSourceScreenshot", &WSRequestHandler::TakeSourceScreenshot },
|
||||||
|
|
||||||
{ "GetSourceFilters", &WSRequestHandler::GetSourceFilters },
|
{ "GetSourceFilters", &WSRequestHandler::GetSourceFilters },
|
||||||
|
@ -135,6 +135,7 @@ class WSRequestHandler {
|
|||||||
RpcResponse SetSourceSettings(const RpcRequest&);
|
RpcResponse SetSourceSettings(const RpcRequest&);
|
||||||
RpcResponse GetAudioMonitorType(const RpcRequest&);
|
RpcResponse GetAudioMonitorType(const RpcRequest&);
|
||||||
RpcResponse SetAudioMonitorType(const RpcRequest&);
|
RpcResponse SetAudioMonitorType(const RpcRequest&);
|
||||||
|
RpcResponse GetSourceDefaultSettings(const RpcRequest&);
|
||||||
RpcResponse TakeSourceScreenshot(const RpcRequest&);
|
RpcResponse TakeSourceScreenshot(const RpcRequest&);
|
||||||
|
|
||||||
RpcResponse GetSourceFilters(const RpcRequest&);
|
RpcResponse GetSourceFilters(const RpcRequest&);
|
||||||
|
@ -1679,6 +1679,43 @@ RpcResponse WSRequestHandler::SetAudioMonitorType(const RpcRequest& request)
|
|||||||
return request.success();
|
return request.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the default settings for a given source type.
|
||||||
|
*
|
||||||
|
* @param {String} `sourceKind` Source kind. Also called "source id" in libobs terminology.
|
||||||
|
*
|
||||||
|
* @return {String} `sourceKind` Source kind. Same value as the `sourceKind` parameter.
|
||||||
|
* @return {Object} `defaultSettings` Settings object for source.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name GetSourceDefaultSettings
|
||||||
|
* @category sources
|
||||||
|
* @since 4.9.0
|
||||||
|
*/
|
||||||
|
RpcResponse WSRequestHandler::GetSourceDefaultSettings(const RpcRequest& request)
|
||||||
|
{
|
||||||
|
if (!request.hasField("sourceKind")) {
|
||||||
|
return request.failed("missing request parameters");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString sourceKind = obs_data_get_string(request.parameters(), "sourceKind");
|
||||||
|
if (sourceKind.isEmpty()) {
|
||||||
|
return request.failed("invalid request parameters");
|
||||||
|
}
|
||||||
|
|
||||||
|
OBSDataAutoRelease defaultData = obs_get_source_defaults(sourceKind.toUtf8());
|
||||||
|
if (!defaultData) {
|
||||||
|
return request.failed("invalid sourceKind");
|
||||||
|
}
|
||||||
|
|
||||||
|
OBSDataAutoRelease defaultSettings = Utils::OBSDataGetDefaults(defaultData);
|
||||||
|
|
||||||
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
|
obs_data_set_string(response, "sourceKind", sourceKind.toUtf8().constData());
|
||||||
|
obs_data_set_obj(response, "defaultSettings", defaultSettings);
|
||||||
|
return request.success(response);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes a picture snapshot of a source and then can either or both:
|
* Takes a picture snapshot of a source and then can either or both:
|
||||||
* - Send it over as a Data URI (base64-encoded data) in the response (by specifying `embedPictureFormat` in the request)
|
* - Send it over as a Data URI (base64-encoded data) in the response (by specifying `embedPictureFormat` in the request)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user