fix some issues with duplicate chat events and some cleanup

This commit is contained in:
Anthony Minessale 2014-07-24 22:58:12 +05:00
parent cd5e6d331a
commit 004c5ab2b0
3 changed files with 43 additions and 13 deletions

View File

@ -55,7 +55,11 @@ function setupChat() {
return;
}
cur_call.message({to: chatting_with, body: $("#chatmsg").val()});
cur_call.message({to: chatting_with,
body: $("#chatmsg").val(),
from_msg_name: cur_call.params.caller_id_name,
from_msg_number: cur_call.params.caller_id_number
});
$("#chatmsg").val("");
});
@ -109,9 +113,14 @@ var callbacks = {
break;
case $.verto.enum.message.info:
var body = data.body.replace(/(http[s]{0,1}:\/\/\S+)/g, "<a target='_blank' href='$1'>$1<\/a>");
body = body.replace(/(?:\r\n|\r|\n)/g, '<br />');
$("#chatwin").append("<span class=chatuid>" + data.from + ":</span><br>" + body);
if (body.slice(-1) !== "\n") {
body += "\n";
}
body = body.replace(/(?:\r\n|\r|\n)/g, '<br />');
var from = data.from_msg_name || data.from;
$("#chatwin").append("<span class=chatuid>" + from + ":</span><br>" + body);
$('#chatwin').animate({"scrollTop": $('#chatwin')[0].scrollHeight}, "fast");
break;

View File

@ -5944,8 +5944,10 @@ static switch_status_t conference_say(conference_obj_t *conference, const char *
static void chat_message_broadcast(conference_obj_t *conference, switch_event_t *event)
{
conference_member_t *member = NULL;
switch_event_t *processed;
switch_assert(conference != NULL);
switch_event_create(&processed, SWITCH_EVENT_CHANNEL_DATA);
switch_mutex_lock(conference->member_mutex);
for (member = conference->members; member; member = member->next) {
@ -5955,20 +5957,22 @@ static void chat_message_broadcast(conference_obj_t *conference, switch_event_t
switch_event_t *reply = NULL;
if (presence_id && chat_proto) {
if (switch_event_get_header(processed, presence_id)) {
continue;
}
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);
switch_core_chat_deliver(chat_proto, &reply);
switch_core_chat_deliver(chat_proto, &reply);
switch_event_add_header_string(processed, SWITCH_STACK_BOTTOM, presence_id, "true");
}
}
}
switch_event_destroy(&processed);
switch_mutex_unlock(conference->member_mutex);
}
@ -9796,7 +9800,10 @@ static switch_status_t chat_send(switch_event_t *message_event)
switch_safe_free(lbuf);
switch_core_chat_send_args(proto, CONF_CHAT_PROTO, to, hint && strchr(hint, '/') ? hint : from, "", stream.data, NULL, NULL, SWITCH_FALSE);
if (!conference->broadcast_chat_messages) {
switch_core_chat_send_args(proto, CONF_CHAT_PROTO, to, hint && strchr(hint, '/') ? hint : from, "", stream.data, NULL, NULL, SWITCH_FALSE);
}
switch_safe_free(stream.data);
switch_thread_rwlock_unlock(conference->rwlock);

View File

@ -946,7 +946,7 @@ static void set_call_params(cJSON *params, verto_pvt_t *tech_pvt) {
const char *caller_id_name = NULL;
const char *caller_id_number = NULL;
if (switch_channel_outbound_display(tech_pvt->channel)) {
if (switch_channel_inbound_display(tech_pvt->channel)) {
caller_id_name = switch_channel_get_variable(tech_pvt->channel, "caller_id_name");
caller_id_number = switch_channel_get_variable(tech_pvt->channel, "caller_id_number");
} else {
@ -2563,10 +2563,10 @@ static switch_bool_t verto__info_func(const char *method, cJSON *params, jsock_t
switch_event_t *event;
char *to = (char *) cJSON_GetObjectCstr(msg, "to");
//char *from = (char *) cJSON_GetObjectCstr(msg, "from");
cJSON *indialog = cJSON_GetObjectItem(msg, "inDialog");
cJSON *i, *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, '+')) {
pproto = strdup(to);
@ -2591,6 +2591,12 @@ 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);
for(i = msg->child; i; i = i->next) {
if (!zstr(i->string) && !zstr(i->valuestring) && (!strncasecmp(i->string, "from_", 5) || !strncasecmp(i->string, "to_", 3))) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, i->string, i->valuestring);
}
}
if (is_dialog) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call_id", call_id);
}
@ -4098,12 +4104,13 @@ static switch_status_t chat_send(switch_event_t *message_event)
const char *body = switch_event_get_body(message_event);
const char *call_id = switch_event_get_header(message_event, "call_id");
DUMP_EVENT(message_event);
//DUMP_EVENT(message_event);
if (!zstr(to) && !zstr(body) && !zstr(from)) {
cJSON *obj = NULL, *msg = NULL, *params = NULL;
switch_event_header_t *eh;
obj = jrpc_new_req("verto.info", call_id, &params);
msg = json_add_child_obj(params, "msg", NULL);
@ -4111,10 +4118,17 @@ static switch_status_t chat_send(switch_event_t *message_event)
cJSON_AddItemToObject(msg, "to", cJSON_CreateString(to));
cJSON_AddItemToObject(msg, "body", cJSON_CreateString(body));
for (eh = message_event->headers; eh; eh = eh->next) {
if ((!strncasecmp(eh->name, "from_", 5) || !strncasecmp(eh->name, "to_", 3))) {
cJSON_AddItemToObject(msg, eh->name, cJSON_CreateString(eh->value));
}
}
verto_send_chat(to, call_id, obj);
cJSON_Delete(obj);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID EVENT\n");
DUMP_EVENT(message_event);
status = SWITCH_STATUS_FALSE;
}