mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
Base: Code cleanup and add some requests
This commit is contained in:
parent
0a02015f7d
commit
4d271da541
@ -1,16 +1,14 @@
|
||||
#include <obs-frontend-api.h>
|
||||
|
||||
#include "Config.h"
|
||||
#include "utils/Utils.h"
|
||||
|
||||
#include "plugin-macros.generated.h"
|
||||
#include "utils/Utils.h"
|
||||
|
||||
#define CONFIG_SECTION_NAME "OBSWebSocket"
|
||||
|
||||
#define PARAM_FIRSTLOAD "FirstLoad"
|
||||
#define PARAM_ENABLED "ServerEnabled"
|
||||
#define PARAM_PORT "ServerPort"
|
||||
#define PARAM_DEBUG "DebugEnabled"
|
||||
#define PARAM_ALERTS "AlertsEnabled"
|
||||
#define PARAM_AUTHREQUIRED "AuthRequred"
|
||||
#define PARAM_PASSWORD "ServerPassword"
|
||||
|
@ -1,13 +1,13 @@
|
||||
#include <obs-module.h>
|
||||
|
||||
#include "WebSocketProtocol.h"
|
||||
#include "WebSocketSession.h"
|
||||
#include "requesthandler/RequestHandler.h"
|
||||
#include "requesthandler/rpc/RequestStatus.h"
|
||||
|
||||
#include "obs-websocket.h"
|
||||
#include "Config.h"
|
||||
#include "utils/Utils.h"
|
||||
#include "plugin-macros.generated.h"
|
||||
#include "utils/Utils.h"
|
||||
|
||||
bool IsSupportedRpcVersion(uint8_t requestedVersion)
|
||||
{
|
||||
@ -66,7 +66,7 @@ WebSocketProtocol::ProcessResult WebSocketProtocol::ProcessMessage(SessionPtr se
|
||||
|
||||
if (!incomingMessage.contains("messageType")) {
|
||||
if (incomingMessage.contains("request-type")) {
|
||||
blog(LOG_WARNING, "Client %s appears to be running a pre-5.0.0 protocol.", session->RemoteAddress().c_str())
|
||||
blog(LOG_WARNING, "Client %s appears to be running a pre-5.0.0 protocol.", session->RemoteAddress().c_str());
|
||||
ret.closeCode = WebSocketServer::WebSocketCloseCode::UnsupportedProtocolVersion;
|
||||
ret.closeReason = "You appear to be attempting to connect with the pre-5.0.0 plugin protocol. Check to make sure your client is updated.";
|
||||
return ret;
|
||||
|
@ -2,10 +2,11 @@
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "WebSocketServer.h"
|
||||
#include "WebSocketSession.h"
|
||||
|
||||
class WebSocketSession;
|
||||
typedef std::shared_ptr<WebSocketSession> SessionPtr;
|
||||
|
||||
namespace WebSocketProtocol {
|
||||
const std::vector<uint8_t> SupportedRpcVersions{
|
||||
|
@ -5,13 +5,11 @@
|
||||
#include <obs-module.h>
|
||||
#include <obs-frontend-api.h>
|
||||
|
||||
#include "obs-websocket.h"
|
||||
|
||||
#include "WebSocketServer.h"
|
||||
#include "WebSocketProtocol.h"
|
||||
#include "Config.h"
|
||||
#include "eventhandler/types/EventSubscription.h"
|
||||
|
||||
#include "obs-websocket.h"
|
||||
#include "Config.h"
|
||||
#include "plugin-macros.generated.h"
|
||||
|
||||
WebSocketServer::WebSocketServer() :
|
||||
|
@ -1,14 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <QObject>
|
||||
#include <QThreadPool>
|
||||
#include <QString>
|
||||
#include <mutex>
|
||||
|
||||
#include "utils/Utils.h"
|
||||
#include <websocketpp/config/asio_no_tls.hpp>
|
||||
#include <websocketpp/server.hpp>
|
||||
|
||||
#include "utils/Utils.h"
|
||||
#include "WebSocketSession.h"
|
||||
|
||||
class WebSocketServer : QObject
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "WebSocketSession.h"
|
||||
#include "eventhandler/types/EventSubscription.h"
|
||||
|
||||
#include "plugin-macros.generated.h"
|
||||
|
||||
WebSocketSession::WebSocketSession() :
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "EventHandler.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
EventHandler::EventHandler(WebSocketServerPtr webSocketServer) :
|
||||
|
@ -4,9 +4,9 @@
|
||||
#include <obs-frontend-api.h>
|
||||
#include <util/platform.h>
|
||||
|
||||
#include "types/EventSubscription.h"
|
||||
#include "../obs-websocket.h"
|
||||
#include "../WebSocketServer.h"
|
||||
#include "types/EventSubscription.h"
|
||||
|
||||
enum ObsOutputState {
|
||||
OBS_WEBSOCKET_OUTPUT_STARTING,
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "EventHandler.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
void EventHandler::HandleCurrentSceneCollectionChanged()
|
||||
|
@ -1,3 +1,2 @@
|
||||
#include "EventHandler.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "EventHandler.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
void EventHandler::HandleExitStarted()
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "EventHandler.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
void EventHandler::HandleInputCreated(obs_source_t *source)
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "EventHandler.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
#define CASE(x) case x: return #x;
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "EventHandler.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
#define CASE(x) case x: return #x;
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "EventHandler.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
void EventHandler::HandleSceneItemCreated(void *param, calldata_t *data)
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "EventHandler.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
void EventHandler::HandleSceneCreated(obs_source_t *source)
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "EventHandler.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
void EventHandler::HandleTransitionCreated(obs_source_t *source)
|
||||
|
@ -1,13 +1,12 @@
|
||||
#include <QClipboard>
|
||||
#include <QPainter>
|
||||
#include <obs-module.h>
|
||||
#include "../../deps/qr/cpp/QrCode.hpp"
|
||||
|
||||
#include "ConnectInfo.h"
|
||||
#include "../../deps/qr/cpp/QrCode.hpp"
|
||||
#include "../obs-websocket.h"
|
||||
#include "../Config.h"
|
||||
#include "../utils/Utils.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
ConnectInfo::ConnectInfo(QWidget* parent) :
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include "../obs-websocket.h"
|
||||
#include "../Config.h"
|
||||
#include "../WebSocketServer.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
QString GetToolTipIconHtml()
|
||||
|
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <QtWidgets/QDialog>
|
||||
#include <QDialog>
|
||||
#include <QTimer>
|
||||
|
||||
#include "ConnectInfo.h"
|
||||
#include "ui_SettingsDialog.h"
|
||||
#include "ConnectInfo.h"
|
||||
|
||||
class SettingsDialog : public QDialog
|
||||
{
|
||||
|
@ -6,27 +6,13 @@
|
||||
#include <obs-data.h>
|
||||
#include <obs-frontend-api.h>
|
||||
|
||||
#include "plugin-macros.generated.h"
|
||||
#include "obs-websocket.h"
|
||||
#include "Config.h"
|
||||
#include "WebSocketServer.h"
|
||||
#include "eventhandler/EventHandler.h"
|
||||
#include "forms/SettingsDialog.h"
|
||||
|
||||
#include "plugin-macros.generated.h"
|
||||
|
||||
// Auto release definitions
|
||||
void ___source_dummy_addref(obs_source_t*) {}
|
||||
void ___sceneitem_dummy_addref(obs_sceneitem_t*) {}
|
||||
void ___data_dummy_addref(obs_data_t*) {}
|
||||
void ___data_array_dummy_addref(obs_data_array_t*) {}
|
||||
void ___output_dummy_addref(obs_output_t*) {}
|
||||
void ___data_item_dummy_addref(obs_data_item_t*) {}
|
||||
void ___data_item_release(obs_data_item_t* dataItem)
|
||||
{
|
||||
obs_data_item_release(&dataItem);
|
||||
}
|
||||
|
||||
|
||||
OBS_DECLARE_MODULE()
|
||||
OBS_MODULE_USE_DEFAULT_LOCALE("obs-websocket", "en-US")
|
||||
|
||||
@ -35,6 +21,14 @@ WebSocketServerPtr _webSocketServer;
|
||||
EventHandlerPtr _eventHandler;
|
||||
SettingsDialog *_settingsDialog = nullptr;
|
||||
|
||||
void ___source_dummy_addref(obs_source_t*) {}
|
||||
void ___sceneitem_dummy_addref(obs_sceneitem_t*) {};
|
||||
void ___data_dummy_addref(obs_data_t*) {};
|
||||
void ___data_array_dummy_addref(obs_data_array_t*) {};
|
||||
void ___output_dummy_addref(obs_output_t*) {};
|
||||
void ___data_item_dummy_addref(obs_data_item_t*) {};
|
||||
void ___data_item_release(obs_data_item_t* dataItem){ obs_data_item_release(&dataItem); };
|
||||
|
||||
bool obs_module_load(void)
|
||||
{
|
||||
blog(LOG_INFO, "[obs_module_load] you can haz websockets (Version: %s | RPC Version: %d)", OBS_WEBSOCKET_VERSION, OBS_WEBSOCKET_RPC_VERSION);
|
||||
|
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <obs.hpp>
|
||||
#include <memory>
|
||||
#include <obs.hpp>
|
||||
|
||||
// Autorelease object declarations
|
||||
// Autorelease object definitions
|
||||
void ___source_dummy_addref(obs_source_t*);
|
||||
void ___sceneitem_dummy_addref(obs_sceneitem_t*);
|
||||
void ___data_dummy_addref(obs_data_t*);
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "RequestHandler.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
const std::map<std::string, RequestMethodHandler> RequestHandler::_handlerMap
|
||||
@ -21,6 +20,8 @@ const std::map<std::string, RequestMethodHandler> RequestHandler::_handlerMap
|
||||
{"SetCurrentProfile", &RequestHandler::SetCurrentProfile},
|
||||
{"GetProfileParameter", &RequestHandler::GetProfileParameter},
|
||||
{"SetProfileParameter", &RequestHandler::SetProfileParameter},
|
||||
{"GetVideoSettings", &RequestHandler::GetVideoSettings},
|
||||
{"SetVideoSettings", &RequestHandler::SetVideoSettings},
|
||||
|
||||
// Sources
|
||||
{"GetSourceActive", &RequestHandler::GetSourceActive},
|
||||
|
@ -4,9 +4,9 @@
|
||||
#include <obs.hpp>
|
||||
#include <obs-frontend-api.h>
|
||||
|
||||
#include "../obs-websocket.h"
|
||||
#include "rpc/Request.h"
|
||||
#include "rpc/RequestResult.h"
|
||||
#include "../obs-websocket.h"
|
||||
#include "../utils/Utils.h"
|
||||
|
||||
class RequestHandler;
|
||||
@ -35,6 +35,8 @@ class RequestHandler {
|
||||
RequestResult SetCurrentProfile(const Request&);
|
||||
RequestResult GetProfileParameter(const Request&);
|
||||
RequestResult SetProfileParameter(const Request&);
|
||||
RequestResult GetVideoSettings(const Request&);
|
||||
RequestResult SetVideoSettings(const Request&);
|
||||
|
||||
// Sources
|
||||
RequestResult GetSourceActive(const Request&);
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include <util/config-file.h>
|
||||
|
||||
#include "RequestHandler.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
RequestResult RequestHandler::GetSceneCollectionList(const Request& request)
|
||||
@ -113,3 +112,66 @@ RequestResult RequestHandler::SetProfileParameter(const Request& request)
|
||||
|
||||
return RequestResult::Success();
|
||||
}
|
||||
|
||||
RequestResult RequestHandler::GetVideoSettings(const Request& request)
|
||||
{
|
||||
struct obs_video_info ovi;
|
||||
if (!obs_get_video_info(&ovi))
|
||||
return RequestResult::Error(RequestStatus::RequestProcessingFailed, "Unable to get internal OBS video info.");
|
||||
|
||||
json responseData;
|
||||
responseData["fpsNumerator"] = ovi.fps_num;
|
||||
responseData["fpsDenominator"] = ovi.fps_den;
|
||||
responseData["baseWidth"] = ovi.base_width;
|
||||
responseData["baseHeight"] = ovi.base_height;
|
||||
responseData["outputWidth"] = ovi.output_width;
|
||||
responseData["outputHeight"] = ovi.output_height;
|
||||
|
||||
return RequestResult::Success(responseData);
|
||||
}
|
||||
|
||||
RequestResult RequestHandler::SetVideoSettings(const Request& request)
|
||||
{
|
||||
if (obs_video_active())
|
||||
return RequestResult::Error(RequestStatus::OutputRunning, "Video settings cannot be changed while an output is active.");
|
||||
|
||||
RequestStatus::RequestStatus statusCode = RequestStatus::NoError;
|
||||
std::string comment;
|
||||
bool changeFps = (request.ValidateNumber("fpsNumerator", statusCode, comment, 1) && request.ValidateNumber("fpsDenominator", statusCode, comment, 1));
|
||||
if (!changeFps && statusCode != RequestStatus::MissingRequestParameter)
|
||||
return RequestResult::Error(statusCode, comment);
|
||||
|
||||
bool changeBaseRes = (request.ValidateNumber("baseWidth", statusCode, comment, 8, 4096) && request.ValidateNumber("baseHeight", statusCode, comment, 8, 4096));
|
||||
if (!changeBaseRes && statusCode != RequestStatus::MissingRequestParameter)
|
||||
return RequestResult::Error(statusCode, comment);
|
||||
|
||||
bool changeOutputRes = (request.ValidateNumber("outputWidth", statusCode, comment, 8, 4096) && request.ValidateNumber("outputHeight", statusCode, comment, 8, 4096));
|
||||
if (!changeOutputRes && statusCode != RequestStatus::MissingRequestParameter)
|
||||
return RequestResult::Error(statusCode, comment);
|
||||
|
||||
config_t *config = obs_frontend_get_profile_config();
|
||||
|
||||
if (changeFps) {
|
||||
config_set_uint(config, "Video", "FPSType", 2);
|
||||
config_set_uint(config, "Video", "FPSNum", request.RequestData["fpsNumerator"]);
|
||||
config_set_uint(config, "Video", "FPSDen", request.RequestData["fpsDenominator"]);
|
||||
}
|
||||
|
||||
if (changeBaseRes) {
|
||||
config_set_uint(config, "Video", "BaseCX", request.RequestData["baseWidth"]);
|
||||
config_set_uint(config, "Video", "BaseCY", request.RequestData["baseHeight"]);
|
||||
}
|
||||
|
||||
if (changeOutputRes) {
|
||||
config_set_uint(config, "Video", "OutputCX", request.RequestData["outputWidth"]);
|
||||
config_set_uint(config, "Video", "OutputCY", request.RequestData["outputHeight"]);
|
||||
}
|
||||
|
||||
if (changeFps || changeBaseRes || changeOutputRes) {
|
||||
config_save_safe(config, "tmp", nullptr);
|
||||
obs_frontend_reset_video();
|
||||
return RequestResult::Success();
|
||||
}
|
||||
|
||||
return RequestResult::Error(RequestStatus::MissingRequestParameter, "You must specify at least one video-changing pair.");
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
#include <QImageWriter>
|
||||
|
||||
#include "RequestHandler.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
#include "../eventhandler/types/EventSubscription.h"
|
||||
#include "../obs-websocket.h"
|
||||
#include "../WebSocketServer.h"
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
RequestResult RequestHandler::GetVersion(const Request& request)
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "RequestHandler.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
RequestResult RequestHandler::GetInputList(const Request& request)
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "RequestHandler.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
RequestResult RequestHandler::GetSceneList(const Request& request)
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include <QDir>
|
||||
|
||||
#include "RequestHandler.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
QImage TakeSourceScreenshot(obs_source_t *source, bool &success, uint32_t requestedWidth = 0, uint32_t requestedHeight = 0)
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "Request.h"
|
||||
|
||||
#include "../../plugin-macros.generated.h"
|
||||
|
||||
json GetDefaultJsonObject(json requestData)
|
||||
|
@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "RequestStatus.h"
|
||||
#include "../../utils/Utils.h"
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include <QCryptographicHash>
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
std::string Utils::Crypto::GenerateSalt()
|
||||
|
@ -1,7 +1,4 @@
|
||||
#include "Utils.h"
|
||||
// For AutoRelease types
|
||||
#include "../obs-websocket.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
bool Utils::Json::JsonArrayIsValidObsArray(json j)
|
||||
@ -18,25 +15,28 @@ void obs_data_set_json_object_item(obs_data_t *d, json j);
|
||||
|
||||
void obs_data_set_json_object(obs_data_t *d, const char *key, json j)
|
||||
{
|
||||
OBSDataAutoRelease subObj = obs_data_create();
|
||||
obs_data_t *subObj = obs_data_create();
|
||||
obs_data_set_json_object_item(subObj, j);
|
||||
obs_data_set_obj(d, key, subObj);
|
||||
obs_data_release(subObj);
|
||||
}
|
||||
|
||||
void obs_data_set_json_array(obs_data_t *d, const char *key, json j)
|
||||
{
|
||||
OBSDataArrayAutoRelease array = obs_data_array_create();
|
||||
obs_data_array_t *array = obs_data_array_create();
|
||||
|
||||
for (auto& [key, value] : j.items()) {
|
||||
if (!value.is_object())
|
||||
continue;
|
||||
|
||||
OBSDataAutoRelease item = obs_data_create();
|
||||
obs_data_t *item = obs_data_create();
|
||||
obs_data_set_json_object_item(item, value);
|
||||
obs_data_array_push_back(array, item);
|
||||
obs_data_release(item);
|
||||
}
|
||||
|
||||
obs_data_set_array(d, key, array);
|
||||
obs_data_array_release(array);
|
||||
}
|
||||
|
||||
void obs_data_set_json_object_item(obs_data_t *d, json j)
|
||||
@ -103,15 +103,17 @@ void set_json_object(json *j, const char *name, obs_data_item_t *item, bool incl
|
||||
void set_json_array(json *j, const char *name, obs_data_item_t *item, bool includeDefault)
|
||||
{
|
||||
json jArray = json::array();
|
||||
OBSDataArrayAutoRelease array = obs_data_item_get_array(item);
|
||||
obs_data_array_t *array = obs_data_item_get_array(item);
|
||||
size_t count = obs_data_array_count(array);
|
||||
|
||||
for (size_t idx = 0; idx < count; idx++) {
|
||||
OBSDataAutoRelease subItem = obs_data_array_item(array, idx);
|
||||
obs_data_t *subItem = obs_data_array_item(array, idx);
|
||||
json jItem = Utils::Json::ObsDataToJson(subItem, includeDefault);
|
||||
obs_data_release(subItem);
|
||||
jArray.push_back(jItem);
|
||||
}
|
||||
|
||||
obs_data_array_release(array);
|
||||
j->emplace(name, jArray);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
#include <obs.hpp>
|
||||
#include <obs-frontend-api.h>
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
#include "../obs-websocket.h"
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
|
@ -2,11 +2,9 @@
|
||||
#include <QCommandLineParser>
|
||||
#include <QNetworkInterface>
|
||||
#include <QHostAddress>
|
||||
|
||||
#include <obs-frontend-api.h>
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
std::string Utils::Platform::GetLocalAddress()
|
||||
|
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <obs.hpp>
|
||||
#include <string>
|
||||
#include <QString>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <obs.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
Loading…
Reference in New Issue
Block a user