add chat to demo

This commit is contained in:
Anthony Minessale 2014-07-24 10:13:32 +05:00
parent cb7a3385aa
commit 7596689865
8 changed files with 196 additions and 81 deletions

View File

@ -29,6 +29,36 @@
cursor: pointer; 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;
}
</style> </style>
</head> </head>
@ -40,32 +70,32 @@
<br> <br>
<a target="_CC2104" href="https://www.cluecon.com"><img border="0" width="300" src="img/cc_banner2014.gif"></a> <a target="_CC2104" href="https://www.cluecon.com"><img border="0" width="300" src="img/cc_banner2014.gif"></a>
<div data-role="fieldcontain"> <div class="ui-field-contain">
<label for="name">Login</label> <label for="name">Login</label>
<input type="text" size="20" id="login"/> <input type="text" size="20" id="login"/>
</div> </div>
<div data-role="fieldcontain"> <div class="ui-field-contain">
<label for="name">Password</label> <label for="name">Password</label>
<input type="password" size="20" id="passwd"/> <input type="password" size="20" id="passwd"/>
</div> </div>
<div data-role="fieldcontain"> <div class="ui-field-contain">
<label for="name">CID Name</label> <label for="name">CID Name</label>
<input type="text" size="30" id="name"/> <input type="text" size="30" id="name"/>
</div> </div>
<div data-role="fieldcontain"> <div class="ui-field-contain">
<label for="name">CID Number</label> <label for="name">CID Number</label>
<input type="text" size="20" id="cid"/> <input type="text" size="20" id="cid"/>
</div> </div>
<div data-role="fieldcontain"> <div class="ui-field-contain">
<label for="name">Hostname</label> <label for="name">Hostname</label>
<input type="text" size="20" id="hostName"/> <input type="text" size="20" id="hostName"/>
</div> </div>
<div data-role="fieldcontain"> <div class="ui-field-contain">
<label for="name">Websocket URL</label> <label for="name">Websocket URL</label>
<input type="text" size="20" id="wsURL"/> <input type="text" size="20" id="wsURL"/>
</div> </div>
@ -93,9 +123,16 @@
</table> </table>
</div> </div>
<div id="display" style="font-weight:bold;font-size:18px"></div>
<br> <br>
<div data-role="fieldcontain" id="xferdiv"> <div id="message" hidden="true">
<hr class="l1" width="500"/>
<div id="chatwin"></div>
<!-- <textarea readonly id="chatwin"></textarea>-->
<table><tr><td><textarea id="chatmsg"></textarea></td><td><button id="chatsend" style="width:100px;">Send</button></td></tr></table>
<hr class="l1" width="500"/><br>
</div>
<div class="ui-field-contain" id="xferdiv">
<input data-mini="true" type="text" id="xferto"><br> <input data-mini="true" type="text" id="xferto"><br>
<button data-inline="true" id="cancelxferbtn">Cancel Transfer</button> <button data-inline="true" id="cancelxferbtn">Cancel Transfer</button>
<button data-inline="true" class="startxferbtn">Complete Transfer</button> <button data-inline="true" class="startxferbtn">Complete Transfer</button>
@ -146,8 +183,7 @@
</div> </div>
<div id="online" align="center" style="width:600px"> <div id="online" align="center" style="width:600px">
<div id="text"></div> <div class="ui-field-contain">
<div data-role="fieldcontain">
<input type="text" id="ext"/><br> <input type="text" id="ext"/><br>
<div id="dialpad"> <div id="dialpad">
<button class="dialbtn" data-inline="true">1</button> <button class="dialbtn" data-inline="true">1</button>
@ -269,13 +305,12 @@
</div> </div>
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.1.min.js"></script> <script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquerymobile/1.4.3/jquery.mobile.min.js"></script> <script type="text/javascript" src="js/jquery.mobile.min.js"></script>
<script type="text/javascript" src="js/jquery.json-2.4.min.js"></script> <script type="text/javascript" src="js/jquery.json-2.4.min.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script> <script type="text/javascript" src="js/jquery.cookie.js"></script>
<script type="text/javascript" src="//cdn.datatables.net/1.10.1/js/jquery.dataTables.min.js"></script> <script type="text/javascript" src="js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="js/verto-min.js"></script> <script type="text/javascript" src="js/verto-min.js"></script>
<script type="text/javascript" src="verto.js"></script> <script type="text/javascript" src="verto.js"></script>
</body> </body>

