ExternalMedia: Change return object from ExternalMedia to Channel

When we created the External Media addition to ARI we created an
ExternalMedia object to be returned from the channels/externalMedia
REST endpoint.  This object contained the channel object that was
created plus local_address and local_port attributes (which are
also in the Channel variables).  At the time, we thought that
creating an ExternalMedia object would give us more flexibility
in the future but as we created the sample speech to text
application, we discovered that it doesn't work so well with ARI
client libraries that a) don't have the ExternalMedia object
defined and/or b) can't promote the embedded channel structure
to a first-class Channel object.

This change causes the channels/externalMedia REST endpoint to
return a Channel object (like channels/create and channels/originate)
instead of the ExternalMedia object.

Change-Id: If280094debd35102cf21e0a31a5e0846fec14af9
This commit is contained in:
George Joseph
2019-10-18 05:36:12 -06:00
parent a339c3fdc5
commit bfd0e05e59
5 changed files with 3 additions and 136 deletions

View File

@@ -2060,7 +2060,6 @@ static void external_media_rtp_udp(struct ast_ari_channels_external_media_args *
size_t endpoint_len;
char *endpoint;
struct ast_channel *chan;
struct ast_json *json_chan;
struct varshead *vars;
endpoint_len = strlen("UnicastRTP/") + strlen(args->external_host) + 1;
@@ -2089,43 +2088,10 @@ static void external_media_rtp_udp(struct ast_ari_channels_external_media_args *
return;
}
/*
* At this point, response->message contains a channel object so we
* need to save it then create a new ExternalMedia object and put the
* channel in it.
*/
json_chan = response->message;
response->message = ast_json_object_create();
if (!response->message) {
ast_channel_unref(chan);
ast_json_unref(json_chan);
ast_ari_response_alloc_failed(response);
return;
}
ast_json_object_set(response->message, "channel", json_chan);
/*
* At the time the channel snapshot was taken the channel variables might
* not have been set so we try to grab them directly from the channel.
*/
ast_channel_lock(chan);
vars = ast_channel_varshead(chan);
if (vars && !AST_LIST_EMPTY(vars)) {
struct ast_var_t *variables;
/* Put them all on the channel object */
ast_json_object_set(json_chan, "channelvars", ast_json_channel_vars(vars));
/* Grab out the local address and port */
AST_LIST_TRAVERSE(vars, variables, entries) {
if (!strcmp("UNICASTRTP_LOCAL_ADDRESS", ast_var_name(variables))) {
ast_json_object_set(response->message, "local_address",
ast_json_string_create(ast_var_value(variables)));
}
else if (!strcmp("UNICASTRTP_LOCAL_PORT", ast_var_name(variables))) {
ast_json_object_set(response->message, "local_port",
ast_json_integer_create(strtol(ast_var_value(variables), NULL, 10)));
}
}
ast_json_object_set(response->message, "channelvars", ast_json_channel_vars(vars));
}
ast_channel_unlock(chan);
ast_channel_unref(chan);