diff --git a/html5/verto/demo/index.html b/html5/verto/demo/index.html index 2ccdde86dc..7a6e53acea 100644 --- a/html5/verto/demo/index.html +++ b/html5/verto/demo/index.html @@ -29,6 +29,36 @@ cursor: pointer; } + + + + #chatwin + { + background-color: #eeeeee; + width: 500px; + height:150px; + max-height:150px; + overflow-y: scroll; + scrolling: auto; + text-align: left; + border-style:inset; + font-size: 10pt; + } + + .l1 + { + border:1; + background-color:#fefefe; + height:1px; + opacity:0.4; + } + #chatmsg + { + width:400px; + max-height:40px; + } + + @@ -40,32 +70,32 @@
-
+
-
+
-
+
-
+
-
+
-
+
@@ -93,9 +123,16 @@
-

-
+ + +

@@ -146,8 +183,7 @@
-
-
+

@@ -269,13 +305,12 @@
- - + + - + - diff --git a/html5/verto/demo/js/verto-min.js b/html5/verto/demo/js/verto-min.js index a0dcc3cbd9..0c161c7cf4 100644 --- a/html5/verto/demo/js/verto-min.js +++ b/html5/verto/demo/js/verto-min.js @@ -72,11 +72,11 @@ this._ws_socket.close();}} $.JsonRpcClient.prototype.loginData=function(params){self.options.login=params.login;self.options.passwd=params.passwd;} $.JsonRpcClient.prototype.connectSocket=function(onmessage_cb){var self=this;if(self.to){clearTimeout(self.to);} if(!self.socketReady()){self.authing=false;if(self._ws_socket){delete self._ws_socket;} -self._ws_socket=new WebSocket(self.options.socketUrl);if(self._ws_socket){self._ws_socket.onmessage=onmessage_cb;self._ws_socket.onclose=function(w){if(!self.ws_sleep){self.ws_sleep=500;} +self._ws_socket=new WebSocket(self.options.socketUrl);if(self._ws_socket){self._ws_socket.onmessage=onmessage_cb;self._ws_socket.onclose=function(w){if(!self.ws_sleep){self.ws_sleep=1000;} if(self.options.onWSClose){self.options.onWSClose(self);} -console.error("Websocket Lost "+self.ws_cnt+" sleep: "+self.ws_sleep+"msec");self.to=setTimeout(function(){console.log("Attempting Reconnection....");self.connectSocket(onmessage_cb);},self.ws_sleep);self.ws_cnt++;if(self.ws_sleep<3000&&(self.ws_cnt%100)==0){self.ws_sleep+=500;}} +console.error("Websocket Lost "+self.ws_cnt+" sleep: "+self.ws_sleep+"msec");self.to=setTimeout(function(){console.log("Attempting Reconnection....");self.connectSocket(onmessage_cb);},self.ws_sleep);self.ws_cnt++;if(self.ws_sleep<3000&&(self.ws_cnt%10)==0){self.ws_sleep+=1000;}} self._ws_socket.onopen=function(){if(self.to){clearTimeout(self.to);} -self.ws_sleep=500;self.ws_cnt=0;if(self.options.onWSConnect){self.options.onWSConnect(self);} +self.ws_sleep=1000;self.ws_cnt=0;if(self.options.onWSConnect){self.options.onWSConnect(self);} var req;while(req=$.JsonRpcClient.q.pop()){self._ws_socket.send(req);}}}} return self._ws_socket?true:false;} $.JsonRpcClient.prototype._getSocket=function(onmessage_cb){if(this.options.socketUrl===null||!("WebSocket"in window))return null;this.connectSocket(onmessage_cb);return this._ws_socket;};$.JsonRpcClient.q=[];$.JsonRpcClient.prototype._wsCall=function(socket,request,success_cb,error_cb){var request_json=$.toJSON(request);if(socket.readyState<1){self=this;$.JsonRpcClient.q.push(request_json);} @@ -127,7 +127,7 @@ var dialog=new $.verto.dialog($.verto.enum.direction.outbound,this,args);dialog. return dialog;};$.verto.prototype.handleMessage=function(data){var verto=this;if(!(data&&data.method)){console.error("Invalid Data",data);return;} if(data.params.callID){var dialog=verto.dialogs[data.params.callID];if(dialog){switch(data.method){case'verto.bye':dialog.hangup(data.params);break;case'verto.answer':dialog.handleAnswer(data.params);break;case'verto.media':dialog.handleMedia(data.params);break;case'verto.display':dialog.handleDisplay(data.params);break;case'verto.info':dialog.handleInfo(data.params);break;default:console.debug("INVALID METHOD OR NON-EXISTANT CALL REFERENCE IGNORED",dialog,data.method);break;}}else{switch(data.method){case'verto.attach':data.params.attach=true;if(data.params.sdp&&data.params.sdp.indexOf("m=video")>0){data.params.useVideo=true;} if(data.params.sdp&&data.params.sdp.indexOf("stereo=1")>0){data.params.useStereo=true;} -dialog=new $.verto.dialog($.verto.enum.direction.inbound,verto,data.params);break;case'verto.invite':if(data.params.sdp&&data.params.sdp.indexOf("m=video")>0){data.params.wantVideo=true;} +dialog=new $.verto.dialog($.verto.enum.direction.inbound,verto,data.params);dialog.setState($.verto.enum.state.recovering);break;case'verto.invite':if(data.params.sdp&&data.params.sdp.indexOf("m=video")>0){data.params.wantVideo=true;} if(data.params.sdp&&data.params.sdp.indexOf("stereo=1")>0){data.params.useStereo=true;} dialog=new $.verto.dialog($.verto.enum.direction.inbound,verto,data.params);break;default:console.debug("INVALID METHOD OR NON-EXISTANT CALL REFERENCE IGNORED");break;}} return{method:data.method};}else{switch(data.method){case'verto.event':var list=null;var key=null;if(data.params){key=data.params.eventChannel;} @@ -135,7 +135,7 @@ if(key){list=verto.eventSUBS[key];if(!list){list=verto.eventSUBS[key.split(".")[ if(!list&&key&&key===verto.sessid){if(verto.callbacks.onMessage){verto.callbacks.onMessage(verto,null,$.verto.enum.message.pvtEvent,data.params);}}else if(!list&&key&&verto.dialogs[key]){verto.dialogs[key].sendMessage($.verto.enum.message.pvtEvent,data.params);}else if(!list){if(!key){key="UNDEFINED";} console.error("UNSUBBED or invalid EVENT "+key+" IGNORED");}else{for(var i in list){var sub=list[i];if(!sub||!sub.ready){console.error("invalid EVENT for "+key+" IGNORED");}else if(sub.handler){sub.handler(verto,data.params,sub.userData);}else if(verto.callbacks.onEvent){verto.callbacks.onEvent(verto,data.params,sub.userData);}else{console.log("EVENT:",data.params);}}} break;case"verto.info":if(verto.callbacks.onMessage){verto.callbacks.onMessage(verto,null,$.verto.enum.message.info,data.params.msg);} -console.error(data);console.debug("MESSAGE from: "+data.params.msg.from,data.params.msg.body);break;default:console.error("INVALID METHOD OR NON-EXISTANT CALL REFERENCE IGNORED",data.method);break;}}};var del_array=function(array,name){var r=[];var len=array.length;for(var i=0;i=array.length){array.push(name);}else{var x=0;var n=[];var len=array.length;for(var i=0;i$.verto.enum.state.requesting.val&&dialog.lastState.val<$.verto.enum.state.hangup.val){dialog.sendMethod("verto.bye",{});} +switch(dialog.state){case $.verto.enum.state.trying:setTimeout(function(){if(dialog.state==$.verto.enum.state.trying){dialog.setState($.verto.enum.state.hangup);}},5000);break;case $.verto.enum.state.purge:dialog.setState($.verto.enum.state.destroy);break;case $.verto.enum.state.hangup:if(dialog.lastState.val>$.verto.enum.state.requesting.val&&dialog.lastState.val<$.verto.enum.state.hangup.val){dialog.sendMethod("verto.bye",{});} dialog.setState($.verto.enum.state.destroy);break;case $.verto.enum.state.destroy:delete verto.dialogs[dialog.callID];dialog.rtc.stop();break;} return true;};$.verto.dialog.prototype.processReply=function(method,success,e){var dialog=this;switch(method){case"verto.answer":case"verto.attach":if(success){dialog.setState($.verto.enum.state.active);}else{dialog.hangup();} break;case"verto.invite":if(success){dialog.setState($.verto.enum.state.trying);}else{dialog.setState($.verto.enum.state.destroy);} @@ -207,7 +207,7 @@ if(success){} break;default:break;}};$.verto.dialog.prototype.hangup=function(params){var dialog=this;if(params){if(params.causeCode){dialog.causeCode=params.causeCode;} if(params.cause){dialog.cause=params.cause;}} if(dialog.state.val>$.verto.enum.state.new.val&&dialog.state.val<$.verto.enum.state.hangup.val){dialog.setState($.verto.enum.state.hangup);}else if(dialog.state.val<$.verto.enum.state.destroy){dialog.setState($.verto.enum.state.destroy);}};$.verto.dialog.prototype.stopRinging=function(){var dialog=this;if(dialog.verto.ringer){dialog.verto.ringer.stop();}};$.verto.dialog.prototype.indicateRing=function(){var dialog=this;if(dialog.verto.ringer){dialog.verto.ringer.attr("src",dialog.verto.options.ringFile)[0].play();setTimeout(function(){dialog.stopRinging();if(dialog.state==$.verto.enum.state.ringing){dialog.indicateRing();}},dialog.verto.options.ringSleep);}};$.verto.dialog.prototype.ring=function(){var dialog=this;dialog.setState($.verto.enum.state.ringing);dialog.indicateRing();};$.verto.dialog.prototype.useVideo=function(on){var dialog=this;dialog.params.useVideo=on;if(on){dialog.videoStream=dialog.audioStream;}else{dialog.videoStream=null;} -dialog.rtc.useVideo(dialog.videoStream);};$.verto.dialog.prototype.useStereo=function(on){var dialog=this;dialog.params.useStereo=on;dialog.rtc.useStereo(on);};$.verto.dialog.prototype.dtmf=function(digits){var dialog=this;if(digits){dialog.sendMethod("verto.info",{dtmf:digits});}};$.verto.dialog.prototype.transfer=function(dest,params){var dialog=this;if(dest){cur_call.sendMethod("verto.modify",{action:"transfer",destination:dest,params:params});}};$.verto.dialog.prototype.hold=function(params){var dialog=this;cur_call.sendMethod("verto.modify",{action:"hold",params:params});};$.verto.dialog.prototype.unhold=function(params){var dialog=this;cur_call.sendMethod("verto.modify",{action:"unhold",params:params});};$.verto.dialog.prototype.toggleHold=function(params){var dialog=this;cur_call.sendMethod("verto.modify",{action:"toggleHold",params:params});};$.verto.dialog.prototype.message=function(msg){var dialog=this;var err=0;if(!msg.to){console.error("Missing To");err++;} +dialog.rtc.useVideo(dialog.videoStream);};$.verto.dialog.prototype.useStereo=function(on){var dialog=this;dialog.params.useStereo=on;dialog.rtc.useStereo(on);};$.verto.dialog.prototype.dtmf=function(digits){var dialog=this;if(digits){dialog.sendMethod("verto.info",{dtmf:digits});}};$.verto.dialog.prototype.transfer=function(dest,params){var dialog=this;if(dest){cur_call.sendMethod("verto.modify",{action:"transfer",destination:dest,params:params});}};$.verto.dialog.prototype.hold=function(params){var dialog=this;cur_call.sendMethod("verto.modify",{action:"hold",params:params});};$.verto.dialog.prototype.unhold=function(params){var dialog=this;cur_call.sendMethod("verto.modify",{action:"unhold",params:params});};$.verto.dialog.prototype.toggleHold=function(params){var dialog=this;cur_call.sendMethod("verto.modify",{action:"toggleHold",params:params});};$.verto.dialog.prototype.message=function(msg){var dialog=this;var err=0;msg.from=dialog.params.login;if(!msg.to){console.error("Missing To");err++;} if(!msg.body){console.error("Missing Body");err++;} if(err){return false;} dialog.sendMethod("verto.info",{msg:msg});return true;};$.verto.dialog.prototype.answer=function(params){var dialog=this;if(!dialog.answered){if(params){if(params.useVideo){dialog.useVideo(true);} @@ -216,5 +216,5 @@ dialog.rtc.createAnswer(dialog.params.sdp);dialog.answered=true;}};$.verto.dialo if(dialog.state.val>=$.verto.enum.state.early.val){dialog.setState($.verto.enum.state.active);}else{dialog.rtc.answer(params.sdp,function(){dialog.setState($.verto.enum.state.active);},function(e){console.error(e);dialog.hangup();});console.log("ANSWER SDP",params.sdp);}};$.verto.dialog.prototype.cidString=function(enc){var dialog=this;var party=dialog.params.remote_caller_id_name+(enc?" <":" <")+dialog.params.remote_caller_id_number+(enc?">":">");return party;};$.verto.dialog.prototype.sendMessage=function(msg,params){var dialog=this;if(dialog.callbacks.onMessage){dialog.callbacks.onMessage(dialog.verto,dialog,msg,params);}};$.verto.dialog.prototype.handleInfo=function(params){var dialog=this;dialog.sendMessage($.verto.enum.message.info,params.msg);};$.verto.dialog.prototype.handleDisplay=function(params){var dialog=this;if(params.display_name){dialog.params.remote_caller_id_name=params.display_name;} if(params.display_number){dialog.params.remote_caller_id_number=params.display_number;} dialog.sendMessage($.verto.enum.message.display,{});};$.verto.dialog.prototype.handleMedia=function(params){var dialog=this;if(dialog.state.val>=$.verto.enum.state.early.val){return;} -dialog.rtc.answer(params.sdp,function(){dialog.setState($.verto.enum.state.early);},function(e){console.error(e);dialog.hangup();});console.log("EARLY SDP",params.sdp);};$.verto.ENUM=function(s){var i=0,o={};s.split(" ").map(function(x){o[x]={name:x,val:i++};});return Object.freeze(o);};$.verto.enum={};$.verto.enum.states=Object.freeze({new:{requesting:1,ringing:1,destroy:1,answering:1},requesting:{trying:1,hangup:1},trying:{active:1,early:1,hangup:1},ringing:{answering:1,hangup:1},answering:{active:1,hangup:1},active:{hangup:1,held:1},held:{hangup:1,active:1},early:{hangup:1,active:1},hangup:{destroy:1},destroy:{},purge:{destroy:1}});$.verto.enum.state=$.verto.ENUM("new requesting trying ringing answering early active held hangup destroy purge");$.verto.enum.direction=$.verto.ENUM("inbound outbound");$.verto.enum.message=$.verto.ENUM("display info pvtEvent");$.verto.enum=Object.freeze($.verto.enum);$.verto.saved=[];$(window).bind('beforeunload',function(){for(var i in $.verto.saved){var verto=$.verto.saved[i];if(verto){verto.logout();verto.purge();}} +dialog.rtc.answer(params.sdp,function(){dialog.setState($.verto.enum.state.early);},function(e){console.error(e);dialog.hangup();});console.log("EARLY SDP",params.sdp);};$.verto.ENUM=function(s){var i=0,o={};s.split(" ").map(function(x){o[x]={name:x,val:i++};});return Object.freeze(o);};$.verto.enum={};$.verto.enum.states=Object.freeze({new:{requesting:1,recovering:1,ringing:1,destroy:1,answering:1},requesting:{trying:1,hangup:1},recovering:{answering:1,hangup:1},trying:{active:1,early:1,hangup:1},ringing:{answering:1,hangup:1},answering:{active:1,hangup:1},active:{hangup:1,held:1},held:{hangup:1,active:1},early:{hangup:1,active:1},hangup:{destroy:1},destroy:{},purge:{destroy:1}});$.verto.enum.state=$.verto.ENUM("new requesting trying recovering ringing answering early active held hangup destroy purge");$.verto.enum.direction=$.verto.ENUM("inbound outbound");$.verto.enum.message=$.verto.ENUM("display info pvtEvent");$.verto.enum=Object.freeze($.verto.enum);$.verto.saved=[];$(window).bind('beforeunload',function(){for(var i in $.verto.saved){var verto=$.verto.saved[i];if(verto){verto.logout();verto.purge();}} return $.verto.warnOnUnload;});})(jQuery); \ No newline at end of file diff --git a/html5/verto/demo/verto.js b/html5/verto/demo/verto.js index 0f72f28f9a..56700c6a9d 100644 --- a/html5/verto/demo/verto.js +++ b/html5/verto/demo/verto.js @@ -1,10 +1,10 @@ 'use strict'; var cur_call = null; var confMan = null; -var $display = $("#display"); var verto; var ringing = false; var autocall = false; +var chatting_with = false; $( ".selector" ).pagecontainer({ "theme": "a" }); @@ -19,6 +19,8 @@ function clearConfMan() { } $("#conf").hide(); + $("#message").hide(); + chatting_with = null; } function goto_dialog(where) { @@ -37,9 +39,6 @@ function online(on) { $("#offline").hide(); first_login = true; } else { - if (first_login && online_visible) { - goto_dialog("logout"); - } $("#online").hide(); $("#offline").show(); @@ -48,6 +47,26 @@ function online(on) { online_visible = on; } +function setupChat() { + $("#chatwin").html(""); + + $("#chatsend").click(function() { + if (!cur_call && chatting_with) { + return; + } + + cur_call.message({to: chatting_with, body: $("#chatmsg").val()}); + $("#chatmsg").val(""); + }); + + $("#chatmsg").keyup(function (event) { + if (event.keyCode == 13 && !event.shiftKey) { + $( "#chatsend" ).trigger( "click" ); + } + }); + +} + function check_vid() { var use_vid = $("#use_vid").is(':checked'); return use_vid; @@ -59,7 +78,7 @@ var callbacks = { switch (msg) { case $.verto.enum.message.pvtEvent: - //console.error("pvtEvent", data.pvtData.action); +// console.error("pvtEvent", data.pvtData); if (data.pvtData) { switch (data.pvtData.action) { @@ -79,13 +98,22 @@ var callbacks = { }); $("#conf").show(); + $("#chatwin").html(""); + $("#message").show(); + + chatting_with = data.pvtData.chatID; break; } } break; case $.verto.enum.message.info: - $("#text").html("Message from: " + data.from + ":
" + "
" + data.body + "
"); + var body = data.body.replace(/(http[s]{0,1}:\/\/\S+)/g, "$1<\/a>"); + body = body.replace(/(?:\r\n|\r|\n)/g, '
'); + + $("#chatwin").append("" + data.from + ":
" + "" + body + "" + "
"); + $('#chatwin').animate({"scrollTop": $('#chatwin')[0].scrollHeight}, "fast"); + break; case $.verto.enum.message.display: var party = dialog.params.remote_caller_id_name + "<" + dialog.params.remote_caller_id_number + ">"; @@ -153,10 +181,11 @@ var callbacks = { break; case $.verto.enum.state.hangup: $("#main_info").html("Call ended with cause: " + d.cause); + goto_page("main"); case $.verto.enum.state.destroy: $("#hangup_cause").html(""); clearConfMan(); - goto_page("main"); + cur_call = null; break; case $.verto.enum.state.held: @@ -382,6 +411,9 @@ function init() { $("#webcam").hide(); online(false); + + setupChat(); + } $(document).ready(function() { @@ -418,6 +450,9 @@ $(document).bind("pagecontainerchange", function(e, data) { break; case "#page-main": + if (cur_call) { + goto_page("incall"); + } break; case "#page-login": diff --git a/html5/verto/js/src/jquery.jsonrpcclient.js b/html5/verto/js/src/jquery.jsonrpcclient.js index 9505cd14de..be2a7a2620 100644 --- a/html5/verto/js/src/jquery.jsonrpcclient.js +++ b/html5/verto/js/src/jquery.jsonrpcclient.js @@ -282,7 +282,7 @@ self._ws_socket.onmessage = onmessage_cb; self._ws_socket.onclose = function (w) { if (!self.ws_sleep) { - self.ws_sleep = 500; + self.ws_sleep = 1000; } if (self.options.onWSClose) { @@ -298,8 +298,8 @@ self.ws_cnt++; - if (self.ws_sleep < 3000 && (self.ws_cnt % 100) == 0) { - self.ws_sleep += 500; + if (self.ws_sleep < 3000 && (self.ws_cnt % 10) == 0) { + self.ws_sleep += 1000; } } @@ -308,7 +308,7 @@ if (self.to) { clearTimeout(self.to); } - self.ws_sleep = 500; + self.ws_sleep = 1000; self.ws_cnt = 0; if (self.options.onWSConnect) { self.options.onWSConnect(self); diff --git a/html5/verto/js/src/jquery.verto.js b/html5/verto/js/src/jquery.verto.js index 5c847d8364..461617ea16 100644 --- a/html5/verto/js/src/jquery.verto.js +++ b/html5/verto/js/src/jquery.verto.js @@ -460,6 +460,8 @@ } dialog = new $.verto.dialog($.verto.enum.direction.inbound, verto, data.params); + dialog.setState($.verto.enum.state.recovering); + break; case 'verto.invite': @@ -533,7 +535,7 @@ if (verto.callbacks.onMessage) { verto.callbacks.onMessage(verto, null, $.verto.enum.message.info, data.params.msg); } - console.error(data); + //console.error(data); console.debug("MESSAGE from: " + data.params.msg.from, data.params.msg.body); break; @@ -1389,7 +1391,8 @@ dialog.params = $.extend({ useVideo: verto.options.useVideo, useStereo: verto.options.useStereo, - tag: verto.options.tag + tag: verto.options.tag, + login: verto.options.login }, params); @@ -1567,6 +1570,13 @@ } switch (dialog.state) { + case $.verto.enum.state.trying: + setTimeout(function() { + if (dialog.state == $.verto.enum.state.trying) { + dialog.setState($.verto.enum.state.hangup); + } + }, 5000); + break; case $.verto.enum.state.purge: dialog.setState($.verto.enum.state.destroy); break; @@ -1760,6 +1770,8 @@ var dialog = this; var err = 0; + msg.from = dialog.params.login; + if (!msg.to) { console.error("Missing To"); err++; @@ -1885,6 +1897,7 @@ $.verto.enum.states = Object.freeze({ new: { requesting: 1, + recovering: 1, ringing: 1, destroy: 1, answering: 1 @@ -1893,6 +1906,10 @@ trying: 1, hangup: 1 }, + recovering: { + answering: 1, + hangup: 1 + }, trying: { active: 1, early: 1, @@ -1927,7 +1944,7 @@ } }); - $.verto.enum.state = $.verto.ENUM("new requesting trying ringing answering early active held hangup destroy purge"); + $.verto.enum.state = $.verto.ENUM("new requesting trying recovering ringing answering early active held hangup destroy purge"); $.verto.enum.direction = $.verto.ENUM("inbound outbound"); $.verto.enum.message = $.verto.ENUM("display info pvtEvent"); diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index 452d0663a2..bbef2f5e60 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -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; diff --git a/src/mod/endpoints/mod_verto/mod_verto.c b/src/mod/endpoints/mod_verto/mod_verto.c index 61ba82f93b..e75eeea8b1 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.c +++ b/src/mod/endpoints/mod_verto/mod_verto.c @@ -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++; } } diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index 2f0e3a7c94..c9ec5f0e81 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -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);