luke 6 anni fa
parent
commit
83cb3ba6fb
1 ha cambiato i file con 14 aggiunte e 14 eliminazioni
  1. 14 14
      pc_chat/src/components/chat.vue

+ 14 - 14
pc_chat/src/components/chat.vue

@@ -189,8 +189,7 @@
 									<div class=" row">
 										<div class="conversation row">
 											<div class="headImg">
-												<img :src="serviceImg?url+serviceImg:require('@/assets/st-img/kf.png')"
-													 alt="">
+												<img :src="serviceImg?url+serviceImg:require('@/assets/st-img/kf.png')" alt="">
 											</div>
 											<div class="cont left">
 												<div v-if="item.content != ''" v-html="item.content"></div>
@@ -467,7 +466,6 @@
 				timeout: 10000,          //10s一次心跳检测
 				timeoutObj: null,
 				serverTimeoutObj: null,
-
 			}
 		},
 		methods: {
@@ -604,7 +602,6 @@
 					this.time = '';
 					this.returnTimer = '';
 					// this.automaticRolling();
-					this.initWebSocket();
 					this.customerSviceChat = [];
 					this.reconnect();
 				}
@@ -776,6 +773,7 @@
 				let apiToken = this.$md5.hex_md5('customer-service' + this.currTime + window.location.origin);
 				this.websock = new WebSocket('ws://103.108.43.176:9101?apiToken=' + apiToken);
 				//this.websock = new WebSocket('ws://192.168.2.186:9101?apiToken=' + apiToken);
+				this.websock.debug = true;
 				// 数据接收
 				this.websock.onmessage = this.websocketonmessage;
 				// 连接建立之后
@@ -783,7 +781,7 @@
 				// 连接建立失败重连
 				this.websock.onerror = this.websocketonerror;
 				// 关闭会话
-				this.websock.onclose = this.websocketonclose;
+				this.websock.onclose = this.websocketclose;
 			},
 
 			/****************连接建立成功***************/
@@ -794,8 +792,8 @@
 			},
 
 			/*************连接建立失败重连***************** */
-			websocketonerror() {
-				console.log('连接建立失败重连');
+			websocketonerror(e) {
+				console.log('连接建立失败重连: ' + e.code + ' ' + e.reason + ' ', e)
 				this.goBack(1);
 			},
 
@@ -930,10 +928,9 @@
 				// 客服关闭会话.
 				if (redata.message_type == 'closeBysever') {
 					this.goBack(1);
-					this.lockReconnect = true;
-					clearTimeout(this.reconnectData);      //离开清除 timeout
-					clearTimeout(this.timeoutObj);         //离开清除 timeout
-					clearTimeout(this.serverTimeoutObj);   //离开清除 timeout
+					// clearTimeout(this.reconnectData);      //离开清除 timeout
+					// clearTimeout(this.timeoutObj);         //离开清除 timeout
+					// clearTimeout(this.serverTimeoutObj);   //离开清除 timeout
 				}
 				// 客服掉线.
 				if (redata.message_type == 'serviceoffline') {
@@ -952,8 +949,8 @@
 
 
 			/************关闭会话*******************/
-			websocketonclose(e) {
-				console.log('断开会话', e);
+			websocketclose(e) {
+				console.log('websocket 断开: ' + e.code + ' ' + e.reason + ' ', e)
 				this.goBack();
 			},
 
@@ -974,6 +971,7 @@
 				this.reconnectData && clearTimeout(this.reconnectData);
 				this.reconnectData = setTimeout(() => {
 					this.initWebSocket();
+					console.log('-----lail-----');
 					this.lockReconnect = false;
 				}, 5000)
 			},
@@ -987,7 +985,9 @@
 					console.log('发送', {type: 'ping'});
 					this.websocketsend(JSON.stringify({type: 'ping'}))   //根据后台要求发送
 					this.serverTimeoutObj = setTimeout(() => {
-						this.websock.close(); //如果  5秒之后我们没有收到 后台返回的心跳检测数据 断开socket,断开后会启动重连机制
+						console.log('------close-------')
+						this.websock.close(); //如果 5秒之后我们没有收到 后台返回的心跳检测数据 断开socket,断开后会启动重连机制
+
 					}, 5000);
 				}, this.timeout)
 			},