|
|
@@ -41,6 +41,11 @@ function Connect() {
|
|
41
|
41
|
var myDate = new Date();
|
|
42
|
42
|
console.log(myDate + " receive " + evt.data);
|
|
43
|
43
|
var data = JSON.parse(evt.data)[0];
|
|
|
44
|
+ //打印日志
|
|
|
45
|
+ directType="recive";
|
|
|
46
|
+ sendType=data.Type; //JSON.stringify(data)
|
|
|
47
|
+ mesCont=JSON.stringify(data);
|
|
|
48
|
+ debuggerLog()
|
|
44
|
49
|
if(data) {
|
|
45
|
50
|
var rlt = data.Result;
|
|
46
|
51
|
if(rlt == true) {
|
|
|
@@ -121,6 +126,11 @@ function Connect() {
|
|
121
|
126
|
};
|
|
122
|
127
|
//连接关闭的回调方法
|
|
123
|
128
|
ws.onclose = function(evt) {
|
|
|
129
|
+ var data = JSON.parse(evt.data)[0];
|
|
|
130
|
+ directType="recive";
|
|
|
131
|
+ sendType="close"; //JSON.stringify(data)
|
|
|
132
|
+ mesCont=JSON.stringify(data);
|
|
|
133
|
+ debuggerLog();
|
|
124
|
134
|
if(cls == 0) {
|
|
125
|
135
|
cls = 1;
|
|
126
|
136
|
//console.log("连接关闭!");
|
|
|
@@ -134,6 +144,11 @@ function Connect() {
|
|
134
|
144
|
};
|
|
135
|
145
|
//连接发生错误的回调方法
|
|
136
|
146
|
ws.onerror = function(evt) {
|
|
|
147
|
+ var data = JSON.parse(evt.data)[0];
|
|
|
148
|
+ directType="recive";
|
|
|
149
|
+ sendType="连接错误 "; //JSON.stringify(data)
|
|
|
150
|
+ mesCont=JSON.stringify(data);
|
|
|
151
|
+ debuggerLog();
|
|
137
|
152
|
//产生异常
|
|
138
|
153
|
$(".hwzt").text('连接出现异常!');
|
|
139
|
154
|
console.log(ws);
|
|
|
@@ -151,12 +166,28 @@ function reconnect() {
|
|
151
|
166
|
lockReconnect = true;
|
|
152
|
167
|
//没连接上会一直重连,设置延迟避免请求过多
|
|
153
|
168
|
setTimeout(function() {
|
|
|
169
|
+ directType="send";
|
|
|
170
|
+ sendType="重连中 "; //JSON.stringify(data)
|
|
|
171
|
+ mesCont="重连中";
|
|
|
172
|
+ debuggerLog();
|
|
154
|
173
|
console.log(new Date() + " " + "重连中……");
|
|
155
|
174
|
createWebSocket("ws://" + huayi.config.socket_ip + ":" + huayi.config.socket_port);
|
|
156
|
175
|
lockReconnect = false;
|
|
157
|
176
|
}, 2000);
|
|
158
|
177
|
}
|
|
159
|
|
-
|
|
|
178
|
+function debuggerLog(){
|
|
|
179
|
+ $.post(huayi.config.callcenter_url + 'Log/CallOpt', {
|
|
|
180
|
+ direct: directType,
|
|
|
181
|
+ type: sendType,
|
|
|
182
|
+ cont: mesCont,
|
|
|
183
|
+ "token": $.cookie("token")
|
|
|
184
|
+ }, function(result) {
|
|
|
185
|
+ result = $.parseJSON(result);
|
|
|
186
|
+ if(result.state.toLowerCase() == "warning") {
|
|
|
187
|
+ //layer.msg("创建工单成功");
|
|
|
188
|
+ }
|
|
|
189
|
+ })
|
|
|
190
|
+}
|
|
160
|
191
|
//发送
|
|
161
|
192
|
function Send() {
|
|
162
|
193
|
if(ws.readyState != ws.OPEN) {
|
|
|
@@ -164,6 +195,17 @@ function Send() {
|
|
164
|
195
|
}
|
|
165
|
196
|
if(ws.readyState == ws.OPEN) {
|
|
166
|
197
|
console.log(new Date() + " send " + JSON.stringify(obj));
|
|
|
198
|
+ if (obj.Type) {
|
|
|
199
|
+ directType="send";
|
|
|
200
|
+ sendType=obj.Type;
|
|
|
201
|
+ mesCont=JSON.stringify(obj);
|
|
|
202
|
+ debuggerLog()
|
|
|
203
|
+ }else{
|
|
|
204
|
+ directType="send";
|
|
|
205
|
+ sendType="建立连接";
|
|
|
206
|
+ mesCont=JSON.stringify(obj);
|
|
|
207
|
+ debuggerLog()
|
|
|
208
|
+ }
|
|
167
|
209
|
ws.send(JSON.stringify(obj));
|
|
168
|
210
|
}
|
|
169
|
211
|
}
|