Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send an "edited" event to all viewers when an "edit" event occurred in the streaming plugin #3000

Merged
merged 3 commits into from
Jun 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions src/plugins/janus_streaming.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@ multistream-test: {
"new_secret" : "<new secret for the mountpoint; optional>",
"new_pin" : "<new PIN for the mountpoint, PIN will be removed if set to an empty string; optional>",
"new_is_private" : <true|false, depending on whether the mountpoint should be now listable; optional>,
"permanent" : <true|false, whether the mountpoint should be saved to configuration file or not; false by default>
"permanent" : <true|false, whether the mountpoint should be saved to configuration file or not; false by default>,
"edited_event" : <true|false, whether an event will be sent to all viewers when metadata is updated; false by default>
}
\endverbatim
*
Expand All @@ -478,6 +479,17 @@ multistream-test: {
"id" : <unique ID of the just edited mountpoint>,
"permanent" : <true|false, depending on whether the changes were saved to configuration file or not>
}
\endverbatim
*
* In case \c edited_event was set to \c true in the request, a successful \c edit will
* also result in an \c edited event sent to all viewers when the metadata has changed:
*
\verbatim
{
"streaming" : "edited",
"id" : <unique ID of the just edited mountpoint>,
"metadata" : "<updated metadata for the mountpoint>",
}
\endverbatim
*
* Just as you can create and edit mountpoints, you can of course also destroy
Expand Down Expand Up @@ -995,10 +1007,12 @@ static struct janus_json_parameter adminkey_parameters[] = {
};
static struct janus_json_parameter edit_parameters[] = {
{"new_description", JSON_STRING, 0},
{"new_metadata", JSON_STRING, 0},
{"new_secret", JSON_STRING, 0},
{"new_pin", JSON_STRING, 0},
{"new_is_private", JANUS_JSON_BOOL, 0},
{"permanent", JANUS_JSON_BOOL, 0}
{"permanent", JANUS_JSON_BOOL, 0},
{"edited_event", JANUS_JSON_BOOL, 0}
};
static struct janus_json_parameter create_parameters[] = {
{"name", JSON_STRING, 0},
Expand Down Expand Up @@ -4178,6 +4192,8 @@ static json_t *janus_streaming_process_synchronous_request(janus_streaming_sessi
json_t *pin = json_object_get(root, "new_pin");
json_t *is_private = json_object_get(root, "new_is_private");
json_t *permanent = json_object_get(root, "permanent");
json_t *edited_event = json_object_get(root, "edited_event");
gboolean send_edited_event = edited_event ? json_is_true(edited_event) : FALSE;
amoizard marked this conversation as resolved.
Show resolved Hide resolved
gboolean save = permanent ? json_is_true(permanent) : FALSE;
if(save && config == NULL) {
JANUS_LOG(LOG_ERR, "No configuration file, can't edit mountpoint permanently\n");
Expand Down Expand Up @@ -4226,6 +4242,8 @@ static json_t *janus_streaming_process_synchronous_request(janus_streaming_sessi
char *old_metadata = mp->metadata;
char *new_metadata = g_strdup(json_string_value(md));
mp->metadata = new_metadata;
if(send_edited_event == TRUE && ((old_metadata == NULL && new_metadata == NULL) || (old_metadata != NULL && new_metadata != NULL && !strcmp(old_metadata, new_metadata))))
send_edited_event = FALSE;
g_free(old_metadata);
}
if(is_private)
Expand Down Expand Up @@ -4423,6 +4441,30 @@ static json_t *janus_streaming_process_synchronous_request(janus_streaming_sessi
json_object_set_new(info, "id", string_ids ? json_string(mp->id_str) : json_integer(mp->id));
gateway->notify_event(&janus_streaming_plugin, session ? session->handle : NULL, info);
}

/* Also notify viewers */
if(send_edited_event) {
json_t *info = json_object();
json_object_set_new(info, "event", json_string("edited"));
json_object_set_new(info, "id", string_ids ? json_string(mp->id_str) : json_integer(mp->id));
if(mp->metadata)
json_object_set_new(info, "metadata", json_string(mp->metadata));
GList *viewer = g_list_first(mp->viewers);
while(viewer) {
janus_streaming_session *s = (janus_streaming_session *)viewer->data;
if(s == NULL) {
viewer = g_list_next(viewer);
continue;
}
janus_mutex_lock(&s->mutex);
JANUS_LOG(LOG_VERB, "Notifying mountpoint %s (%s) viewer\n", mp->id_str, mp->name);
gateway->push_event(s->handle, &janus_streaming_plugin, NULL, info, NULL);
janus_mutex_unlock(&s->mutex);
viewer = g_list_next(viewer);
}
json_decref(info);
}

janus_mutex_unlock(&mp->mutex);
janus_mutex_unlock(&mountpoints_mutex);
janus_refcount_decrease(&mp->ref);
Expand Down