mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-14 16:15:04 +00:00
[mod_verto] add a way to broadcast an event to one session
This commit is contained in:
parent
0fcdeffb0d
commit
8c9d0ecd9e
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user