Sfoglia il codice sorgente

fix: 用户挤下线的bug

xsx 5 mesi fa
parent
commit
b3105f9bd5
3 ha cambiato i file con 14 aggiunte e 9 eliminazioni
  1. 4 2
      im-uniapp/App.vue
  2. 4 3
      im-uniapp/common/wssocket.js
  3. 6 4
      im-web/src/view/Home.vue

+ 4 - 2
im-uniapp/App.vue

@@ -74,8 +74,10 @@ export default {
 			wsApi.onClose((res) => {
 				console.log("ws断开", res);
 				// 重新连接
-				this.reconnectWs();
-				this.configStore.setAppInit(false);
+				if (!this.reconnecting) {
+					this.reconnectWs();
+					this.configStore.setAppInit(false);
+				}
 			})
 		},
 		loadStore() {

+ 4 - 3
im-uniapp/common/wssocket.js

@@ -66,9 +66,7 @@ let connect = (wsurl, token) => {
 
 	socketTask.onError((e) => {
 		console.log("ws错误:",e)
-		close();
-		isConnect = false;
-		closeCallBack && closeCallBack({ code: 1006 });
+		close(1006);
 	})
 }
 
@@ -97,6 +95,9 @@ let close = (code) => {
 		complete: (res) => {
 			console.log("关闭websocket连接");
 			isConnect = false;
+			if (code != 3099) {
+				closeCallBack && closeCallBack(res);s
+			}
 		},
 		fail: (e) => {
 			console.log("关闭websocket连接失败", e);

+ 6 - 4
im-web/src/view/Home.vue

@@ -148,8 +148,10 @@ export default {
 				this.$wsApi.onClose((e) => {
 					if (e.code != 3000) {
 						// 断线重连
-						this.reconnectWs();
-						this.configStore.setAppInit(false)
+						if (!this.reconnecting) {
+							this.reconnectWs();
+							this.configStore.setAppInit(false)
+						}
 					}
 				});
 			}).catch((e) => {
@@ -385,8 +387,8 @@ export default {
 			this.chatStore.insertMessage(msg, chatInfo);
 			// 播放提示音
 			if (!group.isDnd && !this.chatStore.loading &&
-				!msg.selfSend && this.$msgType.isNormal(msg.type)
-				&& msg.status != this.$enums.MESSAGE_STATUS.READED) {
+				!msg.selfSend && this.$msgType.isNormal(msg.type) &&
+				msg.status != this.$enums.MESSAGE_STATUS.READED) {
 				this.playAudioTip();
 			}
 		},