From 9831398d35c08e3ba49e94cf8e6aae7215bf19af Mon Sep 17 00:00:00 2001 From: Aymeric Moizard Date: Fri, 10 Jun 2022 14:58:11 +0200 Subject: [PATCH 1/3] Send an "edited" event to all viewers when an "edit" event occurred so all viewers receive the new metadata Signed-off-by: Aymeric Moizard --- src/plugins/janus_streaming.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/plugins/janus_streaming.c b/src/plugins/janus_streaming.c index d012fcccc7..727b8028b1 100644 --- a/src/plugins/janus_streaming.c +++ b/src/plugins/janus_streaming.c @@ -478,6 +478,17 @@ multistream-test: { "id" : , "permanent" : } +\endverbatim + * + * A successful \c edit will also result in an \c edited event sent to all viewers: + * +\verbatim +{ + "streaming" : "edited", + "id" : , + "permanent" : + "metadata" : "", +} \endverbatim * * Just as you can create and edit mountpoints, you can of course also destroy @@ -4423,6 +4434,28 @@ 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 */ + 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 *session = (janus_streaming_session *)viewer->data; + if(session == NULL) { + viewer = g_list_next(viewer); + continue; + } + janus_mutex_lock(&session->mutex); + JANUS_LOG(LOG_WARN, "Notifying mountpoint %s (%s) viewer\n", mp->id_str, mp->name); + gateway->push_event(session->handle, &janus_streaming_plugin, NULL, info, NULL); + janus_mutex_unlock(&session->mutex); + viewer = g_list_next(viewer); + } + json_decref(info); + janus_mutex_unlock(&mp->mutex); janus_mutex_unlock(&mountpoints_mutex); janus_refcount_decrease(&mp->ref); From 52865c92a5553db2376df6c1fc781af908408336 Mon Sep 17 00:00:00 2001 From: Aymeric Moizard Date: Tue, 14 Jun 2022 15:20:44 +0200 Subject: [PATCH 2/3] Send an "edited" event to all viewers when an "edit" event occurred so all viewers receive the new metadata * The edit request have an option to enable the event "edited_event" * The edited event is only sent if the edit contains "edited_event=true" AND if the metadata has been updated * Documentation updated Signed-off-by: Aymeric Moizard --- src/plugins/janus_streaming.c | 52 +++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/src/plugins/janus_streaming.c b/src/plugins/janus_streaming.c index 727b8028b1..95663739b2 100644 --- a/src/plugins/janus_streaming.c +++ b/src/plugins/janus_streaming.c @@ -466,7 +466,8 @@ multistream-test: { "new_secret" : "", "new_pin" : "", "new_is_private" : , - "permanent" : + "permanent" : , + "edited_event" : } \endverbatim * @@ -480,14 +481,13 @@ multistream-test: { } \endverbatim * - * A successful \c edit will also result in an \c edited event sent to all viewers: + * 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" : , - "permanent" : - "metadata" : "", + "metadata" : "", } \endverbatim * @@ -4189,6 +4189,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; 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"); @@ -4237,6 +4239,14 @@ 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) { + if (old_metadata == NULL && new_metadata == NULL) { + send_edited_event = FALSE; + } + if (old_metadata != NULL && new_metadata != NULL && !strcmp(old_metadata, new_metadata)) { + send_edited_event = FALSE; + } + } g_free(old_metadata); } if(is_private) @@ -4436,25 +4446,27 @@ static json_t *janus_streaming_process_synchronous_request(janus_streaming_sessi } /* Also notify viewers */ - 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 *session = (janus_streaming_session *)viewer->data; - if(session == NULL) { + 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 *session = (janus_streaming_session *)viewer->data; + if(session == NULL) { + viewer = g_list_next(viewer); + continue; + } + janus_mutex_lock(&session->mutex); + JANUS_LOG(LOG_VERB, "Notifying mountpoint %s (%s) viewer\n", mp->id_str, mp->name); + gateway->push_event(session->handle, &janus_streaming_plugin, NULL, info, NULL); + janus_mutex_unlock(&session->mutex); viewer = g_list_next(viewer); - continue; } - janus_mutex_lock(&session->mutex); - JANUS_LOG(LOG_WARN, "Notifying mountpoint %s (%s) viewer\n", mp->id_str, mp->name); - gateway->push_event(session->handle, &janus_streaming_plugin, NULL, info, NULL); - janus_mutex_unlock(&session->mutex); - viewer = g_list_next(viewer); + json_decref(info); } - json_decref(info); janus_mutex_unlock(&mp->mutex); janus_mutex_unlock(&mountpoints_mutex); From d6b8f7e68addd019226de1324df5e4b889b6c752 Mon Sep 17 00:00:00 2001 From: Aymeric Moizard Date: Fri, 17 Jun 2022 13:01:39 +0200 Subject: [PATCH 3/3] Send an "edited" event to all viewers when an "edit" event occurred so all viewers receive the new metadata * fix typo and documentation text * add edited_event to the object that performs the automated valitation checks on incoming JSON payloads * fix coding style * rename a variable to avoid shadowing NOTE: add missing new_metadata to the object that performs the automated valitation checks on incoming JSON payloads Signed-off-by: Aymeric Moizard --- src/plugins/janus_streaming.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/plugins/janus_streaming.c b/src/plugins/janus_streaming.c index 95663739b2..524b1f35da 100644 --- a/src/plugins/janus_streaming.c +++ b/src/plugins/janus_streaming.c @@ -467,7 +467,7 @@ multistream-test: { "new_pin" : "", "new_is_private" : , "permanent" : , - "edited_event" : + "edited_event" : } \endverbatim * @@ -481,7 +481,8 @@ multistream-test: { } \endverbatim * - * A successful \c edit will also result in an \c edited event sent to all viewers when the metadata has changed: + * 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 { @@ -1006,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}, @@ -4239,14 +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) { - if (old_metadata == NULL && new_metadata == NULL) { - send_edited_event = FALSE; - } - if (old_metadata != NULL && new_metadata != NULL && !strcmp(old_metadata, new_metadata)) { - send_edited_event = FALSE; - } - } + 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) @@ -4446,7 +4443,7 @@ static json_t *janus_streaming_process_synchronous_request(janus_streaming_sessi } /* Also notify viewers */ - if (send_edited_event) { + 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)); @@ -4454,15 +4451,15 @@ static json_t *janus_streaming_process_synchronous_request(janus_streaming_sessi json_object_set_new(info, "metadata", json_string(mp->metadata)); GList *viewer = g_list_first(mp->viewers); while(viewer) { - janus_streaming_session *session = (janus_streaming_session *)viewer->data; - if(session == NULL) { + janus_streaming_session *s = (janus_streaming_session *)viewer->data; + if(s == NULL) { viewer = g_list_next(viewer); continue; } - janus_mutex_lock(&session->mutex); + janus_mutex_lock(&s->mutex); JANUS_LOG(LOG_VERB, "Notifying mountpoint %s (%s) viewer\n", mp->id_str, mp->name); - gateway->push_event(session->handle, &janus_streaming_plugin, NULL, info, NULL); - janus_mutex_unlock(&session->mutex); + gateway->push_event(s->handle, &janus_streaming_plugin, NULL, info, NULL); + janus_mutex_unlock(&s->mutex); viewer = g_list_next(viewer); } json_decref(info);