diff options
author | Matthew Jordan <mjordan@digium.com> | 2015-04-07 15:22:42 +0000 |
---|---|---|
committer | Matthew Jordan <mjordan@digium.com> | 2015-04-07 15:22:42 +0000 |
commit | c2f50ba6f47e04c0457baa0bb5bf84b22a26d20b (patch) | |
tree | bef776975d16755afde6f2809bd5fae43fd7075a /main/stasis_channels.c | |
parent | af4d8027730fff35dba65eb2d7ade73ade4a4a8e (diff) |
ARI: Add the ability to intercept hold and raise an event
For some applications - such as SLA - a phone pressing hold should not behave
in the fashion that the Asterisk core would like it to. Instead, the hold
action has some application specific behaviour associated with it - such as
disconnecting the channel that initiated the hold; only playing MoH to channels
in the bridge if the channels are of a particular type, etc.
One way of accomplishing this is to use a framehook to intercept the
hold/unhold frames, raise an event, and eat the frame. Tasty. This patch
accomplishes that using a new dialplan function, HOLD_INTERCEPT.
In addition, some general cleanup of raising hold/unhold Stasis messages was
done, including removing some RAII_VAR usage.
Review: https://reviewboard.asterisk.org/r/4549/
ASTERISK-24922 #close
........
Merged revisions 434216 from http://svn.asterisk.org/svn/asterisk/branches/13
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@434217 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/stasis_channels.c')
-rw-r--r-- | main/stasis_channels.c | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/main/stasis_channels.c b/main/stasis_channels.c index 85abe58bc..968afbd7d 100644 --- a/main/stasis_channels.c +++ b/main/stasis_channels.c @@ -1136,6 +1136,47 @@ static struct ast_json *talking_stop_to_json(struct stasis_message *message, return channel_blob_to_json(message, "ChannelTalkingFinished", sanitize); } +static struct ast_json *hold_to_json(struct stasis_message *message, + const struct stasis_message_sanitizer *sanitize) +{ + struct ast_channel_blob *channel_blob = stasis_message_data(message); + struct ast_json *blob = channel_blob->blob; + struct ast_channel_snapshot *snapshot = channel_blob->snapshot; + const char *musicclass = ast_json_string_get(ast_json_object_get(blob, "musicclass")); + const struct timeval *tv = stasis_message_timestamp(message); + struct ast_json *json_channel; + + json_channel = ast_channel_snapshot_to_json(snapshot, sanitize); + if (!json_channel) { + return NULL; + } + + return ast_json_pack("{s: s, s: o, s: s, s: o}", + "type", "ChannelHold", + "timestamp", ast_json_timeval(*tv, NULL), + "musicclass", S_OR(musicclass, "N/A"), + "channel", json_channel); +} + +static struct ast_json *unhold_to_json(struct stasis_message *message, + const struct stasis_message_sanitizer *sanitize) +{ + struct ast_channel_blob *channel_blob = stasis_message_data(message); + struct ast_channel_snapshot *snapshot = channel_blob->snapshot; + const struct timeval *tv = stasis_message_timestamp(message); + struct ast_json *json_channel; + + json_channel = ast_channel_snapshot_to_json(snapshot, sanitize); + if (!json_channel) { + return NULL; + } + + return ast_json_pack("{s: s, s: o, s: o}", + "type", "ChannelUnhold", + "timestamp", ast_json_timeval(*tv, NULL), + "channel", json_channel); +} + /*! * @{ \brief Define channel message types. */ @@ -1154,8 +1195,12 @@ STASIS_MESSAGE_TYPE_DEFN(ast_channel_dtmf_begin_type); STASIS_MESSAGE_TYPE_DEFN(ast_channel_dtmf_end_type, .to_json = dtmf_end_to_json, ); -STASIS_MESSAGE_TYPE_DEFN(ast_channel_hold_type); -STASIS_MESSAGE_TYPE_DEFN(ast_channel_unhold_type); +STASIS_MESSAGE_TYPE_DEFN(ast_channel_hold_type, + .to_json = hold_to_json, + ); +STASIS_MESSAGE_TYPE_DEFN(ast_channel_unhold_type, + .to_json = unhold_to_json, + ); STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_start_type); STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_stop_type); STASIS_MESSAGE_TYPE_DEFN(ast_channel_fax_type); |