From 8c9d0ecd9e97a3dc5ed78de194385ba380e16913 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 5 Mar 2021 01:46:01 +0000 Subject: [PATCH] [mod_verto] add a way to broadcast an event to one session --- src/mod/endpoints/mod_verto/mod_verto.c | 39 +++++++++++++------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/mod/endpoints/mod_verto/mod_verto.c b/src/mod/endpoints/mod_verto/mod_verto.c index 3ae8913d04..2faf77455e 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.c +++ b/src/mod/endpoints/mod_verto/mod_verto.c @@ -710,7 +710,7 @@ static void write_event(const char *event_channel, const char *super_channel, js static void jsock_send_event(cJSON *event) { - const char *event_channel, *session_uuid = NULL; + const char *event_channel, *session_uuid = NULL, *direct_id = NULL; jsock_t *use_jsock = NULL; switch_core_session_t *session = NULL; @@ -719,17 +719,27 @@ static void jsock_send_event(cJSON *event) return; } - - if ((session = switch_core_session_locate(event_channel))) { - switch_channel_t *channel = switch_core_session_get_channel(session); - const char *jsock_uuid_str = switch_channel_get_variable(channel, "jsock_uuid_str"); - if (jsock_uuid_str) { - use_jsock = get_jsock(jsock_uuid_str); - } - switch_core_session_rwunlock(session); + if (!(direct_id = cJSON_GetObjectCstr(event, "eventChannelSessid"))) { + direct_id = event_channel; } - if (use_jsock || (use_jsock = get_jsock(event_channel))) { /* implicit subscription to channel identical to the connection uuid or session uuid */ + if ((session_uuid = cJSON_GetObjectCstr(event, "sessid"))) { + if (!(use_jsock = get_jsock(session_uuid))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Socket %s not connected\n", session_uuid); + return; + } + } else { + if ((session = switch_core_session_locate(direct_id))) { + switch_channel_t *channel = switch_core_session_get_channel(session); + const char *jsock_uuid_str = switch_channel_get_variable(channel, "jsock_uuid_str"); + if (jsock_uuid_str) { + use_jsock = get_jsock(jsock_uuid_str); + } + switch_core_session_rwunlock(session); + } + } + + if (use_jsock || (use_jsock = get_jsock(direct_id))) { /* implicit subscription to channel identical to the connection uuid or session uuid */ cJSON *msg = NULL, *params; params = cJSON_Duplicate(event, 1); msg = jrpc_new_req("verto.event", NULL, ¶ms); @@ -739,14 +749,6 @@ static void jsock_send_event(cJSON *event) return; } - - if ((session_uuid = cJSON_GetObjectCstr(event, "sessid"))) { - if (!(use_jsock = get_jsock(session_uuid))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Socket %s not connected\n", session_uuid); - return; - } - } - switch_thread_rwlock_rdlock(verto_globals.event_channel_rwlock); write_event(event_channel, NULL, use_jsock, event); if (strchr(event_channel, '.')) { @@ -4383,6 +4385,7 @@ static switch_bool_t verto__broadcast_func(const char *method, cJSON *params, js cJSON_AddItemToObject(params, "userid", cJSON_CreateString(jsock->uid)); + cJSON_AddItemToObject(params, "sessid", cJSON_CreateString(jsock->uuid_str)); display = switch_event_get_header(jsock->params, "caller-id-name"); if (display) {