var ws; //--------------------------------��������websocket-----------------------------------------// function initwebsocket(cti_ws_url) { if ('WebSocket' in window) { ws = new WebSocket(cti_ws_url); } else { alert("do not suports websocket"); } ws.onopen = function(evt) { alert("open websocket success"); } ws.onclose = function(evt) { alert("websocket close"); } //�������� ws.onmessage = function(evt) { var reader = new FileReader(); reader.onloadend = function(e) { console.log(this.result); var msgdiv = document.getElementById("msg"); var span = document.createElement("span"); span.innerHTML = "receive_msg:"+this.result + "
"; msgdiv.appendChild(span); var obj = eval('(' + this.result + ')'); if(obj.cmd=="system"&&obj.action=="keepalive"){ keepalive(obj.seatname,obj.seatnum); } var uuid = document.getElementById("uuid"); if(obj.cmd=="control"&&obj.action=="tp_callin"){ uuid.value=obj.uuid; } }; reader.readAsText(event.data); } ws.onerror = function(evt) { alert("websocket error"); } } function sendmessage(protocolStr){ console.log(); var msgdiv = document.getElementById("msg"); var span = document.createElement("span"); span.innerHTML = "send_msg:"+protocolStr + "
"; msgdiv.appendChild(span); ws.send(protocolStr); } function testclear(){ var msgdiv = document.getElementById("msg"); msgdiv.innerHTML=""; } //--------------------------------command send-----------------------------------------// //��ϯǩ�� function seatlogin(seatname,seatnum,password,cti_ws_url) { if ('WebSocket' in window) { ws = new WebSocket(cti_ws_url); } else { alert("do not suports websocket"); } ws.onopen = function(evt) { alert("open websocket success"); if(seatname=="") { alert("seatname is null"); return; } if(seatnum=="") { alert("seatnum is null"); return; } var protocol={"cmd":"system","action":"seatlogin","seatname":"","seatnum":"","password":"","timestamp":""}; protocol.seatname=seatname; protocol.seatnum=seatnum; protocol.password=password; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); } ws.onclose = function(evt) { alert("websocket close"); } //�������� ws.onmessage = function(evt) { var reader = new FileReader(); reader.onloadend = function(e) { console.log(this.result); var msgdiv = document.getElementById("msg"); var span = document.createElement("span"); span.innerHTML = "receive_msg:"+this.result + "
"; msgdiv.appendChild(span); var obj = eval('(' + this.result + ')'); if(obj.cmd=="system"&&obj.action=="keepalive"){ keepalive(obj.seatname,obj.seatnum); } var uuid = document.getElementById("uuid"); if(obj.cmd=="control"&&obj.action=="tp_callin"){ uuid.value=obj.uuid; } }; reader.readAsText(event.data); } ws.onerror = function(evt) { alert("websocket error"); } //ws.send(protocolStr); } //��ϯǩ�� function seatlogout(seatname,seatnum) { if(seatname=="") { alert("seatname is null"); return; } if(seatnum=="") { alert("seatnum is null"); return; } var protocol={"cmd":"system","action":"seatlogout","seatname":"","seatnum":"","timestamp":""}; protocol.seatname=seatname; protocol.seatnum=seatnum; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); ws.close(); } //���� function afk(seatname,seatnum) { if(seatname=="") { alert("seatname is null"); return; } if(seatnum=="") { alert("seatnum is null"); return; } var protocol={"cmd":"system","action":"afk","seatname":"","seatnum":"","timestamp":""}; protocol.seatname=seatname; protocol.seatnum=seatnum; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //���� function online(seatname,seatnum) { if(seatname=="") { alert("seatname is null"); return; } if(seatnum=="") { alert("seatnum is null"); return; } var protocol={"cmd":"system","action":"online","seatname":"","seatnum":"","timestamp":""}; protocol.seatname=seatname; protocol.seatnum=seatnum; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //��� function callout(seatname,seatnum,phone) { if(seatnum=="") { alert("seatnum is null"); return; } if(phone=="") { alert("phone is null"); return; } var protocol={"cmd":"control","action":"callout","phone":"","seatname":"","seatnum":"","timestamp":""}; protocol.phone=phone; protocol.seatname=seatname; protocol.seatnum=seatnum; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //ת�� function transfer(seatname,seatnum,phone,uuid) { if(seatnum=="") { alert("seatnum is null"); return; } if(phone=="") { alert("phone is null"); return; } if(uuid=="") { alert("uuid is null"); return; } var protocol={"cmd":"control","action":"transfer","uuid":"","phone":"","seatname":"","seatnum":"","timestamp":""}; protocol.phone=phone; protocol.seatname=seatname; protocol.seatnum=seatnum; protocol.uuid=uuid; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //ת���ջ� function transferresume(seatname,seatnum,phone,uuid) { if(seatnum=="") { alert("seatnum is null"); return; } if(phone=="") { alert("phone is null"); return; } if(uuid=="") { alert("uuid is null"); return; } var protocol={"cmd":"control","action":"transferresume","uuid":"","phone":"","seatname":"","seatnum":"","timestamp":""}; protocol.phone=phone; protocol.seatname=seatname; protocol.seatnum=seatnum; protocol.uuid=uuid; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //ͨ������ function hold(seatname,seatnum,uuid) { if(seatnum=="") { alert("seatnum is null"); return; } if(uuid=="") { alert("uuid is null"); return; } var protocol={"cmd":"control","action":"hold","uuid":"","seatname":"","seatnum":"","timestamp":""}; protocol.uuid=uuid; protocol.seatname=seatname; protocol.seatnum=seatnum; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //ͨ�������ջ� function holdresume(seatname,seatnum,uuid) { if(seatnum=="") { alert("seatnum is null"); return; } if(uuid=="") { alert("uuid is null"); return; } var protocol={"cmd":"control","action":"holdresume","uuid":"","seatname":"","seatnum":"","timestamp":""}; protocol.uuid=uuid; protocol.seatname=seatname; protocol.seatnum=seatnum; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //���� function pickup(seatname,seatnum) { if(seatnum=="") { alert("seatnum is null"); return; } var protocol={"cmd":"control","action":"pickup","seatname":"","seatnum":"","timestamp":""}; protocol.seatnum=seatnum; protocol.seatname=seatname; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //�Ҷ� function hangup(seatname,seatnum) { if(seatnum=="") { alert("seatnum is null"); return; } var protocol={"cmd":"control","action":"hangup","seatname":"","seatnum":"","timestamp":""}; protocol.seatnum=seatnum; protocol.seatname=seatname; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //ͨ��ǿ�� function remove(seatname,seatnum,phone) { if(seatnum=="") { alert("seatnum is null"); return; } if(phone=="") { alert("phone is null"); return; } var protocol={"cmd":"control","action":"remove","phone":"","seatname":"","seatnum":"","timestamp":""}; protocol.phone=phone; protocol.seatname=seatname; protocol.seatnum=seatnum; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //ͨ��ǿ�� function insert(seatname,seatnum,phone) { if(seatnum=="") { alert("seatnum is null"); return; } if(phone=="") { alert("phone is null"); return; } var protocol={"cmd":"control","action":"insert","phone":"","seatname":"","seatnum":"","timestamp":""}; protocol.phone=phone; protocol.seatname=seatname; protocol.seatnum=seatnum; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //���� function monitor(seatname,seatnum,phone) { if(seatnum=="") { alert("seatnum is null"); return; } if(phone=="") { alert("phone is null"); return; } var protocol={"cmd":"control","action":"monitor","phone":"","seatname":"","seatnum":"","timestamp":""}; protocol.phone=phone; protocol.seatname=seatname; protocol.seatnum=seatnum; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //����תͨ�� function monitor_to_talk(seatname,seatnum,phone) { if(seatnum=="") { alert("seatnum is null"); return; } if(phone=="") { alert("phone is null"); return; } var protocol={"cmd":"control","action":"monitor_to_talk","phone":"","seatname":"","seatnum":"","timestamp":""}; protocol.phone=phone; protocol.seatname=seatname; protocol.seatnum=seatnum; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //�������� function monitor_end(seatname,seatnum,phone) { if(seatnum=="") { alert("seatnum is null"); return; } if(phone=="") { alert("phone is null"); return; } var protocol={"cmd":"control","action":"monitor_end","phone":"","seatname":"","seatnum":"","timestamp":""}; protocol.phone=phone; protocol.seatname=seatname; protocol.seatnum=seatnum; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //ѡ�� function choosecall(seatname,seatnum,uuid) { if(seatnum=="") { alert("seatnum is null"); return; } if(uuid=="") { alert("uuid is null"); return; } var protocol={"cmd":"control","action":"choosecall","uuid":"","seatname":"","seatnum":"","timestamp":""}; protocol.uuid=uuid; protocol.seatname=seatname; protocol.seatnum=seatnum; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //���� function replacecall(seatname,seatnum,phone) { if(seatnum=="") { alert("seatnum is null"); return; } if(phone=="") { alert("phone is null"); return; } var protocol={"cmd":"control","action":"replacecall","phone":"","seatname":"","seatnum":"","timestamp":""}; protocol.phone=phone; protocol.seatname=seatname; protocol.seatnum=seatnum; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //����ͨ�� function three(seatname,seatnum,phone) { if(seatnum=="") { alert("seatnum is null"); return; } if(phone=="") { alert("phone is null"); return; } var protocol={"cmd":"control","action":"three","phone":"","seatname":"","seatnum":"","timestamp":""}; protocol.phone=phone; protocol.seatname=seatname; protocol.seatnum=seatnum; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //������ϯ״̬ function openseatlist(seatname,seatnum) { if(seatnum=="") { alert("seatnum is null"); return; } var protocol={"cmd":"status","action":"openseatlist","seatname":"","seatnum":"","timestamp":""}; protocol.seatnum=seatnum; protocol.seatname=seatname; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //�ر���ϯ״̬ function closeseatlist(seatname,seatnum) { if(seatnum=="") { alert("seatnum is null"); return; } var protocol={"cmd":"status","action":"closeseatlist","seatname":"","seatnum":"","timestamp":""}; protocol.seatnum=seatnum; protocol.seatname=seatname; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //�����Ŷ���Ϣ function openqueues(seatname,seatnum) { if(seatnum=="") { alert("seatnum is null"); return; } var protocol={"cmd":"status","action":"openqueues","seatname":"","seatnum":"","timestamp":""}; protocol.seatnum=seatnum; protocol.seatname=seatname; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //�ر��Ŷ���Ϣ function closequeues(seatname,seatnum) { if(seatnum=="") { alert("seatnum is null"); return; } var protocol={"cmd":"status","action":"closequeues","seatname":"","seatnum":"","timestamp":""}; protocol.seatnum=seatnum; protocol.seatname=seatname; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //����ͨ����Ϣ function opencalllist(seatname,seatnum) { if(seatnum=="") { alert("seatnum is null"); return; } var protocol={"cmd":"status","action":"opencalllist","seatname":"","seatnum":"","timestamp":""}; protocol.seatnum=seatnum; protocol.seatname=seatname; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //�ر�ͨ����Ϣ function closecalllist(seatname,seatnum) { if(seatnum=="") { alert("seatnum is null"); return; } var protocol={"cmd":"status","action":"closecalllist","seatname":"","seatnum":"","timestamp":""}; protocol.seatnum=seatnum; protocol.seatname=seatname; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //�����м���Ϣ function openroutelist(seatname,seatnum) { if(seatnum=="") { alert("seatnum is null"); return; } var protocol={"cmd":"status","action":"openroutelist","seatname":"","seatnum":"","timestamp":""}; protocol.seatnum=seatnum; protocol.seatname=seatname; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //�ر��м���Ϣ function closeroutelist(seatname,seatnum) { if(seatnum=="") { alert("seatnum is null"); return; } var protocol={"cmd":"status","action":"closeroutelist","seatname":"","seatnum":"","timestamp":""}; protocol.seatnum=seatnum; protocol.seatname=seatname; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //��ȡ��ϯ��Ϣ function seatlist(group) { if(group=="") { alert("group is null"); return; } var protocol={"cmd":"status","action":"seatlist","group":"","timestamp":""}; protocol.group=group; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //��ȡ�Ŷ���Ϣ function queues() { var protocol={"cmd":"status","action":"queues","timestamp":""}; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //��ȡͨ����Ϣ function calllist() { var protocol={"cmd":"status","action":"calllist","timestamp":""}; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //��ȡ�м���Ϣ function routelist() { var protocol={"cmd":"status","action":"routelist","timestamp":""}; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //��ȡ�������������Ϣ function batch(paramid) { if(paramid=="") { alert("paramid is null"); return; } var protocol={"cmd":"status","action":"batch","paramid":"","timestamp":""}; protocol.paramid=paramid; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //��ʼ������� function batch_start(seatname,seatnum) { if(seatnum=="") { alert("seatnum is null"); return; } var protocol={"cmd":"system","action":"batch_start","seatname":"","seatnum":"","timestamp":""}; protocol.seatnum=seatnum; protocol.seatname=seatname; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //�ر�������� function batch_stop(seatname,seatnum) { if(seatnum=="") { alert("seatnum is null"); return; } var protocol={"cmd":"system","action":"batch_stop","seatname":"","seatnum":"","timestamp":""}; protocol.seatnum=seatnum; protocol.seatname=seatname; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //ͨ����ѯ��ʼ function handoff_ready(seatname,seatnum,uuid) { if(seatnum=="") { alert("seatnum is null"); return; } if(uuid=="") { alert("uuid is null"); return; } var protocol={"cmd":"control","action":"handoff_ready","uuid":"","seatname":"","seatnum":"","timestamp":""}; protocol.uuid=uuid; protocol.seatname=seatname; protocol.seatnum=seatnum; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //��ѯ function handoff_call(seatname,seatnum,phone,uuid) { if(seatnum=="") { alert("seatnum is null"); return; } if(phone=="") { alert("phone is null"); return; } if(uuid=="") { alert("uuid is null"); return; } var protocol={"cmd":"control","action":"handoff_call","uuid":"","phone":"","seatname":"","seatnum":"","timestamp":""}; protocol.phone=phone; protocol.seatname=seatname; protocol.seatnum=seatnum; protocol.uuid=uuid; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //��ѯ�ջ� function handoff_resume(seatname,seatnum,uuid) { if(seatnum=="") { alert("seatnum is null"); return; } if(uuid=="") { alert("uuid is null"); return; } var protocol={"cmd":"control","action":"handoff_resume","uuid":"","seatname":"","seatnum":"","timestamp":""}; protocol.seatname=seatname; protocol.seatnum=seatnum; protocol.uuid=uuid; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //��ѯת�� function handoff_transfer(seatname,seatnum,phone,uuid) { if(seatnum=="") { alert("seatnum is null"); return; } if(phone=="") { alert("phone is null"); return; } if(uuid=="") { alert("uuid is null"); return; } var protocol={"cmd":"control","action":"handoff_transfer","uuid":"","phone":"","seatname":"","seatnum":"","timestamp":""}; protocol.phone=phone; protocol.seatname=seatname; protocol.seatnum=seatnum; protocol.uuid=uuid; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //��ѯ���� function handoff_three(seatname,seatnum,uuid) { if(seatnum=="") { alert("seatnum is null"); return; } if(uuid=="") { alert("uuid is null"); return; } var protocol={"cmd":"control","action":"handoff_three","uuid":"","seatname":"","seatnum":"","timestamp":""}; protocol.seatname=seatname; protocol.seatnum=seatnum; protocol.uuid=uuid; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //���� function keepalive(seatname,seatnum) { if(seatnum=="") { alert("seatnum is null"); return; } var protocol={"cmd":"system","action":"keepalive","seatname":"","seatnum":"","timestamp":""}; protocol.seatnum=seatnum; protocol.seatname=seatname; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); } //ͨ������¼�� function record_start(seatname,seatnum,uuid) { if(seatnum=="") { alert("seatnum is null"); return; } if(uuid=="") { alert("uuid is null"); return; } var protocol={"cmd":"control","action":"record_start","uuid":"","seatname":"","seatnum":"","timestamp":""}; protocol.uuid=uuid; protocol.seatname=seatname; protocol.seatnum=seatnum; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //ͨ��ֹͣ¼�� function record_stop(seatname,seatnum,uuid) { if(seatnum=="") { alert("seatnum is null"); return; } if(uuid=="") { alert("uuid is null"); return; } var protocol={"cmd":"control","action":"record_stop","uuid":"","seatname":"","seatnum":"","timestamp":""}; protocol.uuid=uuid; protocol.seatname=seatname; protocol.seatnum=seatnum; var protocolStr=JSON.stringify(protocol); sendmessage(protocolStr); //ws.send(protocolStr); } //---------------------------------------------------------------------------------//