View File

@ -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.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);} $.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;} 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);} 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_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);}}}} var req;while(req=$.JsonRpcClient.q.pop()){self._ws_socket.send(req);}}}}
return self._ws_socket?true:false;} 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);} $.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;} 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.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;} 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;} 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;}} 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;} 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";} 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);}}} 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);} 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<len;i++){if(array[i]!=name){r.push(array[i]);}} 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<len;i++){if(array[i]!=name){r.push(array[i]);}}
return r;};var hashArray=function(){var vha=this;var hash={};var array=[];vha.reorder=function(a){array=a;var h=hash;hash={};var len=array.length;for(var i=0;i<len;i++){var key=array[i];if(h[key]){hash[key]=h[key];delete h[key];}} return r;};var hashArray=function(){var vha=this;var hash={};var array=[];vha.reorder=function(a){array=a;var h=hash;hash={};var len=array.length;for(var i=0;i<len;i++){var key=array[i];if(h[key]){hash[key]=h[key];delete h[key];}}
h=undefined;};vha.clear=function(){hash=undefined;array=undefined;hash={};array=[];};vha.add=function(name,val,insertAt){var redraw=false;if(!hash[name]){if(insertAt===undefined||insertAt<0||insertAt>=array.length){array.push(name);}else{var x=0;var n=[];var len=array.length;for(var i=0;i<len;i++){if(x++==insertAt){n.push(name);} h=undefined;};vha.clear=function(){hash=undefined;array=undefined;hash={};array=[];};vha.add=function(name,val,insertAt){var redraw=false;if(!hash[name]){if(insertAt===undefined||insertAt<0||insertAt>=array.length){array.push(name);}else{var x=0;var n=[];var len=array.length;for(var i=0;i<len;i++){if(x++==insertAt){n.push(name);}
n.push(array[i]);} n.push(array[i]);}
@ -184,7 +184,7 @@ $.verto.confMan.prototype.modCommand=function(cmd,id,value){var confMan=this;con
$.verto.confMan.prototype.destroy=function(){var confMan=this;confMan.destroyed=true;if(confMan.lt){confMan.lt.destroy();} $.verto.confMan.prototype.destroy=function(){var confMan=this;confMan.destroyed=true;if(confMan.lt){confMan.lt.destroy();}
if(confMan.params.laData.modChannel){confMan.verto.unsubscribe(confMan.params.laData.modChannel);} if(confMan.params.laData.modChannel){confMan.verto.unsubscribe(confMan.params.laData.modChannel);}
if(confMan.params.mainModID){$(confMan.params.mainModID).html("");}} if(confMan.params.mainModID){$(confMan.params.mainModID).html("");}}
$.verto.dialog=function(direction,verto,params){var dialog=this;dialog.params=$.extend({useVideo:verto.options.useVideo,useStereo:verto.options.useStereo,tag:verto.options.tag},params);dialog.verto=verto;dialog.direction=direction;dialog.lastState=null;dialog.state=dialog.lastState=$.verto.enum.state.new;dialog.callbacks=verto.callbacks;dialog.answered=false;dialog.attach=params.attach||false;if(dialog.params.callID){dialog.callID=dialog.params.callID;}else{dialog.callID=dialog.params.callID=generateGUID();} $.verto.dialog=function(direction,verto,params){var dialog=this;dialog.params=$.extend({useVideo:verto.options.useVideo,useStereo:verto.options.useStereo,tag:verto.options.tag,login:verto.options.login},params);dialog.verto=verto;dialog.direction=direction;dialog.lastState=null;dialog.state=dialog.lastState=$.verto.enum.state.new;dialog.callbacks=verto.callbacks;dialog.answered=false;dialog.attach=params.attach||false;if(dialog.params.callID){dialog.callID=dialog.params.callID;}else{dialog.callID=dialog.params.callID=generateGUID();}
if(dialog.params.tag){dialog.audioStream=document.getElementById(dialog.params.tag);if(dialog.params.useVideo){dialog.videoStream=dialog.audioStream;}} if(dialog.params.tag){dialog.audioStream=document.getElementById(dialog.params.tag);if(dialog.params.useVideo){dialog.videoStream=dialog.audioStream;}}
dialog.verto.dialogs[dialog.callID]=dialog;var RTCcallbacks={};if(dialog.direction==$.verto.enum.direction.inbound){dialog.params.remote_caller_id_name=dialog.params.caller_id_name;dialog.params.remote_caller_id_number=dialog.params.caller_id_number;if(!dialog.params.remote_caller_id_name){dialog.params.remote_caller_id_name="Nobody";} dialog.verto.dialogs[dialog.callID]=dialog;var RTCcallbacks={};if(dialog.direction==$.verto.enum.direction.inbound){dialog.params.remote_caller_id_name=dialog.params.caller_id_name;dialog.params.remote_caller_id_number=dialog.params.caller_id_number;if(!dialog.params.remote_caller_id_name){dialog.params.remote_caller_id_name="Nobody";}
if(!dialog.params.remote_caller_id_number){dialog.params.remote_caller_id_number="UNKNOWN";} if(!dialog.params.remote_caller_id_number){dialog.params.remote_caller_id_number="UNKNOWN";}
@ -198,7 +198,7 @@ if(dialog.state==state||!checkStateChange(dialog.state,state)){console.error("Di
console.info("Dialog "+dialog.callID+": state change from "+dialog.state.name+" to "+state.name);dialog.lastState=dialog.state;dialog.state=state;if(!dialog.causeCode){dialog.causeCode=16;} console.info("Dialog "+dialog.callID+": state change from "+dialog.state.name+" to "+state.name);dialog.lastState=dialog.state;dialog.state=state;if(!dialog.causeCode){dialog.causeCode=16;}
if(!dialog.cause){dialog.cause="NORMAL CLEARING";} if(!dialog.cause){dialog.cause="NORMAL CLEARING";}
if(dialog.callbacks.onDialogState){dialog.callbacks.onDialogState(this);} if(dialog.callbacks.onDialogState){dialog.callbacks.onDialogState(this);}
switch(dialog.state){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",{});} 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;} 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();} 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);} 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;} 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(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;} 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(!msg.body){console.error("Missing Body");err++;}
if(err){return false;} 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);} 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?" &lt;":" <")+dialog.params.remote_caller_id_number+(enc?"&gt;":">");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(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?" &lt;":" <")+dialog.params.remote_caller_id_number+(enc?"&gt;":">");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;} 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.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); return $.verto.warnOnUnload;});})(jQuery);

View File

@ -1,10 +1,10 @@
'use strict'; 'use strict';
var cur_call = null; var cur_call = null;
var confMan = null; var confMan = null;
var $display = $("#display");
var verto; var verto;
var ringing = false; var ringing = false;
var autocall = false; var autocall = false;
var chatting_with = false;
$( ".selector" ).pagecontainer({ "theme": "a" }); $( ".selector" ).pagecontainer({ "theme": "a" });
@ -19,6 +19,8 @@ function clearConfMan() {
} }
$("#conf").hide(); $("#conf").hide();
$("#message").hide();
chatting_with = null;
} }
function goto_dialog(where) { function goto_dialog(where) {
@ -37,9 +39,6 @@ function online(on) {
$("#offline").hide(); $("#offline").hide();
first_login = true; first_login = true;
} else { } else {
if (first_login && online_visible) {
goto_dialog("logout");
}
$("#online").hide(); $("#online").hide();
$("#offline").show(); $("#offline").show();
@ -48,6 +47,26 @@ function online(on) {
online_visible = 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() { function check_vid() {
var use_vid = $("#use_vid").is(':checked'); var use_vid = $("#use_vid").is(':checked');
return use_vid; return use_vid;
@ -59,7 +78,7 @@ var callbacks = {
switch (msg) { switch (msg) {
case $.verto.enum.message.pvtEvent: case $.verto.enum.message.pvtEvent:
//console.error("pvtEvent", data.pvtData.action); // console.error("pvtEvent", data.pvtData);
if (data.pvtData) { if (data.pvtData) {
switch (data.pvtData.action) { switch (data.pvtData.action) {
@ -79,13 +98,22 @@ var callbacks = {
}); });
$("#conf").show(); $("#conf").show();
$("#chatwin").html("");
$("#message").show();
chatting_with = data.pvtData.chatID;
break; break;
} }
} }
break; break;
case $.verto.enum.message.info: case $.verto.enum.message.info:
$("#text").html("Message from: <b>" + data.from + "</b>:<br>" + "<pre>" + data.body + "</pre>"); 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("<b>" + data.from + "</b>:<br>" + "" + body + "" + "<br>");
$('#chatwin').animate({"scrollTop": $('#chatwin')[0].scrollHeight}, "fast");
break; break;
case $.verto.enum.message.display: case $.verto.enum.message.display:
var party = dialog.params.remote_caller_id_name + "<" + dialog.params.remote_caller_id_number + ">"; var party = dialog.params.remote_caller_id_name + "<" + dialog.params.remote_caller_id_number + ">";
@ -153,10 +181,11 @@ var callbacks = {
break; break;
case $.verto.enum.state.hangup: case $.verto.enum.state.hangup:
$("#main_info").html("Call ended with cause: " + d.cause); $("#main_info").html("Call ended with cause: " + d.cause);
goto_page("main");
case $.verto.enum.state.destroy: case $.verto.enum.state.destroy:
$("#hangup_cause").html(""); $("#hangup_cause").html("");
clearConfMan(); clearConfMan();
goto_page("main");
cur_call = null; cur_call = null;
break; break;
case $.verto.enum.state.held: case $.verto.enum.state.held:
@ -382,6 +411,9 @@ function init() {
$("#webcam").hide(); $("#webcam").hide();
online(false); online(false);
setupChat();
} }
$(document).ready(function() { $(document).ready(function() {
@ -418,6 +450,9 @@ $(document).bind("pagecontainerchange", function(e, data) {
break; break;
case "#page-main": case "#page-main":
if (cur_call) {
goto_page("incall");
}
break; break;
case "#page-login": case "#page-login":

View File

@ -282,7 +282,7 @@
self._ws_socket.onmessage = onmessage_cb; self._ws_socket.onmessage = onmessage_cb;
self._ws_socket.onclose = function (w) { self._ws_socket.onclose = function (w) {
if (!self.ws_sleep) { if (!self.ws_sleep) {
self.ws_sleep = 500; self.ws_sleep = 1000;
} }
if (self.options.onWSClose) { if (self.options.onWSClose) {
@ -298,8 +298,8 @@
self.ws_cnt++; self.ws_cnt++;
if (self.ws_sleep < 3000 && (self.ws_cnt % 100) == 0) { if (self.ws_sleep < 3000 && (self.ws_cnt % 10) == 0) {
self.ws_sleep += 500; self.ws_sleep += 1000;
} }
} }
@ -308,7 +308,7 @@
if (self.to) { if (self.to) {
clearTimeout(self.to); clearTimeout(self.to);
} }
self.ws_sleep = 500; self.ws_sleep = 1000;
self.ws_cnt = 0; self.ws_cnt = 0;
if (self.options.onWSConnect) { if (self.options.onWSConnect) {
self.options.onWSConnect(self); self.options.onWSConnect(self);

View File

@ -460,6 +460,8 @@
} }
dialog = new $.verto.dialog($.verto.enum.direction.inbound, verto, data.params); dialog = new $.verto.dialog($.verto.enum.direction.inbound, verto, data.params);
dialog.setState($.verto.enum.state.recovering);
break; break;
case 'verto.invite': case 'verto.invite':
@ -533,7 +535,7 @@
if (verto.callbacks.onMessage) { if (verto.callbacks.onMessage) {
verto.callbacks.onMessage(verto, null, $.verto.enum.message.info, data.params.msg); 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); console.debug("MESSAGE from: " + data.params.msg.from, data.params.msg.body);
break; break;
@ -1389,7 +1391,8 @@
dialog.params = $.extend({ dialog.params = $.extend({
useVideo: verto.options.useVideo, useVideo: verto.options.useVideo,
useStereo: verto.options.useStereo, useStereo: verto.options.useStereo,
tag: verto.options.tag tag: verto.options.tag,
login: verto.options.login
}, },
params); params);
@ -1567,6 +1570,13 @@
} }
switch (dialog.state) { 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: case $.verto.enum.state.purge:
dialog.setState($.verto.enum.state.destroy); dialog.setState($.verto.enum.state.destroy);
break; break;
@ -1760,6 +1770,8 @@
var dialog = this; var dialog = this;
var err = 0; var err = 0;
msg.from = dialog.params.login;
if (!msg.to) { if (!msg.to) {
console.error("Missing To"); console.error("Missing To");
err++; err++;
@ -1885,6 +1897,7 @@
$.verto.enum.states = Object.freeze({ $.verto.enum.states = Object.freeze({
new: { new: {
requesting: 1, requesting: 1,
recovering: 1,
ringing: 1, ringing: 1,
destroy: 1, destroy: 1,
answering: 1 answering: 1
@ -1893,6 +1906,10 @@
trying: 1, trying: 1,
hangup: 1 hangup: 1
}, },
recovering: {
answering: 1,
hangup: 1
},
trying: { trying: {
active: 1, active: 1,
early: 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.direction = $.verto.ENUM("inbound outbound");
$.verto.enum.message = $.verto.ENUM("display info pvtEvent"); $.verto.enum.message = $.verto.ENUM("display info pvtEvent");

View File

@ -381,6 +381,7 @@ typedef struct conference_obj {
char *bad_pin_sound; char *bad_pin_sound;
char *profile_name; char *profile_name;
char *domain; char *domain;
char *chat_id;
char *caller_controls; char *caller_controls;
char *moderator_controls; char *moderator_controls;
switch_live_array_t *la; 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, "laChannel", cJSON_CreateString(conference->la_event_channel));
cJSON_AddItemToObject(data, "laName", cJSON_CreateString(conference->la_name)); 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, "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)) { if (switch_test_flag(member, MFLAG_MOD)) {
cJSON_AddItemToObject(data, "modChannel", cJSON_CreateString(conference->mod_event_channel)); 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 *from = switch_event_get_header(event, "from");
char *to = switch_event_get_header(event, "to"); char *to = switch_event_get_header(event, "to");
char *body = switch_event_get_body(event); char *body = switch_event_get_body(event);
if (to && from && body) { if (to && from && body) {
if (strchr(to, '+') && strncmp(to, CONF_CHAT_PROTO, strlen(CONF_CHAT_PROTO))) { if (strchr(to, '+') && strncmp(to, CONF_CHAT_PROTO, strlen(CONF_CHAT_PROTO))) {
switch_event_del_header(event, "to"); 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 */ /* 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; 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(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); switch_mutex_lock(conference->member_mutex);
for (member = conference->members; member; member = member->next) { for (member = conference->members; member; member = member->next) {
if (member->session && !switch_test_flag(member, MFLAG_NOCHANNEL)) { 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_chat_deliver(chat_proto, &reply);
switch_core_session_receive_message(lsession, &msg); }
} }
} }
switch_mutex_unlock(conference->member_mutex); 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 *body;
//const char *type; //const char *type;
const char *hint; const char *hint;
const char *ouuid;
proto = switch_event_get_header(message_event, "proto"); proto = switch_event_get_header(message_event, "proto");
from = switch_event_get_header(message_event, "from"); from = switch_event_get_header(message_event, "from");
to = switch_event_get_header(message_event, "to"); to = switch_event_get_header(message_event, "to");
//subject = switch_event_get_header(message_event, "subject");
body = switch_event_get_body(message_event); body = switch_event_get_body(message_event);
//type = switch_event_get_header(message_event, "type");
hint = switch_event_get_header(message_event, "hint"); hint = switch_event_get_header(message_event, "hint");
ouuid = switch_event_get_header(message_event, "Channel-Call-UUID");
if ((p = strchr(to, '+'))) { if ((p = strchr(to, '+'))) {
to = ++p; to = ++p;
@ -9788,7 +9785,7 @@ static switch_status_t chat_send(switch_event_t *message_event)
if (body != NULL && (lbuf = strdup(body))) { if (body != NULL && (lbuf = strdup(body))) {
/* special case list */ /* special case list */
if (conference->broadcast_chat_messages) { 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)) { } else if (switch_stristr("list", lbuf)) {
conference_list_pretty(conference, &stream); conference_list_pretty(conference, &stream);
/* provide help */ /* 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; char *maxmember_sound = NULL;
uint32_t rate = 8000, interval = 20; uint32_t rate = 8000, interval = 20;
uint32_t channels = 1; uint32_t channels = 1;
int broadcast_chat_messages = 0; int broadcast_chat_messages = 1;
int comfort_noise_level = 0; int comfort_noise_level = 0;
int pin_retries = 3; int pin_retries = 3;
int ivr_dtmf_timeout = 500; 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)) { } else if (!strcasecmp(var, "moderator-controls") && !zstr(val)) {
moderator_controls = val; moderator_controls = val;
} else if (!strcasecmp(var, "broadcast-chat-messages") && !zstr(val) && switch_true(val)) { } else if (!strcasecmp(var, "broadcast-chat-messages") && !zstr(val)) {
broadcast_chat_messages = 1; broadcast_chat_messages = switch_true(val);
} else if (!strcasecmp(var, "comfort-noise") && !zstr(val)) { } else if (!strcasecmp(var, "comfort-noise") && !zstr(val)) {
int tmp; int tmp;
tmp = atoi(val); 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->domain = "cluecon.com";
} }
conference->chat_id = switch_core_sprintf(conference->pool, "conf+%s@%s", conference->name, conference->domain);
conference->channels = channels; conference->channels = channels;
conference->rate = rate; conference->rate = rate;
conference->interval = interval; conference->interval = interval;

View File

@ -588,6 +588,11 @@ static switch_status_t jsock_queue_event(jsock_t *jsock, cJSON **json)
return status; 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) 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++)); cJSON_AddItemToObject(params, "eventSerno", cJSON_CreateNumber(np->serno++));
msg = jrpc_new_req("verto.event", NULL, &params); msg = jrpc_new_req("verto.event", NULL, &params);
//ws_write_json(np->jsock, &msg, SWITCH_TRUE); //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); params = cJSON_Duplicate(event, 1);
msg = jrpc_new_req("verto.event", NULL, &params); msg = jrpc_new_req("verto.event", NULL, &params);
//ws_write_json(use_jsock, &msg, SWITCH_TRUE); //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); switch_thread_rwlock_unlock(use_jsock->rwlock);
use_jsock = NULL; use_jsock = NULL;
return; 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"); 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; *code = CODE_AUTH_FAILED;
switch_snprintf(message, mlen, "Login Incorrect"); switch_snprintf(message, mlen, "Login Incorrect");
} else { } 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->domain = switch_core_strdup(jsock->pool, domain);
jsock->uid = switch_core_sprintf(jsock->pool, "%s@%s", id, 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"))) { 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) { 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); switch_event_destroy(&req_params);
} }
if (jsock->profile->blind_reg) {
r = SWITCH_TRUE;
}
end: end:
return r; 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, "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); switch_channel_set_variable(tech_pvt->channel, "verto_host", jsock->domain);
if ((var = switch_event_get_header(jsock->params, "caller-id-name"))) { 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_name", cJSON_CreateString(name));
cJSON_AddItemToObject(params, "display_number", cJSON_CreateString(number)); cJSON_AddItemToObject(params, "display_number", cJSON_CreateString(number));
//ws_write_json(jsock, &jmsg, SWITCH_TRUE); //ws_write_json(jsock, &jmsg, SWITCH_TRUE);
jsock_queue_event(jsock, &jmsg); jsock_queue_event_clone(jsock, jmsg);
} }
switch_thread_rwlock_unlock(jsock->rwlock); 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"))) { if ((msg = cJSON_GetObjectItem(params, "msg"))) {
switch_event_t *event; switch_event_t *event;
char *to = (char *) cJSON_GetObjectCstr(msg, "to"); char *to = (char *) cJSON_GetObjectCstr(msg, "to");
//char *from = (char *) cJSON_GetObjectCstr(msg, "from");
cJSON *indialog = cJSON_GetObjectItem(msg, "inDialog"); cJSON *indialog = cJSON_GetObjectItem(msg, "inDialog");
const char *body = cJSON_GetObjectCstr(msg, "body"); 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 (!zstr(to)) {
if (strchr(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) { 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, "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", 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_user", jsock->id);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_host", jsock->domain); 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_profile", jsock->profile->name);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "verto_jsock_uuid", jsock->uuid_str); 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); 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(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 { } else {
r = SWITCH_FALSE; 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_name(channel, name);
switch_channel_set_variable(channel, "jsock_uuid_str", jsock->uuid_str); 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, "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, "verto_host", jsock->domain);
switch_channel_set_variable(channel, "event_channel_cookie", tech_pvt->jsock_uuid); switch_channel_set_variable(channel, "event_channel_cookie", tech_pvt->jsock_uuid);
switch_channel_set_variable(channel, "verto_profile_name", jsock->profile->name); 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; jsock_t *jsock;
if ((jsock = get_jsock(tech_pvt->jsock_uuid))) { 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) { //if (ws_write_json(jsock, &msg, SWITCH_FALSE) <= 0) {
// switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); // 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) { for(jsock = profile->jsock_head; jsock; jsock = jsock->next) {
if (!strcmp(uid, jsock->uid)) { if (!strcmp(uid, jsock->uid)) {
//ws_write_json(jsock, &msg, SWITCH_FALSE); //ws_write_json(jsock, &msg, SWITCH_FALSE);
jsock_queue_event(jsock, &msg); jsock_queue_event_clone(jsock, msg);
hits++; hits++;
} }
} }

View File

@ -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); switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "proto", proto);
} }
replying = switch_event_get_header(message_event, "replying"); 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"))) { 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); switch_mutex_lock(loadable_modules.mutex);
for (hi = switch_core_hash_first(loadable_modules.chat_hash); hi; hi = switch_core_hash_next(&hi)) { 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); switch_mutex_unlock(loadable_modules.mutex);
} }
if (!do_skip && !switch_stristr("GLOBAL", dest_proto)) { if (!do_skip && !switch_stristr("GLOBAL", dest_proto)) {
if ((ci = switch_loadable_module_get_chat_interface(dest_proto)) && ci->chat_send) { if ((ci = switch_loadable_module_get_chat_interface(dest_proto)) && ci->chat_send) {
status = ci->chat_send(message_event); status = ci->chat_send(message_event);