From ed9f9a4a345a0e68787fc4811bc978b587ae480c Mon Sep 17 00:00:00 2001 From: phillypro Date: Wed, 20 Sep 2023 08:06:44 -0400 Subject: [PATCH] Added Ability for Websockets to update Stream Key (#9) added functionality to send stream key via websocket --- vertical-canvas.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++ vertical-canvas.hpp | 3 +++ 2 files changed, 50 insertions(+) diff --git a/vertical-canvas.cpp b/vertical-canvas.cpp index 89cdf45..cbfdd43 100644 --- a/vertical-canvas.cpp +++ b/vertical-canvas.cpp @@ -373,6 +373,7 @@ void vendor_request_invoke(obs_data_t *request_data, obs_data_t *response_data, obs_data_set_bool(response_data, "success", false); } + void vendor_request_save_replay(obs_data_t *request_data, obs_data_t *response_data, void *p) { @@ -393,6 +394,39 @@ void vendor_request_save_replay(obs_data_t *request_data, obs_data_set_bool(response_data, "success", false); } +void vendor_request_update_stream_key(obs_data_t *request_data, + obs_data_t *response_data, void *) +{ + // Parse request_data to get the new stream_key + const char *new_stream_key = obs_data_get_string(request_data, "stream_key"); + const auto width = obs_data_get_int(request_data, "width"); + const auto height = obs_data_get_int(request_data, "height"); + + if (!new_stream_key || !strlen(new_stream_key)) { + obs_data_set_string(response_data, "error", "'stream_key' not set"); + obs_data_set_bool(response_data, "success", false); + return; + } + + // Loop through each CanvasDock to find the right one + for (const auto &it : canvas_docks) { + if ((width && it->GetCanvasWidth() != width) || + (height && it->GetCanvasHeight() != height)) + continue; + + // Update stream_key using the UpdateStreamKey method of CanvasDock + QMetaObject::invokeMethod( + it, "UpdateStreamKey", + Q_ARG(QString, QString::fromUtf8(new_stream_key))); + + obs_data_set_bool(response_data, "success", true); + return; + } + + obs_data_set_bool(response_data, "success", false); +} + + update_info_t *verison_update_info = nullptr; bool version_info_downloaded(void *param, struct file_download_data *file) @@ -532,6 +566,11 @@ void obs_module_post_load(void) obs_websocket_vendor_register_request(vendor, "stop_virtual_camera", vendor_request_invoke, (void *)"StopVirtualCam"); + obs_websocket_vendor_register_request(vendor, "update_stream_key", + vendor_request_update_stream_key, + (void *)"UpdateStreamKey"); + + verison_update_info = update_info_create_single( "[vertical-canvas]", "OBS", "https://api.aitum.tv/vertical", @@ -569,6 +608,8 @@ void obs_module_unload(void) "start_virtual_camera"); obs_websocket_vendor_unregister_request(vendor, "stop_virtual_camera"); + obs_websocket_vendor_unregister_request(vendor, + "update_stream_key"); } obs_frontend_remove_event_callback(frontend_event, nullptr); update_info_destroy(verison_update_info); @@ -7429,6 +7470,12 @@ void CanvasDock::OpenSourceProjector() obs_source_get_name(source)); } +void CanvasDock::updateStreamKey(const QString& newStreamKey) { + // Your code to update the stream_key, assuming stream_key is a member variable + this->stream_key = newStreamKey.toStdString(); + // any additional actions needed to apply the new stream key +} + LockedCheckBox::LockedCheckBox() {} LockedCheckBox::LockedCheckBox(QWidget *parent) : QCheckBox(parent) {} diff --git a/vertical-canvas.hpp b/vertical-canvas.hpp index bf3139f..195e050 100644 --- a/vertical-canvas.hpp +++ b/vertical-canvas.hpp @@ -412,6 +412,9 @@ private slots: obs_data_t *SaveSettings(); + void updateStreamKey(const QString& newStreamKey); + + obs_scene_t *GetCurrentScene(); std::vector GetScenes(); bool StreamingActive();