Skip to content

Commit

Permalink
Added Ability for Websockets to update Stream Key (#9)
Browse files Browse the repository at this point in the history
added functionality to send stream key via websocket
  • Loading branch information
phillypro authored Sep 20, 2023
1 parent 21d25c7 commit ed9f9a4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
47 changes: 47 additions & 0 deletions vertical-canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {}
Expand Down
3 changes: 3 additions & 0 deletions vertical-canvas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ private slots:

obs_data_t *SaveSettings();

void updateStreamKey(const QString& newStreamKey);


obs_scene_t *GetCurrentScene();
std::vector<QString> GetScenes();
bool StreamingActive();
Expand Down

0 comments on commit ed9f9a4

Please sign in to comment.