ARI: MOH start and stop for a channel
(issue ASTERISK-21974) Reported by: Matt Jordan Review: https://reviewboard.asterisk.org/r/2680/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@394810 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
parent
17c546173f
commit
a6329a3acf
|
@ -251,6 +251,19 @@ void stasis_app_control_hold(struct stasis_app_control *control);
|
|||
*/
|
||||
void stasis_app_control_unhold(struct stasis_app_control *control);
|
||||
|
||||
/*!
|
||||
* \brief Play music on hold to a channel (does not affect hold status)
|
||||
* \param control Control for \c res_stasis.
|
||||
* \param moh_class class of music on hold to play (NULL allowed)
|
||||
*/
|
||||
void stasis_app_control_moh_start(struct stasis_app_control *control, const char *moh_class);
|
||||
|
||||
/*!
|
||||
* \brief Stop playing music on hold to a channel (does not affect hold status)
|
||||
* \param control Control for \c res_stasis.
|
||||
*/
|
||||
void stasis_app_control_moh_stop(struct stasis_app_control *control);
|
||||
|
||||
/*!
|
||||
* \brief Returns the most recent snapshot for the associated channel.
|
||||
*
|
||||
|
|
|
@ -667,6 +667,116 @@ static void stasis_http_unhold_channel_cb(
|
|||
}
|
||||
#endif /* AST_DEVMODE */
|
||||
}
|
||||
/*!
|
||||
* \brief Parameter parsing callback for /channels/{channelId}/mohstart.
|
||||
* \param get_params GET parameters in the HTTP request.
|
||||
* \param path_vars Path variables extracted from the request.
|
||||
* \param headers HTTP headers.
|
||||
* \param[out] response Response to the HTTP request.
|
||||
*/
|
||||
static void stasis_http_moh_start_channel_cb(
|
||||
struct ast_variable *get_params, struct ast_variable *path_vars,
|
||||
struct ast_variable *headers, struct stasis_http_response *response)
|
||||
{
|
||||
#if defined(AST_DEVMODE)
|
||||
int is_valid;
|
||||
int code;
|
||||
#endif /* AST_DEVMODE */
|
||||
|
||||
struct ast_moh_start_channel_args args = {};
|
||||
struct ast_variable *i;
|
||||
|
||||
for (i = get_params; i; i = i->next) {
|
||||
if (strcmp(i->name, "mohClass") == 0) {
|
||||
args.moh_class = (i->value);
|
||||
} else
|
||||
{}
|
||||
}
|
||||
for (i = path_vars; i; i = i->next) {
|
||||
if (strcmp(i->name, "channelId") == 0) {
|
||||
args.channel_id = (i->value);
|
||||
} else
|
||||
{}
|
||||
}
|
||||
stasis_http_moh_start_channel(headers, &args, response);
|
||||
#if defined(AST_DEVMODE)
|
||||
code = response->response_code;
|
||||
|
||||
switch (code) {
|
||||
case 500: /* Internal server error */
|
||||
case 404: /* Channel not found */
|
||||
case 409: /* Channel not in a Stasis application */
|
||||
is_valid = 1;
|
||||
break;
|
||||
default:
|
||||
if (200 <= code && code <= 299) {
|
||||
is_valid = ari_validate_void(
|
||||
response->message);
|
||||
} else {
|
||||
ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/mohstart\n", code);
|
||||
is_valid = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_valid) {
|
||||
ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/mohstart\n");
|
||||
stasis_http_response_error(response, 500,
|
||||
"Internal Server Error", "Response validation failed");
|
||||
}
|
||||
#endif /* AST_DEVMODE */
|
||||
}
|
||||
/*!
|
||||
* \brief Parameter parsing callback for /channels/{channelId}/mohstop.
|
||||
* \param get_params GET parameters in the HTTP request.
|
||||
* \param path_vars Path variables extracted from the request.
|
||||
* \param headers HTTP headers.
|
||||
* \param[out] response Response to the HTTP request.
|
||||
*/
|
||||
static void stasis_http_moh_stop_channel_cb(
|
||||
struct ast_variable *get_params, struct ast_variable *path_vars,
|
||||
struct ast_variable *headers, struct stasis_http_response *response)
|
||||
{
|
||||
#if defined(AST_DEVMODE)
|
||||
int is_valid;
|
||||
int code;
|
||||
#endif /* AST_DEVMODE */
|
||||
|
||||
struct ast_moh_stop_channel_args args = {};
|
||||
struct ast_variable *i;
|
||||
|
||||
for (i = path_vars; i; i = i->next) {
|
||||
if (strcmp(i->name, "channelId") == 0) {
|
||||
args.channel_id = (i->value);
|
||||
} else
|
||||
{}
|
||||
}
|
||||
stasis_http_moh_stop_channel(headers, &args, response);
|
||||
#if defined(AST_DEVMODE)
|
||||
code = response->response_code;
|
||||
|
||||
switch (code) {
|
||||
case 500: /* Internal server error */
|
||||
case 404: /* Channel not found */
|
||||
case 409: /* Channel not in a Stasis application */
|
||||
is_valid = 1;
|
||||
break;
|
||||
default:
|
||||
if (200 <= code && code <= 299) {
|
||||
is_valid = ari_validate_void(
|
||||
response->message);
|
||||
} else {
|
||||
ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/mohstop\n", code);
|
||||
is_valid = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_valid) {
|
||||
ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/mohstop\n");
|
||||
stasis_http_response_error(response, 500,
|
||||
"Internal Server Error", "Response validation failed");
|
||||
}
|
||||
#endif /* AST_DEVMODE */
|
||||
}
|
||||
/*!
|
||||
* \brief Parameter parsing callback for /channels/{channelId}/play.
|
||||
* \param get_params GET parameters in the HTTP request.
|
||||
|
@ -995,6 +1105,24 @@ static struct stasis_rest_handlers channels_channelId_unhold = {
|
|||
.children = { }
|
||||
};
|
||||
/*! \brief REST handler for /api-docs/channels.{format} */
|
||||
static struct stasis_rest_handlers channels_channelId_mohstart = {
|
||||
.path_segment = "mohstart",
|
||||
.callbacks = {
|
||||
[AST_HTTP_POST] = stasis_http_moh_start_channel_cb,
|
||||
},
|
||||
.num_children = 0,
|
||||
.children = { }
|
||||
};
|
||||
/*! \brief REST handler for /api-docs/channels.{format} */
|
||||
static struct stasis_rest_handlers channels_channelId_mohstop = {
|
||||
.path_segment = "mohstop",
|
||||
.callbacks = {
|
||||
[AST_HTTP_POST] = stasis_http_moh_stop_channel_cb,
|
||||
},
|
||||
.num_children = 0,
|
||||
.children = { }
|
||||
};
|
||||
/*! \brief REST handler for /api-docs/channels.{format} */
|
||||
static struct stasis_rest_handlers channels_channelId_play = {
|
||||
.path_segment = "play",
|
||||
.callbacks = {
|
||||
|
@ -1030,8 +1158,8 @@ static struct stasis_rest_handlers channels_channelId = {
|
|||
[AST_HTTP_GET] = stasis_http_get_channel_cb,
|
||||
[AST_HTTP_DELETE] = stasis_http_delete_channel_cb,
|
||||
},
|
||||
.num_children = 10,
|
||||
.children = { &channels_channelId_dial,&channels_channelId_continue,&channels_channelId_answer,&channels_channelId_mute,&channels_channelId_unmute,&channels_channelId_hold,&channels_channelId_unhold,&channels_channelId_play,&channels_channelId_record,&channels_channelId_variable, }
|
||||
.num_children = 12,
|
||||
.children = { &channels_channelId_dial,&channels_channelId_continue,&channels_channelId_answer,&channels_channelId_mute,&channels_channelId_unmute,&channels_channelId_hold,&channels_channelId_unhold,&channels_channelId_mohstart,&channels_channelId_mohstop,&channels_channelId_play,&channels_channelId_record,&channels_channelId_variable, }
|
||||
};
|
||||
/*! \brief REST handler for /api-docs/channels.{format} */
|
||||
static struct stasis_rest_handlers channels = {
|
||||
|
|
|
@ -37,6 +37,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|||
#include "asterisk/bridging_features.h"
|
||||
#include "asterisk/frame.h"
|
||||
#include "asterisk/pbx.h"
|
||||
#include "asterisk/musiconhold.h"
|
||||
|
||||
struct stasis_app_control {
|
||||
/*! Queue of commands to dispatch on the channel */
|
||||
|
@ -325,6 +326,40 @@ void stasis_app_control_unhold(struct stasis_app_control *control)
|
|||
stasis_app_send_command_async(control, app_control_unhold, NULL);
|
||||
}
|
||||
|
||||
static void *app_control_moh_start(struct stasis_app_control *control,
|
||||
struct ast_channel *chan, void *data)
|
||||
{
|
||||
char *moh_class = data;
|
||||
|
||||
ast_moh_start(chan, moh_class, NULL);
|
||||
|
||||
ast_free(moh_class);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void stasis_app_control_moh_start(struct stasis_app_control *control, const char *moh_class)
|
||||
{
|
||||
char *data = NULL;
|
||||
|
||||
if (!ast_strlen_zero(moh_class)) {
|
||||
data = ast_strdup(moh_class);
|
||||
}
|
||||
|
||||
stasis_app_send_command_async(control, app_control_moh_start, data);
|
||||
}
|
||||
|
||||
static void *app_control_moh_stop(struct stasis_app_control *control,
|
||||
struct ast_channel *chan, void *data)
|
||||
{
|
||||
ast_moh_stop(chan);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void stasis_app_control_moh_stop(struct stasis_app_control *control)
|
||||
{
|
||||
stasis_app_send_command_async(control, app_control_moh_stop, NULL);
|
||||
}
|
||||
|
||||
struct ast_channel_snapshot *stasis_app_control_get_snapshot(
|
||||
const struct stasis_app_control *control)
|
||||
{
|
||||
|
|
|
@ -229,6 +229,34 @@ void stasis_http_unhold_channel(struct ast_variable *headers, struct ast_unhold_
|
|||
stasis_http_response_no_content(response);
|
||||
}
|
||||
|
||||
void stasis_http_moh_start_channel(struct ast_variable *headers, struct ast_moh_start_channel_args *args, struct stasis_http_response *response)
|
||||
{
|
||||
RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
|
||||
|
||||
control = find_control(response, args->channel_id);
|
||||
if (control == NULL) {
|
||||
/* Response filled in by find_control */
|
||||
return;
|
||||
}
|
||||
|
||||
stasis_app_control_moh_start(control, args->moh_class);
|
||||
stasis_http_response_no_content(response);
|
||||
}
|
||||
|
||||
void stasis_http_moh_stop_channel(struct ast_variable *headers, struct ast_moh_stop_channel_args *args, struct stasis_http_response *response)
|
||||
{
|
||||
RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
|
||||
|
||||
control = find_control(response, args->channel_id);
|
||||
if (control == NULL) {
|
||||
/* Response filled in by find_control */
|
||||
return;
|
||||
}
|
||||
|
||||
stasis_app_control_moh_stop(control);
|
||||
stasis_http_response_no_content(response);
|
||||
}
|
||||
|
||||
void stasis_http_play_on_channel(struct ast_variable *headers,
|
||||
struct ast_play_on_channel_args *args,
|
||||
struct stasis_http_response *response)
|
||||
|
|
|
@ -212,6 +212,36 @@ struct ast_unhold_channel_args {
|
|||
* \param[out] response HTTP response
|
||||
*/
|
||||
void stasis_http_unhold_channel(struct ast_variable *headers, struct ast_unhold_channel_args *args, struct stasis_http_response *response);
|
||||
/*! \brief Argument struct for stasis_http_moh_start_channel() */
|
||||
struct ast_moh_start_channel_args {
|
||||
/*! \brief Channel's id */
|
||||
const char *channel_id;
|
||||
/*! \brief Music on hold class to use */
|
||||
const char *moh_class;
|
||||
};
|
||||
/*!
|
||||
* \brief Play music on hold to a channel.
|
||||
*
|
||||
* Using media operations such as playOnChannel on a channel playing MOH in this manner will suspend MOH without resuming automatically. If continuing music on hold is desired, the stasis application must reinitiate music on hold.
|
||||
*
|
||||
* \param headers HTTP headers
|
||||
* \param args Swagger parameters
|
||||
* \param[out] response HTTP response
|
||||
*/
|
||||
void stasis_http_moh_start_channel(struct ast_variable *headers, struct ast_moh_start_channel_args *args, struct stasis_http_response *response);
|
||||
/*! \brief Argument struct for stasis_http_moh_stop_channel() */
|
||||
struct ast_moh_stop_channel_args {
|
||||
/*! \brief Channel's id */
|
||||
const char *channel_id;
|
||||
};
|
||||
/*!
|
||||
* \brief Stop playing music on hold to a channel.
|
||||
*
|
||||
* \param headers HTTP headers
|
||||
* \param args Swagger parameters
|
||||
* \param[out] response HTTP response
|
||||
*/
|
||||
void stasis_http_moh_stop_channel(struct ast_variable *headers, struct ast_moh_stop_channel_args *args, struct stasis_http_response *response);
|
||||
/*! \brief Argument struct for stasis_http_play_on_channel() */
|
||||
struct ast_play_on_channel_args {
|
||||
/*! \brief Channel's id */
|
||||
|
|
|
@ -463,6 +463,79 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/channels/{channelId}/mohstart",
|
||||
"description": "Play music on hold to a channel",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "POST",
|
||||
"summary": "Play music on hold to a channel.",
|
||||
"notes": "Using media operations such as playOnChannel on a channel playing MOH in this manner will suspend MOH without resuming automatically. If continuing music on hold is desired, the stasis application must reinitiate music on hold.",
|
||||
"nickname": "mohStartChannel",
|
||||
"responseClass": "void",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "channelId",
|
||||
"description": "Channel's id",
|
||||
"paramType": "path",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "mohClass",
|
||||
"description": "Music on hold class to use",
|
||||
"paramType": "query",
|
||||
"required": false,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
],
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Channel not found"
|
||||
},
|
||||
{
|
||||
"code": 409,
|
||||
"reason": "Channel not in a Stasis application"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/channels/{channelId}/mohstop",
|
||||
"description": "Stop playing music on hold to a channel",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "POST",
|
||||
"summary": "Stop playing music on hold to a channel.",
|
||||
"nickname": "mohStopChannel",
|
||||
"responseClass": "void",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "channelId",
|
||||
"description": "Channel's id",
|
||||
"paramType": "path",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
],
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Channel not found"
|
||||
},
|
||||
{
|
||||
"code": 409,
|
||||
"reason": "Channel not in a Stasis application"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/channels/{channelId}/play",
|
||||
"description": "Play media to a channel",
|
||||
|
|
Loading…
Reference in New Issue