mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-10-09 21:14:02 +00:00
add chat to demo
This commit is contained in:
@@ -381,6 +381,7 @@ typedef struct conference_obj {
|
||||
char *bad_pin_sound;
|
||||
char *profile_name;
|
||||
char *domain;
|
||||
char *chat_id;
|
||||
char *caller_controls;
|
||||
char *moderator_controls;
|
||||
switch_live_array_t *la;
|
||||
@@ -2120,6 +2121,7 @@ static void adv_la(conference_obj_t *conference, conference_member_t *member, sw
|
||||
cJSON_AddItemToObject(data, "laChannel", cJSON_CreateString(conference->la_event_channel));
|
||||
cJSON_AddItemToObject(data, "laName", cJSON_CreateString(conference->la_name));
|
||||
cJSON_AddItemToObject(data, "role", cJSON_CreateString(switch_test_flag(member, MFLAG_MOD) ? "moderator" : "participant"));
|
||||
cJSON_AddItemToObject(data, "chatID", cJSON_CreateString(conference->chat_id));
|
||||
if (switch_test_flag(member, MFLAG_MOD)) {
|
||||
cJSON_AddItemToObject(data, "modChannel", cJSON_CreateString(conference->mod_event_channel));
|
||||
}
|
||||
@@ -4845,7 +4847,7 @@ static void conference_loop_output(conference_member_t *member)
|
||||
char *from = switch_event_get_header(event, "from");
|
||||
char *to = switch_event_get_header(event, "to");
|
||||
char *body = switch_event_get_body(event);
|
||||
|
||||
|
||||
if (to && from && body) {
|
||||
if (strchr(to, '+') && strncmp(to, CONF_CHAT_PROTO, strlen(CONF_CHAT_PROTO))) {
|
||||
switch_event_del_header(event, "to");
|
||||
@@ -5939,34 +5941,32 @@ static switch_status_t conference_say(conference_obj_t *conference, const char *
|
||||
}
|
||||
|
||||
/* send a message to every member of the conference */
|
||||
static void chat_message_broadcast(conference_obj_t *conference, switch_stream_handle_t *stream, const char *data, const char *chat_from, const char *ouuid)
|
||||
static void chat_message_broadcast(conference_obj_t *conference, switch_event_t *event)
|
||||
{
|
||||
conference_member_t *member = NULL;
|
||||
char *argv[2] = { 0 };
|
||||
char *dup = NULL;
|
||||
switch_core_session_message_t msg = { 0 };
|
||||
|
||||
switch_assert(conference != NULL);
|
||||
switch_assert(stream != NULL);
|
||||
|
||||
if (!(dup = strdup(chat_from))) {
|
||||
return;
|
||||
}
|
||||
switch_separate_string(dup, '@', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||
|
||||
msg.message_id = SWITCH_MESSAGE_INDICATE_MESSAGE;
|
||||
msg.string_array_arg[2] = data;
|
||||
msg.string_array_arg[3] = ouuid;
|
||||
msg.from = __FILE__;
|
||||
|
||||
switch_mutex_lock(conference->member_mutex);
|
||||
for (member = conference->members; member; member = member->next) {
|
||||
if (member->session && !switch_test_flag(member, MFLAG_NOCHANNEL)) {
|
||||
switch_core_session_t *lsession = NULL;
|
||||
const char *presence_id = switch_channel_get_variable(member->channel, "presence_id");
|
||||
const char *chat_proto = switch_channel_get_variable(member->channel, "chat_proto");
|
||||
switch_event_t *reply = NULL;
|
||||
|
||||
if (presence_id && chat_proto) {
|
||||
switch_event_dup(&reply, event);
|
||||
switch_event_add_header_string(reply, SWITCH_STACK_BOTTOM, "to", presence_id);
|
||||
switch_event_add_header_string(reply, SWITCH_STACK_BOTTOM, "conference_name", conference->name);
|
||||
switch_event_add_header_string(reply, SWITCH_STACK_BOTTOM, "conference_domain", conference->domain);
|
||||
|
||||
switch_event_set_body(reply, switch_event_get_body(event));
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SENDIT\n");
|
||||
DUMP_EVENT(reply);
|
||||
|
||||
lsession = member->session;
|
||||
|
||||
switch_core_session_receive_message(lsession, &msg);
|
||||
switch_core_chat_deliver(chat_proto, &reply);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
switch_mutex_unlock(conference->member_mutex);
|
||||
@@ -9752,16 +9752,13 @@ static switch_status_t chat_send(switch_event_t *message_event)
|
||||
const char *body;
|
||||
//const char *type;
|
||||
const char *hint;
|
||||
const char *ouuid;
|
||||
|
||||
proto = switch_event_get_header(message_event, "proto");
|
||||
from = switch_event_get_header(message_event, "from");
|
||||
to = switch_event_get_header(message_event, "to");
|
||||
//subject = switch_event_get_header(message_event, "subject");
|
||||
body = switch_event_get_body(message_event);
|
||||
//type = switch_event_get_header(message_event, "type");
|
||||
hint = switch_event_get_header(message_event, "hint");
|
||||
ouuid = switch_event_get_header(message_event, "Channel-Call-UUID");
|
||||
|
||||
|
||||
if ((p = strchr(to, '+'))) {
|
||||
to = ++p;
|
||||
@@ -9788,7 +9785,7 @@ static switch_status_t chat_send(switch_event_t *message_event)
|
||||
if (body != NULL && (lbuf = strdup(body))) {
|
||||
/* special case list */
|
||||
if (conference->broadcast_chat_messages) {
|
||||
chat_message_broadcast(conference, &stream, body, from, ouuid);
|
||||
chat_message_broadcast(conference, message_event);
|
||||
} else if (switch_stristr("list", lbuf)) {
|
||||
conference_list_pretty(conference, &stream);
|
||||
/* provide help */
|
||||
@@ -9876,7 +9873,7 @@ static conference_obj_t *conference_new(char *name, conf_xml_cfg_t cfg, switch_c
|
||||
char *maxmember_sound = NULL;
|
||||
uint32_t rate = 8000, interval = 20;
|
||||
uint32_t channels = 1;
|
||||
int broadcast_chat_messages = 0;
|
||||
int broadcast_chat_messages = 1;
|
||||
int comfort_noise_level = 0;
|
||||
int pin_retries = 3;
|
||||
int ivr_dtmf_timeout = 500;
|
||||
@@ -10091,8 +10088,8 @@ static conference_obj_t *conference_new(char *name, conf_xml_cfg_t cfg, switch_c
|
||||
}
|
||||
} else if (!strcasecmp(var, "moderator-controls") && !zstr(val)) {
|
||||
moderator_controls = val;
|
||||
} else if (!strcasecmp(var, "broadcast-chat-messages") && !zstr(val) && switch_true(val)) {
|
||||
broadcast_chat_messages = 1;
|
||||
} else if (!strcasecmp(var, "broadcast-chat-messages") && !zstr(val)) {
|
||||
broadcast_chat_messages = switch_true(val);
|
||||
} else if (!strcasecmp(var, "comfort-noise") && !zstr(val)) {
|
||||
int tmp;
|
||||
tmp = atoi(val);
|
||||
@@ -10379,6 +10376,8 @@ static conference_obj_t *conference_new(char *name, conf_xml_cfg_t cfg, switch_c
|
||||
conference->domain = "cluecon.com";
|
||||
}
|
||||
|
||||
conference->chat_id = switch_core_sprintf(conference->pool, "conf+%s@%s", conference->name, conference->domain);
|
||||
|
||||
conference->channels = channels;
|
||||
conference->rate = rate;
|
||||
conference->interval = interval;
|
||||
|
||||
@@ -588,6 +588,11 @@ static switch_status_t jsock_queue_event(jsock_t *jsock, cJSON **json)
|
||||
return status;
|
||||
}
|
||||
|
||||
static switch_status_t jsock_queue_event_clone(jsock_t *jsock, cJSON *json)
|
||||
{
|
||||
cJSON *dup = cJSON_Duplicate(json, 1);
|
||||
return jsock_queue_event(jsock, &dup);
|
||||
}
|
||||
|
||||
static void write_event(const char *event_channel, jsock_t *use_jsock, cJSON *event)
|
||||
{
|
||||
@@ -604,7 +609,7 @@ static void write_event(const char *event_channel, jsock_t *use_jsock, cJSON *ev
|
||||
cJSON_AddItemToObject(params, "eventSerno", cJSON_CreateNumber(np->serno++));
|
||||
msg = jrpc_new_req("verto.event", NULL, ¶ms);
|
||||
//ws_write_json(np->jsock, &msg, SWITCH_TRUE);
|
||||
jsock_queue_event(np->jsock, &msg);
|
||||
jsock_queue_event_clone(np->jsock, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -637,7 +642,7 @@ static void jsock_send_event(cJSON *event)
|
||||
params = cJSON_Duplicate(event, 1);
|
||||
msg = jrpc_new_req("verto.event", NULL, ¶ms);
|
||||
//ws_write_json(use_jsock, &msg, SWITCH_TRUE);
|
||||
jsock_queue_event(use_jsock, &msg);
|
||||
jsock_queue_event_clone(use_jsock, msg);
|
||||
switch_thread_rwlock_unlock(use_jsock->rwlock);
|
||||
use_jsock = NULL;
|
||||
return;
|
||||
@@ -853,7 +858,7 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
|
||||
|
||||
switch_event_add_header_string(req_params, SWITCH_STACK_BOTTOM, "action", "jsonrpc-authenticate");
|
||||
|
||||
if (switch_xml_locate_user_merged("id", id, domain, NULL, &x_user, req_params) != SWITCH_STATUS_SUCCESS) {
|
||||
if (switch_xml_locate_user_merged("id", id, domain, NULL, &x_user, req_params) != SWITCH_STATUS_SUCCESS && !jsock->profile->blind_reg) {
|
||||
*code = CODE_AUTH_FAILED;
|
||||
switch_snprintf(message, mlen, "Login Incorrect");
|
||||
} else {
|
||||
@@ -864,6 +869,11 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
|
||||
jsock->domain = switch_core_strdup(jsock->pool, domain);
|
||||
jsock->uid = switch_core_sprintf(jsock->pool, "%s@%s", id, domain);
|
||||
|
||||
if (!x_user) {
|
||||
switch_event_destroy(&req_params);
|
||||
r = SWITCH_TRUE;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if ((x_params = switch_xml_child(x_user, "params"))) {
|
||||
for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
|
||||
@@ -916,10 +926,6 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
|
||||
switch_event_destroy(&req_params);
|
||||
}
|
||||
|
||||
if (jsock->profile->blind_reg) {
|
||||
r = SWITCH_TRUE;
|
||||
}
|
||||
|
||||
end:
|
||||
|
||||
return r;
|
||||
@@ -1505,6 +1511,8 @@ static switch_status_t verto_connect(switch_core_session_t *session, const char
|
||||
|
||||
|
||||
switch_channel_set_variable(tech_pvt->channel, "verto_user", jsock->uid);
|
||||
switch_channel_set_variable(tech_pvt->channel, "presence_id", jsock->uid);
|
||||
switch_channel_set_variable(tech_pvt->channel, "chat_proto", VERTO_CHAT_PROTO);
|
||||
switch_channel_set_variable(tech_pvt->channel, "verto_host", jsock->domain);
|
||||
|
||||
if ((var = switch_event_get_header(jsock->params, "caller-id-name"))) {
|
||||
@@ -1829,7 +1837,7 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_
|
||||
cJSON_AddItemToObject(params, "display_name", cJSON_CreateString(name));
|
||||
cJSON_AddItemToObject(params, "display_number", cJSON_CreateString(number));
|
||||
//ws_write_json(jsock, &jmsg, SWITCH_TRUE);
|
||||
jsock_queue_event(jsock, &jmsg);
|
||||
jsock_queue_event_clone(jsock, jmsg);
|
||||
}
|
||||
|
||||
switch_thread_rwlock_unlock(jsock->rwlock);
|
||||
@@ -2544,9 +2552,10 @@ static switch_bool_t verto__info_func(const char *method, cJSON *params, jsock_t
|
||||
if ((msg = cJSON_GetObjectItem(params, "msg"))) {
|
||||
switch_event_t *event;
|
||||
char *to = (char *) cJSON_GetObjectCstr(msg, "to");
|
||||
//char *from = (char *) cJSON_GetObjectCstr(msg, "from");
|
||||
cJSON *indialog = cJSON_GetObjectItem(msg, "inDialog");
|
||||
const char *body = cJSON_GetObjectCstr(msg, "body");
|
||||
|
||||
switch_bool_t is_dialog = indialog && (indialog->type == cJSON_True || (indialog->type == cJSON_String && switch_true(indialog->valuestring)));
|
||||
|
||||
if (!zstr(to)) {
|
||||
if (strchr(to, '+')) {
|
||||
@@ -2560,6 +2569,7 @@ static switch_bool_t verto__info_func(const char *method, cJSON *params, jsock_t
|
||||
|
||||
if (!zstr(to) && !zstr(body) && switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", VERTO_CHAT_PROTO);
|
||||
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", jsock->uid);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_user", jsock->id);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_host", jsock->domain);
|
||||
@@ -2571,7 +2581,7 @@ static switch_bool_t verto__info_func(const char *method, cJSON *params, jsock_t
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "verto_profile", jsock->profile->name);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "verto_jsock_uuid", jsock->uuid_str);
|
||||
|
||||
if (indialog && (indialog->type == cJSON_True || (indialog->type == cJSON_String && switch_true(indialog->valuestring))) && call_id) {
|
||||
if (is_dialog) {
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call_id", call_id);
|
||||
}
|
||||
|
||||
@@ -2581,9 +2591,26 @@ static switch_bool_t verto__info_func(const char *method, cJSON *params, jsock_t
|
||||
switch_core_chat_send(proto, event);
|
||||
}
|
||||
|
||||
switch_core_chat_send("GLOBAL", event);
|
||||
if (is_dialog) {
|
||||
if ((dialog = cJSON_GetObjectItem(params, "dialogParams")) && (call_id = cJSON_GetObjectCstr(dialog, "callID"))) {
|
||||
switch_core_session_t *session = NULL;
|
||||
|
||||
if ((session = switch_core_session_locate(call_id))) {
|
||||
switch_core_session_queue_event(session, &event);
|
||||
switch_core_session_rwunlock(session);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
switch_core_chat_send("GLOBAL", event);
|
||||
}
|
||||
|
||||
switch_event_destroy(&event);
|
||||
if (event) {
|
||||
switch_event_destroy(&event);
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(*response, "message", cJSON_CreateString("SENT"));
|
||||
r = SWITCH_TRUE;
|
||||
|
||||
} else {
|
||||
r = SWITCH_FALSE;
|
||||
@@ -2667,6 +2694,8 @@ static switch_bool_t verto__invite_func(const char *method, cJSON *params, jsock
|
||||
switch_channel_set_name(channel, name);
|
||||
switch_channel_set_variable(channel, "jsock_uuid_str", jsock->uuid_str);
|
||||
switch_channel_set_variable(channel, "verto_user", jsock->uid);
|
||||
switch_channel_set_variable(channel, "presence_id", jsock->uid);
|
||||
switch_channel_set_variable(channel, "chat_proto", VERTO_CHAT_PROTO);
|
||||
switch_channel_set_variable(channel, "verto_host", jsock->domain);
|
||||
switch_channel_set_variable(channel, "event_channel_cookie", tech_pvt->jsock_uuid);
|
||||
switch_channel_set_variable(channel, "verto_profile_name", jsock->profile->name);
|
||||
@@ -4015,7 +4044,7 @@ static int verto_send_chat(const char *uid, const char *call_id, cJSON *msg)
|
||||
jsock_t *jsock;
|
||||
|
||||
if ((jsock = get_jsock(tech_pvt->jsock_uuid))) {
|
||||
jsock_queue_event(jsock, &msg);
|
||||
jsock_queue_event_clone(jsock, msg);
|
||||
//if (ws_write_json(jsock, &msg, SWITCH_FALSE) <= 0) {
|
||||
// switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
||||
//}
|
||||
@@ -4039,7 +4068,7 @@ static int verto_send_chat(const char *uid, const char *call_id, cJSON *msg)
|
||||
for(jsock = profile->jsock_head; jsock; jsock = jsock->next) {
|
||||
if (!strcmp(uid, jsock->uid)) {
|
||||
//ws_write_json(jsock, &msg, SWITCH_FALSE);
|
||||
jsock_queue_event(jsock, &msg);
|
||||
jsock_queue_event_clone(jsock, msg);
|
||||
hits++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -613,9 +613,8 @@ static switch_status_t do_chat_send(switch_event_t *message_event)
|
||||
switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "proto", proto);
|
||||
}
|
||||
|
||||
|
||||
replying = switch_event_get_header(message_event, "replying");
|
||||
|
||||
|
||||
if (!switch_true(replying) && !switch_stristr("global", proto) && !switch_true(switch_event_get_header(message_event, "skip_global_process"))) {
|
||||
switch_mutex_lock(loadable_modules.mutex);
|
||||
for (hi = switch_core_hash_first(loadable_modules.chat_hash); hi; hi = switch_core_hash_next(&hi)) {
|
||||
@@ -650,6 +649,7 @@ static switch_status_t do_chat_send(switch_event_t *message_event)
|
||||
switch_mutex_unlock(loadable_modules.mutex);
|
||||
}
|
||||
|
||||
|
||||
if (!do_skip && !switch_stristr("GLOBAL", dest_proto)) {
|
||||
if ((ci = switch_loadable_module_get_chat_interface(dest_proto)) && ci->chat_send) {
|
||||
status = ci->chat_send(message_event);
|
||||
|
||||
Reference in New Issue
Block a user