mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-14 13:18:36 -05:00
Add support for sending generic OBS websocket messages
This should allow to send OBS websocket vendor requests to other plugins which offer an API via this method (e.g. vertical OBS)
This commit is contained in:
@@ -131,6 +131,7 @@ Connection *GetConnectionByName(const QString &name)
|
||||
{
|
||||
return GetConnectionByName(name.toStdString());
|
||||
}
|
||||
|
||||
Connection *GetConnectionByName(const std::string &name)
|
||||
{
|
||||
for (auto &con : switcher->connections) {
|
||||
|
||||
@@ -40,6 +40,7 @@ public:
|
||||
void Save(obs_data_t *obj) const;
|
||||
std::string GetName() { return _name; }
|
||||
std::vector<std::string> &Events() { return _client.Events(); }
|
||||
bool IsUsingOBSProtocol() { return _useOBSWSProtocol; }
|
||||
|
||||
private:
|
||||
void UseOBSWebsocketProtocol(bool);
|
||||
|
||||
@@ -75,8 +75,7 @@ extern "C" void RegisterWebsocketVendor()
|
||||
}
|
||||
}
|
||||
|
||||
WSConnection::WSConnection(bool useOBSProtocol)
|
||||
: QObject(nullptr), _useOBSProtocol(useOBSProtocol)
|
||||
WSConnection::WSConnection(bool useOBSProtocol) : QObject(nullptr)
|
||||
{
|
||||
_client.get_alog().clear_channels(
|
||||
websocketpp::log::alevel::frame_header |
|
||||
@@ -179,14 +178,13 @@ void WSConnection::Disconnect()
|
||||
_status = Status::DISCONNECTED;
|
||||
}
|
||||
|
||||
static std::string constructVendorRequestMessage(const std::string &message,
|
||||
const std::string &uri)
|
||||
std::string ConstructVendorRequestMessage(const std::string &message)
|
||||
{
|
||||
auto request = obs_data_create();
|
||||
obs_data_set_int(request, "op", 6);
|
||||
auto *data = obs_data_create();
|
||||
obs_data_set_string(data, "requestType", "CallVendorRequest");
|
||||
obs_data_set_string(data, "requestId", (message + " - " + uri).c_str());
|
||||
obs_data_set_string(data, "requestId", message.c_str());
|
||||
|
||||
auto vendorData = obs_data_create();
|
||||
obs_data_set_string(vendorData, "vendorName", VendorName);
|
||||
@@ -211,11 +209,7 @@ static std::string constructVendorRequestMessage(const std::string &message,
|
||||
|
||||
void WSConnection::SendRequest(const std::string &msg)
|
||||
{
|
||||
if (_useOBSProtocol) {
|
||||
Send(constructVendorRequestMessage(msg, _uri));
|
||||
} else {
|
||||
Send(msg);
|
||||
}
|
||||
Send(msg);
|
||||
}
|
||||
|
||||
WSConnection::Status WSConnection::GetStatus() const
|
||||
@@ -225,7 +219,6 @@ WSConnection::Status WSConnection::GetStatus() const
|
||||
|
||||
void WSConnection::UseOBSWebsocketProtocol(bool useOBSProtocol)
|
||||
{
|
||||
_useOBSProtocol = useOBSProtocol;
|
||||
_client.set_open_handler(bind(useOBSProtocol
|
||||
? &WSConnection::OnOBSOpen
|
||||
: &WSConnection::OnGenericOpen,
|
||||
|
||||
@@ -30,6 +30,7 @@ constexpr char VendorEvent[] = "AdvancedSceneSwitcherEvent";
|
||||
|
||||
void ClearWebsocketMessages();
|
||||
void SendWebsocketEvent(const std::string &);
|
||||
std::string ConstructVendorRequestMessage(const std::string &message);
|
||||
|
||||
class WSConnection : public QObject {
|
||||
public:
|
||||
@@ -79,7 +80,6 @@ private:
|
||||
std::atomic_bool _disconnect{false};
|
||||
|
||||
std::vector<std::string> _messages;
|
||||
bool _useOBSProtocol = true;
|
||||
};
|
||||
|
||||
} // namespace advss
|
||||
|
||||
Reference in New Issue
Block a user