diff --git a/configs/samples/stasis.conf.sample b/configs/samples/stasis.conf.sample index 46a240eb25e75f57fd2b76b22f2edea5c5a00db5..6fadc74073eea23813bbe699206d5fa6e1a1144c 100644 --- a/configs/samples/stasis.conf.sample +++ b/configs/samples/stasis.conf.sample @@ -53,6 +53,7 @@ ; decline=ast_channel_hangup_request_type ; decline=ast_channel_dtmf_begin_type ; decline=ast_channel_dtmf_end_type +; decline=ast_channel_flash_type ; decline=ast_channel_hold_type ; decline=ast_channel_unhold_type ; decline=ast_channel_chanspy_start_type diff --git a/doc/CHANGES-staging/flash_ami_event.txt b/doc/CHANGES-staging/flash_ami_event.txt new file mode 100644 index 0000000000000000000000000000000000000000..4cbea80683182d2ad44826242cd1316d708c433f --- /dev/null +++ b/doc/CHANGES-staging/flash_ami_event.txt @@ -0,0 +1,3 @@ +Subject: AMI Flash event + +Hook flash events are now exposed as AMI events. diff --git a/include/asterisk/stasis_channels.h b/include/asterisk/stasis_channels.h index 02654e91be24376bf78521e007759223357aad02..61f1c213a91f40ccb99b4a2848c66e9fd30dfe96 100644 --- a/include/asterisk/stasis_channels.h +++ b/include/asterisk/stasis_channels.h @@ -525,6 +525,13 @@ struct stasis_message_type *ast_channel_dtmf_begin_type(void); */ struct stasis_message_type *ast_channel_dtmf_end_type(void); +/*! + * \brief Message type for when a hook flash occurs on a channel. + * + * \retval A stasis message type + */ +struct stasis_message_type *ast_channel_flash_type(void); + /*! * \since 12 * \brief Message type for when a channel is placed on hold. diff --git a/main/channel.c b/main/channel.c index e92eaf8bb29a0dec6ab844a50e67e43e84e8fbe0..42083c3f47d2b409c7c4915e9b83ff05ace87bd2 100644 --- a/main/channel.c +++ b/main/channel.c @@ -3315,6 +3315,7 @@ int ast_waitfordigit_full(struct ast_channel *c, int timeout_ms, const char *bre case AST_CONTROL_UPDATE_RTP_PEER: case AST_CONTROL_HOLD: case AST_CONTROL_UNHOLD: + case AST_CONTROL_FLASH: case -1: /* Unimportant */ break; @@ -3393,6 +3394,11 @@ static void send_dtmf_end_event(struct ast_channel *chan, ast_channel_publish_blob(chan, ast_channel_dtmf_end_type(), blob); } +static void send_flash_event(struct ast_channel *chan) +{ + ast_channel_publish_blob(chan, ast_channel_flash_type(), NULL); +} + static void ast_read_generator_actions(struct ast_channel *chan, struct ast_frame *f) { struct ast_generator *generator; @@ -3859,6 +3865,8 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio, int */ ast_frfree(f); f = &ast_null_frame; + } else if (f->subclass.integer == AST_CONTROL_FLASH) { + send_flash_event(chan); } break; case AST_FRAME_DTMF_END: diff --git a/main/manager_channels.c b/main/manager_channels.c index 7f40efe54cdcaf1b566bb494f0111b728551f6bf..dae737c3a62a7362fc2d81f2b122205ec31ccb82 100644 --- a/main/manager_channels.c +++ b/main/manager_channels.c @@ -968,6 +968,24 @@ static void channel_dtmf_end_cb(void *data, struct stasis_subscription *sub, digit, duration_ms, direction); } +static void channel_flash_cb(void *data, struct stasis_subscription *sub, + struct stasis_message *message) +{ + struct ast_channel_blob *obj = stasis_message_data(message); + struct ast_str *channel_event_string; + + channel_event_string = ast_manager_build_channel_state_string(obj->snapshot); + if (!channel_event_string) { + return; + } + + manager_event(EVENT_FLAG_CALL, "Flash", + "%s", + ast_str_buffer(channel_event_string)); + + ast_free(channel_event_string); +} + static void channel_hangup_handler_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message) { @@ -1327,6 +1345,9 @@ int manager_channels_init(void) ret |= stasis_message_router_add(message_router, ast_channel_dtmf_end_type(), channel_dtmf_end_cb, NULL); + ret |= stasis_message_router_add(message_router, + ast_channel_flash_type(), channel_flash_cb, NULL); + ret |= stasis_message_router_add(message_router, ast_channel_hangup_request_type(), channel_hangup_request_cb, NULL); diff --git a/main/stasis.c b/main/stasis.c index 4ae6d6a357da0b082b8fe08bcc28dc8d6312057d..bc11b7f4caf5b84f6abd0fea668f3df5373a4002 100644 --- a/main/stasis.c +++ b/main/stasis.c @@ -120,6 +120,7 @@ <enum name="ast_channel_hangup_request_type" /> <enum name="ast_channel_dtmf_begin_type" /> <enum name="ast_channel_dtmf_end_type" /> + <enum name="ast_channel_flash_type" /> <enum name="ast_channel_hold_type" /> <enum name="ast_channel_unhold_type" /> <enum name="ast_channel_chanspy_start_type" /> diff --git a/main/stasis_channels.c b/main/stasis_channels.c index 3f3312be1a0850c2a8efe9fcfe26d5545a210f44..5e39c0765411b277ce40cbd563f1e0855067d80b 100644 --- a/main/stasis_channels.c +++ b/main/stasis_channels.c @@ -1598,6 +1598,7 @@ STASIS_MESSAGE_TYPE_DEFN(ast_channel_hold_type, STASIS_MESSAGE_TYPE_DEFN(ast_channel_unhold_type, .to_json = unhold_to_json, ); +STASIS_MESSAGE_TYPE_DEFN(ast_channel_flash_type); 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); @@ -1642,6 +1643,7 @@ static void stasis_channels_cleanup(void) STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_masquerade_type); STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_begin_type); STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_end_type); + STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_flash_type); STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_hold_type); STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_unhold_type); STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_chanspy_start_type); @@ -1695,6 +1697,7 @@ int ast_stasis_channels_init(void) res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_masquerade_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_begin_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_end_type); + res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_flash_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_hold_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_unhold_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_chanspy_start_type);