|
|
@@ -2,16 +2,9 @@
|
|
2
|
2
|
timer,hidTel,hidCallID,hidActionID;
|
|
3
|
3
|
var lockReconnect = false; //避免重复连接
|
|
4
|
4
|
var obj = {};
|
|
5
|
|
-var directType;
|
|
6
|
|
-var sendType;
|
|
7
|
|
-var mesCont;
|
|
8
|
|
-var eorrorConnect;
|
|
|
5
|
+
|
|
9
|
6
|
var cls = 0;
|
|
10
|
7
|
var lasttime = new Date().getTime();
|
|
11
|
|
-var errorState;
|
|
12
|
|
-var reconnecTion;
|
|
13
|
|
-var recon;
|
|
14
|
|
-var loginOr;
|
|
15
|
8
|
//创建scoket连接
|
|
16
|
9
|
function createWebSocket() {
|
|
17
|
10
|
try {
|
|
|
@@ -19,11 +12,6 @@ function createWebSocket() {
|
|
19
|
12
|
|
|
20
|
13
|
Connect();
|
|
21
|
14
|
} catch(e) {
|
|
22
|
|
- //打印日志
|
|
23
|
|
- directType="lianjie";
|
|
24
|
|
- sendType="异常错误"; //JSON.stringify(data)
|
|
25
|
|
- mesCont=e.message;
|
|
26
|
|
- debuggerLog();
|
|
27
|
15
|
reconnect();
|
|
28
|
16
|
}
|
|
29
|
17
|
}
|
|
|
@@ -39,24 +27,6 @@ function Connect() {
|
|
39
|
27
|
|
|
40
|
28
|
cls = 0;
|
|
41
|
29
|
$(".Login").addClass("active");
|
|
42
|
|
- if (errorState) {
|
|
43
|
|
- //自动签入
|
|
44
|
|
- lasttime = new Date().getTime();
|
|
45
|
|
- obj.Type = "Login";
|
|
46
|
|
- obj.AgentType = "0";
|
|
47
|
|
- Send();
|
|
48
|
|
- directType="recive";
|
|
49
|
|
- sendType="自动签入 "; //JSON.stringify(data)
|
|
50
|
|
- //mesCont=JSON.stringify(data);
|
|
51
|
|
- debuggerLog();
|
|
52
|
|
- clearInterval(timer);
|
|
53
|
|
- //loginOr=false;
|
|
54
|
|
- errorState=false;
|
|
55
|
|
- }else{
|
|
56
|
|
- //签入
|
|
57
|
|
- Send();
|
|
58
|
|
-
|
|
59
|
|
- }
|
|
60
|
30
|
//自动签入
|
|
61
|
31
|
//lasttime = new Date().getTime();
|
|
62
|
32
|
//obj.Type = "Login";
|
|
|
@@ -71,23 +41,12 @@ function Connect() {
|
|
71
|
41
|
var myDate = new Date();
|
|
72
|
42
|
console.log(myDate + " receive " + evt.data);
|
|
73
|
43
|
var data = JSON.parse(evt.data)[0];
|
|
74
|
|
- //打印日志
|
|
75
|
|
- directType="recive";
|
|
76
|
|
- sendType=data.Type; //JSON.stringify(data)
|
|
77
|
|
- mesCont=JSON.stringify(data);
|
|
78
|
|
- debuggerLog()
|
|
79
|
44
|
if(data) {
|
|
80
|
45
|
var rlt = data.Result;
|
|
81
|
46
|
if(rlt == true) {
|
|
82
|
47
|
clearInterval(timer);
|
|
83
|
48
|
$('title').text('安图生物呼叫中心管理系统');
|
|
84
|
49
|
var type = data.Type;
|
|
85
|
|
- if (eorrorConnect) {
|
|
86
|
|
- LoginBack();
|
|
87
|
|
- obj.Type = "Login";
|
|
88
|
|
- Send();
|
|
89
|
|
- eorrorConnect=false;
|
|
90
|
|
- }
|
|
91
|
50
|
switch(type.toLowerCase()) {
|
|
92
|
51
|
//case "heart": HeartBack(); break;//心跳
|
|
93
|
52
|
case "login":
|
|
|
@@ -143,6 +102,7 @@ function Connect() {
|
|
143
|
102
|
// case "agentstateagent":
|
|
144
|
103
|
// AgentStateAgentBack(data);
|
|
145
|
104
|
// break; //坐席状态通知
|
|
|
105
|
+
|
|
146
|
106
|
case "callid":
|
|
147
|
107
|
CallIDBack(data);
|
|
148
|
108
|
break; //获取callid
|
|
|
@@ -200,11 +160,6 @@ function Connect() {
|
|
200
|
160
|
};
|
|
201
|
161
|
//连接关闭的回调方法
|
|
202
|
162
|
ws.onclose = function(evt) {
|
|
203
|
|
- var data = JSON.parse(evt.data)[0];
|
|
204
|
|
- directType="recive";
|
|
205
|
|
- sendType="close"; //JSON.stringify(data)
|
|
206
|
|
- mesCont=JSON.stringify(data);
|
|
207
|
|
- debuggerLog();
|
|
208
|
163
|
if(cls == 0) {
|
|
209
|
164
|
cls = 1;
|
|
210
|
165
|
//console.log("连接关闭!");
|
|
|
@@ -216,11 +171,6 @@ function Connect() {
|
|
216
|
171
|
};
|
|
217
|
172
|
//连接发生错误的回调方法
|
|
218
|
173
|
ws.onerror = function(evt) {
|
|
219
|
|
- var data = JSON.parse(evt.data)[0];
|
|
220
|
|
- directType="recive";
|
|
221
|
|
- sendType="连接错误 "; //JSON.stringify(data)
|
|
222
|
|
- mesCont=JSON.stringify(data);
|
|
223
|
|
- debuggerLog();
|
|
224
|
174
|
//产生异常
|
|
225
|
175
|
$(".hwzt").text('连接出现异常!');
|
|
226
|
176
|
showMsgNotification('呼叫系统提示', '连接出现异常'); //暂时关闭
|
|
|
@@ -239,112 +189,17 @@ function reconnect() {
|
|
239
|
189
|
lockReconnect = true;
|
|
240
|
190
|
//没连接上会一直重连,设置延迟避免请求过多
|
|
241
|
191
|
setTimeout(function() {
|
|
242
|
|
- directType="send";
|
|
243
|
|
- sendType="重连中 "; //JSON.stringify(data)
|
|
244
|
|
- mesCont="重连中";
|
|
245
|
|
- debuggerLog();
|
|
246
|
192
|
console.log(new Date() + " " + "重连中……");
|
|
247
|
193
|
createWebSocket("ws://" + huayi.config.socket_ip + ":" + huayi.config.socket_port);
|
|
248
|
194
|
lockReconnect = false;
|
|
249
|
195
|
}, 2000);
|
|
250
|
196
|
}
|
|
251
|
|
-function debuggerLog(){
|
|
252
|
|
- $.post(huayi.config.callcenter_url + 'Log/CallOpt', {
|
|
253
|
|
- direct: directType,
|
|
254
|
|
- type: sendType,
|
|
255
|
|
- cont: mesCont,
|
|
256
|
|
- "token": $.cookie("token")
|
|
257
|
|
- }, function(result) {
|
|
258
|
|
- result = $.parseJSON(result);
|
|
259
|
|
- if(result.state.toLowerCase() == "warning") {
|
|
260
|
|
- //layer.msg("创建工单成功");
|
|
261
|
|
- }
|
|
262
|
|
- })
|
|
263
|
|
-}
|
|
264
|
|
-//异常重连
|
|
265
|
|
-function errorFun(){
|
|
266
|
|
- clearInterval(timer);
|
|
267
|
|
- var errorNum=0
|
|
268
|
|
- timer = setInterval(function() {
|
|
269
|
|
- errorNum++;
|
|
270
|
|
- if (errorNum>2) {
|
|
271
|
|
- //$("#top-search li i").removeClass("active");
|
|
272
|
|
- $(".hwzt").text('连接异常!');
|
|
273
|
|
- }else{
|
|
274
|
|
- LogoutBack();
|
|
275
|
|
- }
|
|
276
|
|
- reconnect();
|
|
277
|
|
- $(".hwzt").text('连接异常!');
|
|
278
|
|
- }, 15000);
|
|
279
|
|
-}
|
|
280
|
|
-noLine();
|
|
281
|
|
-clearInterval(recon);
|
|
282
|
|
-recon = setInterval(function () {
|
|
283
|
|
- if(loginOr){
|
|
284
|
|
- noLine();
|
|
285
|
|
- setTimeout(function () {
|
|
286
|
|
- lineState();
|
|
287
|
|
- }, 2000);
|
|
288
|
|
- }
|
|
289
|
|
-}, 1000*10);
|
|
290
|
|
-function lineState(){
|
|
291
|
|
- if (reconnecTion) {
|
|
292
|
|
- reconnecTion=false;
|
|
293
|
|
- }else{
|
|
294
|
|
- directType="send";
|
|
295
|
|
- sendType="断网 "; //JSON.stringify(data)
|
|
296
|
|
- mesCont="断网";
|
|
297
|
|
- debuggerLog();
|
|
298
|
|
- errorState=true;
|
|
299
|
|
- errorFun();
|
|
300
|
|
- var numEorr=0;
|
|
301
|
|
- numEorr++;
|
|
302
|
|
- if (numEorr>2) {
|
|
303
|
|
- $("#top-search li i").removeClass("active");
|
|
304
|
|
- }
|
|
305
|
|
- LogoutBack();
|
|
306
|
|
- $(".hwzt").text('网络异常!');
|
|
307
|
|
- }
|
|
308
|
|
-}
|
|
309
|
|
-function noLine(){
|
|
310
|
|
- $.ajax({
|
|
311
|
|
- type: "get",
|
|
312
|
|
- url: huayi.config.callcenter_url + 'UserAccount/GetNowUser',
|
|
313
|
|
- async: true,
|
|
314
|
|
- dataType: 'json',
|
|
315
|
|
- data: {
|
|
316
|
|
- "token": $.cookie("token")
|
|
317
|
|
- },
|
|
318
|
|
- success: function(data) {
|
|
319
|
|
- reconnecTion = data.data.user.F_UserCode;
|
|
320
|
|
- }
|
|
321
|
|
- });
|
|
322
|
|
-}
|
|
323
|
197
|
//发送
|
|
324
|
198
|
function Send() {
|
|
325
|
199
|
if(ws.readyState != ws.OPEN) {
|
|
326
|
|
- errorState=true;
|
|
327
|
|
- LogoutBack();
|
|
328
|
|
- errorFun();
|
|
329
|
|
- directType="send";
|
|
330
|
|
- sendType=ws.readyState; //JSON.stringify(data)
|
|
331
|
|
- mesCont="异常了";
|
|
332
|
|
- debuggerLog();
|
|
333
|
|
- $(".hwzt").text('连接异常!');
|
|
334
|
200
|
reconnect();
|
|
335
|
201
|
}
|
|
336
|
202
|
if(ws.readyState == ws.OPEN) {
|
|
337
|
|
- if (obj.Type) {
|
|
338
|
|
- directType="send";
|
|
339
|
|
- sendType=obj.Type;
|
|
340
|
|
- mesCont=JSON.stringify(obj);
|
|
341
|
|
- debuggerLog()
|
|
342
|
|
- }else{
|
|
343
|
|
- directType="send";
|
|
344
|
|
- sendType="建立连接";
|
|
345
|
|
- mesCont=JSON.stringify(obj);
|
|
346
|
|
- debuggerLog()
|
|
347
|
|
- }
|
|
348
|
203
|
console.log(new Date() + " send " + JSON.stringify(obj));
|
|
349
|
204
|
ws.send(JSON.stringify(obj));
|
|
350
|
205
|
}
|
|
|
@@ -375,7 +230,6 @@ var heartCheck = {
|
|
375
|
230
|
|
|
376
|
231
|
//签入
|
|
377
|
232
|
function LoginBack() {
|
|
378
|
|
- loginOr=true;
|
|
379
|
233
|
$("#top-search li i").removeClass("active");
|
|
380
|
234
|
$(".Logout").addClass("active");
|
|
381
|
235
|
$(".SayBusy").addClass("active");
|
|
|
@@ -387,7 +241,6 @@ function LoginBack() {
|
|
387
|
241
|
}
|
|
388
|
242
|
//签出
|
|
389
|
243
|
function LogoutBack() {
|
|
390
|
|
- loginOr=false;
|
|
391
|
244
|
$("#top-search li i").removeClass("active");
|
|
392
|
245
|
$(".Login").addClass("active");
|
|
393
|
246
|
$(".zxzt").removeClass("bl").addClass("br");
|