mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-24 13:12:03 +00:00
FS-7889: [mod_conference] move conference chat to use an event channel so messages only go to the right 'room' for the conference
This commit is contained in:
@@ -212,6 +212,68 @@ void conference_event_mod_channel_handler(const char *event_channel, cJSON *json
|
||||
|
||||
}
|
||||
|
||||
void conference_event_chat_channel_handler(const char *event_channel, cJSON *json, const char *key, switch_event_channel_id_t id)
|
||||
{
|
||||
cJSON *data;
|
||||
cJSON *jid = 0;
|
||||
const char *type = NULL;
|
||||
const char *action = NULL;
|
||||
cJSON *msg;
|
||||
char *conference_name = strdup(event_channel + 15);
|
||||
char *message = NULL;
|
||||
cJSON *jdata;
|
||||
char *p;
|
||||
const char *uid = NULL;
|
||||
const char *display = NULL;
|
||||
|
||||
if (conference_name && (p = strchr(conference_name, '@'))) {
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
uid = cJSON_GetObjectCstr(json, "userid");
|
||||
display = cJSON_GetObjectCstr(json, "fromDisplay");
|
||||
|
||||
if ((data = cJSON_GetObjectItem(json, "data"))) {
|
||||
type = cJSON_GetObjectCstr(data, "type");
|
||||
action = cJSON_GetObjectCstr(data, "action");
|
||||
if ((jid = cJSON_GetObjectItem(data, "message"))) {
|
||||
if (!zstr(jid->valuestring)) {
|
||||
message = jid->valuestring;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (action && !strcasecmp(action, "send")) {
|
||||
msg = cJSON_CreateObject();
|
||||
jdata = json_add_child_obj(msg, "data", NULL);
|
||||
|
||||
cJSON_AddItemToObject(msg, "eventChannel", cJSON_CreateString(event_channel));
|
||||
cJSON_AddItemToObject(jdata, "direction", cJSON_CreateString("outbound"));
|
||||
|
||||
if (message) {
|
||||
cJSON_AddItemToObject(jdata, "message", cJSON_CreateString(message));
|
||||
}
|
||||
|
||||
if (display) {
|
||||
cJSON_AddItemToObject(jdata, "fromDisplay", cJSON_CreateString(display));
|
||||
}
|
||||
|
||||
if (uid) {
|
||||
cJSON_AddItemToObject(jdata, "from", cJSON_CreateString(uid));
|
||||
}
|
||||
|
||||
if (type) {
|
||||
cJSON_AddItemToObject(jdata, "type", cJSON_CreateString(type));
|
||||
} else {
|
||||
cJSON_AddItemToObject(jdata, "type", cJSON_CreateString("message"));
|
||||
}
|
||||
|
||||
switch_event_channel_broadcast(event_channel, &msg, __FILE__, conference_globals.event_channel_id);
|
||||
}
|
||||
|
||||
switch_safe_free(conference_name);
|
||||
}
|
||||
|
||||
void conference_event_la_channel_handler(const char *event_channel, cJSON *json, const char *key, switch_event_channel_id_t id)
|
||||
{
|
||||
switch_live_array_parse_json(json, conference_globals.event_channel_id);
|
||||
@@ -347,6 +409,8 @@ void conference_event_adv_la(conference_obj_t *conference, conference_member_t *
|
||||
cJSON_AddItemToObject(data, "modChannel", cJSON_CreateString(conference->mod_event_channel));
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(data, "chatChannel", cJSON_CreateString(conference->chat_event_channel));
|
||||
|
||||
switch_core_get_variables(&variables);
|
||||
for (hp = variables->headers; hp; hp = hp->next) {
|
||||
if (!strncasecmp(hp->name, "conference_verto_", 11)) {
|
||||
@@ -363,6 +427,7 @@ void conference_event_adv_la(conference_obj_t *conference, conference_member_t *
|
||||
if (cookie) {
|
||||
switch_event_channel_permission_modify(cookie, conference->la_event_channel, join);
|
||||
switch_event_channel_permission_modify(cookie, conference->mod_event_channel, join);
|
||||
switch_event_channel_permission_modify(cookie, conference->chat_event_channel, join);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,9 +242,11 @@ void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t *thread, void *ob
|
||||
|
||||
if (strchr(conference->name, '@')) {
|
||||
conference->la_event_channel = switch_core_sprintf(conference->pool, "conference-liveArray.%s", conference->name);
|
||||
conference->chat_event_channel = switch_core_sprintf(conference->pool, "conference-chat.%s", conference->name);
|
||||
conference->mod_event_channel = switch_core_sprintf(conference->pool, "conference-mod.%s", conference->name);
|
||||
} else {
|
||||
conference->la_event_channel = switch_core_sprintf(conference->pool, "conference-liveArray.%s@%s", conference->name, conference->domain);
|
||||
conference->chat_event_channel = switch_core_sprintf(conference->pool, "conference-chat.%s@%s", conference->name, conference->domain);
|
||||
conference->mod_event_channel = switch_core_sprintf(conference->pool, "conference-mod.%s@%s", conference->name, conference->domain);
|
||||
}
|
||||
|
||||
@@ -3303,6 +3305,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_conference_load)
|
||||
switch_event_channel_bind("conference", conference_event_channel_handler, &conference_globals.event_channel_id);
|
||||
switch_event_channel_bind("conference-liveArray", conference_event_la_channel_handler, &conference_globals.event_channel_id);
|
||||
switch_event_channel_bind("conference-mod", conference_event_mod_channel_handler, &conference_globals.event_channel_id);
|
||||
switch_event_channel_bind("conference-chat", conference_event_chat_channel_handler, &conference_globals.event_channel_id);
|
||||
|
||||
if ( conference_api_sub_syntax(&api_syntax) != SWITCH_STATUS_SUCCESS) {
|
||||
return SWITCH_STATUS_TERM;
|
||||
@@ -3358,6 +3361,8 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_conference_shutdown)
|
||||
|
||||
switch_event_channel_unbind(NULL, conference_event_channel_handler);
|
||||
switch_event_channel_unbind(NULL, conference_event_la_channel_handler);
|
||||
switch_event_channel_unbind(NULL, conference_event_mod_channel_handler);
|
||||
switch_event_channel_unbind(NULL, conference_event_chat_channel_handler);
|
||||
|
||||
switch_console_del_complete_func("::conference::conference_list_conferences");
|
||||
|
||||
|
||||
@@ -515,6 +515,7 @@ typedef struct conference_obj {
|
||||
char *name;
|
||||
char *la_name;
|
||||
char *la_event_channel;
|
||||
char *chat_event_channel;
|
||||
char *mod_event_channel;
|
||||
char *desc;
|
||||
char *timer_name;
|
||||
@@ -1002,7 +1003,7 @@ void conference_cdr_render(conference_obj_t *conference);
|
||||
void conference_event_channel_handler(const char *event_channel, cJSON *json, const char *key, switch_event_channel_id_t id);
|
||||
void conference_event_la_channel_handler(const char *event_channel, cJSON *json, const char *key, switch_event_channel_id_t id);
|
||||
void conference_event_mod_channel_handler(const char *event_channel, cJSON *json, const char *key, switch_event_channel_id_t id);
|
||||
|
||||
void conference_event_chat_channel_handler(const char *event_channel, cJSON *json, const char *key, switch_event_channel_id_t id);
|
||||
|
||||
void conference_member_itterator(conference_obj_t *conference, switch_stream_handle_t *stream, uint8_t non_mod, conference_api_member_cmd_t pfncallback, void *data);
|
||||
|
||||
|
||||
@@ -3386,8 +3386,10 @@ static switch_bool_t verto__invite_func(const char *method, cJSON *params, jsock
|
||||
if ((var = switch_event_get_header(jsock->params, "caller-id-name"))) {
|
||||
caller_id_name = var;
|
||||
}
|
||||
} else if (caller_id_name) {
|
||||
switch_event_add_header_string(jsock->params, SWITCH_STACK_BOTTOM, "caller-id-name", caller_id_name);
|
||||
}
|
||||
|
||||
|
||||
if (zstr(caller_id_number)) {
|
||||
if ((var = switch_event_get_header(jsock->params, "caller-id-number"))) {
|
||||
caller_id_number = var;
|
||||
@@ -3647,6 +3649,7 @@ static switch_bool_t verto__broadcast_func(const char *method, cJSON *params, js
|
||||
switch_bool_t r = SWITCH_FALSE;
|
||||
const char *event_channel = cJSON_GetObjectCstr(params, "eventChannel");
|
||||
cJSON *jevent;
|
||||
const char *display = NULL;
|
||||
|
||||
*response = cJSON_CreateObject();
|
||||
|
||||
@@ -3666,6 +3669,11 @@ static switch_bool_t verto__broadcast_func(const char *method, cJSON *params, js
|
||||
|
||||
cJSON_AddItemToObject(params, "userid", cJSON_CreateString(jsock->uid));
|
||||
|
||||
display = switch_event_get_header(jsock->params, "caller-id-name");
|
||||
if (display) {
|
||||
cJSON_AddItemToObject(params, "fromDisplay", cJSON_CreateString(display));
|
||||
}
|
||||
|
||||
jevent = cJSON_Duplicate(params, 1);
|
||||
switch_event_channel_broadcast(event_channel, &jevent, modname, globals.event_channel_id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user