| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- if (typeof console == "undefined") {
- this.console = {
- log: function(msg) {}
- };
- }
- // 如果浏览器不支持websocket,会使用这个flash自动模拟websocket协议,此过程对开发者透明
- WEB_SOCKET_SWF_LOCATION = "./js/websocket/WebSocketMain.swf";
- // 开启flash的websocket debug
- WEB_SOCKET_DEBUG = true;
- var ws, n = 0,
- timer;
- var lockReconnect = false; //避免重复连接
- var obj = {};
- var Statess;
- var cls = 0;
- var webData;
- var dataLength;
- let callDate = [];
- var lasttime = new Date().getTime();
- //坐席分析
- agentCount();
- setInterval(function(){
- agentCount();
- },120000)
- //坐席数量
- function agentCount(){
- $.ajax({
- url: huayi.config.callcenter_url + "SeatMonitoring/getlist",
- data: {},
- async: false,
- dataType:'json',
- success: function(res) {
- dataLength=res.data.length;
- }
- })
- }
- Connect()
- //创建scoket连接
- function createWebSocket() {
- try {
- Connect();
- } catch (e) {
- reconnect();
- }
- }
- //连接
- function Connect() {
- // debugger
- ws = new WebSocket("ws://" + huayi.config.socket_ip + ":" + huayi.config.socket_port);
- ws.onopen = function() {
- console.log(new Date() + " " + "建立连接");
- //心跳检测重置
- heartCheck.reset().start();
- cls = 0;
- $(".Login").addClass("active");
- lasttime = new Date().getTime();
- // debugger
- //话务坐席情况
- obj = {
- "Type": 'GetAgentDetail', //话后处理时长设置,0代表一致话后处理,除非发送置闲 (按照历史习惯,字符串形式)
- };
- Send();
- };
- //接收到消息的回调方法
- ws.onmessage = function(evt) {
- //如果获取到消息,心跳检测重置
- //拿到任何消息都说明当前连接是正常的
- heartCheck.reset().start();
- var myDate = new Date();
- webData = JSON.parse(evt.data)[0];
- if(webData.Type=='GetAgentDetail'){
- const outLine=dataLength - webData.AgentOnlineCount;
- callDate = [dataLength, webData.AgentOnlineCount, webData.AgentSpeakCount, webData
- .AgentProcessingCount, webData.AgentReposeCount, webData.AgentFreeCount, outLine
- ]
- chart1(callDate);
-
- }
- }
- };
- //连接关闭的回调方法
- ws.onclose = function(evt) {
- if (cls == 0) {
- cls = 1;
- //console.log("连接关闭!");
- //layer.confirm('连接关闭!', {
- // btn: ['确定']
- //});
- $(".hwzt").text('连接关闭!');
- $("#top-search li i").removeClass("active");
- reconnect();
- }
- };
- //连接发生错误的回调方法
- ws.onerror = function(evt) {
- //产生异常
- $(".hwzt").text('连接出现异常!');
- console.log(ws);
- if (ws == null || ws.readyState != ws.OPEN) {
- console.log(new Date() + "开始重连");
- reconnect();
- }
- };
- //}
- //重连
- function reconnect() {
- if (lockReconnect) return;
- lockReconnect = true;
- //没连接上会一直重连,设置延迟避免请求过多
- setTimeout(function() {
- console.log(new Date() + " " + "重连中……");
- createWebSocket("ws://" + huayi.config.socket_ip + ":" + huayi.config.socket_port);
- lockReconnect = false;
- }, 2000);
- }
- //发送
- function Send() {
- if (ws.readyState != ws.OPEN) {
- reconnect();
- }
- if (ws.readyState == ws.OPEN) {
- console.log(new Date() + " send " + JSON.stringify(obj));
- ws.send(JSON.stringify(obj));
- }
- }
- //心跳检测
- var heartCheck = {
- timeout: 25000, //25秒
- timeoutObj: null,
- serverTimeoutObj: null,
- reset: function() {
- clearTimeout(this.timeoutObj);
- clearTimeout(this.serverTimeoutObj);
- return this;
- },
- start: function() {
- var self = this;
- this.timeoutObj = setTimeout(function() {
- //这里发送一个心跳,后端收到后,返回一个心跳消息,
- //onmessage拿到返回的心跳就说明连接正常
- obj.Type = "Heart";
- Send();
- self.serverTimeoutObj = setTimeout(function() { //如果超过一定时间还没重置,说明后端主动断开了
- ws
- .close(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
- }, self.timeout)
- }, this.timeout)
- }
- }
- function toDub(i) {
- return i < 10 ? "0" + i : "" + i;
- }
- //默认记忆上次是否签入,是否置忙置闲 0表示已签入 空闲,1表示签入置忙,2表示签出
- function SetStateCookie(state) {
- $.cookie("socket_state", state);
- }
- function backstageQueue(data) {
- console.log("123")
- var obj = $("iframe:visible")
- // if (obj.attr("data-id") == "index_v1.html") {
- window.frames[obj.attr("name")].realTimeMonitorQueue(data.WaitCount);
- // }
- }
- //在线坐席信息
- function GetAgentListBack(data) {
- console.log(data)
- $.ajax({
- type: "get",
- url: huayi.config.callcenter_url + "SeatMonitoring/GetAgentList",
- async: true,
- dataType: 'json',
- data: {
- "token": $.cookie("token")
- },
- success: function(result) {
- var user = result.data;
- $(user).each(function(j, m) {
- $(data.AgentList).each(function(k, g) {
- if (g.AgentID == m.UserCode) {
- g.userName = m.UserName;
- }
- })
- })
- $(data.AgentList).each(function(k, m) {
- var strr = '';
- switch (m.State) {
- case "0":
- strr = "离线";
- break; //离线
- case "1":
- break; //登录中
- case "2":
- strr = "空闲";
- break; //空闲
- case "3":
- strr = "通话中";
- break; //通话中
- case "4":
- strr = "话后处理中";
- break; //话后处理中
- case "5":
- strr = "忙碌";
- break; //小休
- case "6":
- strr = "振铃";
- break; //被请求
- case "7":
- strr = "注销";
- break; //注销
- }
- var html = '<tr fjh="' + m.AgentExten + '">' +
- '<td>' + (m.userName ? '' : m.userName) + '</td>' //姓名
- +
- '<td>' + m.AgentID + '</td>' //工号
- +
- '<td>' + m.AgentExten + '</td>' //分机号
- +
- '<td class=" ' + m.UserCode + 'state">' + strr + '</td>' //状态
- +
- '</tr>';
- $(html).appendTo("#zxTable tbody");
- })
- }
- });
- }
- //获取当前的日期时间 格式“yyyy-MM-dd HH:mm:ss”
- function getNowFormatDate() {
- var date = new Date();
- var seperator1 = "-";
- var seperator2 = ":";
- var month = date.getMonth() + 1;
- var strDate = date.getDate();
- if (month >= 1 && month <= 9) {
- month = "0" + month;
- }
- if (strDate >= 0 && strDate <= 9) {
- strDate = "0" + strDate;
- }
- var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
- " " + date.getHours() + seperator2 + date.getMinutes() +
- seperator2 + date.getSeconds();
- return currentdate;
- }
- var iswebcloase = 1;
- window.onunload = function() {
- if (iswebcloase) {
- iswebcloase = 0;
- if (ws.readyState == ws.OPEN) {
- obj.Type = 'Logout';
- Send();
- ws.onclose();
- }
- }
- }
- window.onbeforeunload = function() {
- if (iswebcloase) {
- iswebcloase = 0;
- if (ws.readyState == ws.OPEN) {
- obj.Type = 'Logout';
- Send();
- ws.onclose();
- }
- }
- }
|