diff --git a/res/ari/resource_events.c b/res/ari/resource_events.c index f1342b7fae3cfd9dab65ba7261d264f8d925d8e2..deb7f9cc05774db3861a60db18d24ff15b3c65ff 100644 --- a/res/ari/resource_events.c +++ b/res/ari/resource_events.c @@ -103,12 +103,12 @@ static void stasis_app_message_handler( msg_type, msg_application); } else if (!session->ws_session) { - /* If the websocket is NULL, the message goes to the queue */ - AST_VECTOR_APPEND(&session->message_queue, message); - ast_log(LOG_WARNING, - "Queued '%s' message for Stasis app '%s'; websocket is not ready\n", - msg_type, - msg_application); + /* If the websocket is NULL, the message goes to the queue */ + AST_VECTOR_APPEND(&session->message_queue, message); + ast_log(LOG_WARNING, + "Queued '%s' message for Stasis app '%s'; websocket is not ready\n", + msg_type, + msg_application); } else { /* We are ready to publish the message */ ast_ari_websocket_session_write(session->ws_session, message); @@ -426,13 +426,18 @@ static int event_session_alloc(struct ast_tcptls_session_instance *ser, return 0; } +void ast_ari_websocket_events_event_websocket_dtor(void) +{ + ao2_cleanup(event_session_registry); + event_session_registry = NULL; +} + int ast_ari_websocket_events_event_websocket_init(void) { /* Try to instantiate the registry */ event_session_registry = ao2_container_alloc(EVENT_SESSION_NUM_BUCKETS, event_session_hash, event_session_compare); - if (!event_session_registry) { /* This is bad, bad. */ ast_log(LOG_WARNING, diff --git a/res/ari/resource_events.h b/res/ari/resource_events.h index bc763ebd3874f0a1b71a81696cddfd2c18500585..aa1e3dfd645f2c829419477e8d4c95bf2b1f5bc3 100644 --- a/res/ari/resource_events.h +++ b/res/ari/resource_events.h @@ -57,6 +57,13 @@ struct ast_ari_events_event_websocket_args { */ int ast_ari_websocket_events_event_websocket_init(void); +/*! + * \brief WebSocket connection for events. + * + * \return Nothing + */ +void ast_ari_websocket_events_event_websocket_dtor(void); + /*! * \brief WebSocket connection for events. * diff --git a/res/res_ari_events.c b/res/res_ari_events.c index bf33aeaff27a8f24a1900260a3d4f703b87ce438..4b2b151aa0ad0b339d1e51550fc9449d24da306e 100644 --- a/res/res_ari_events.c +++ b/res/res_ari_events.c @@ -462,6 +462,7 @@ static int unload_module(void) ast_ari_remove_handler(&events); ao2_cleanup(events.ws_server); events.ws_server = NULL; + ast_ari_websocket_events_event_websocket_dtor(); stasis_app_unref(); return 0; } diff --git a/rest-api-templates/ari_resource.h.mustache b/rest-api-templates/ari_resource.h.mustache index f28e832d189dd374890c0b6e3764d2a62b5d4d4c..5e06af734f7f56a1a219649134132aad2c6cbb8c 100644 --- a/rest-api-templates/ari_resource.h.mustache +++ b/rest-api-templates/ari_resource.h.mustache @@ -102,6 +102,17 @@ void ast_ari_{{c_name}}_{{c_nickname}}(struct ast_variable *headers, struct ast_ */ int ast_ari_websocket_{{c_name}}_{{c_nickname}}_init(void); +/*! + * \brief {{summary}} +{{#notes}} + * + * {{{notes}}} +{{/notes}} + * + * \return Nothing + */ +void ast_ari_websocket_{{c_name}}_{{c_nickname}}_dtor(void); + /*! * \brief {{summary}} {{#notes}}