diff --git a/src/plugins/janus_streaming.c b/src/plugins/janus_streaming.c index d012fcccc7..524b1f35da 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 * @@ -478,6 +479,17 @@ multistream-test: { "id" : , "permanent" : } +\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" : , + "metadata" : "", +} \endverbatim * * Just as you can create and edit mountpoints, you can of course also destroy @@ -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}, @@ -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; 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"); @@ -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) @@ -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);