|
@@ -3,6 +3,7 @@ class WebSocketClient {
|
|
|
constructor(userId, options = {}) {
|
|
|
this.system = '3';
|
|
|
this.userId = userId;
|
|
|
+ // import.meta.env.VITE_APP_BASE_API
|
|
|
const baseURL = 'http://192.168.100.128:9527';
|
|
|
// const baseURL = 'https://goldshulin.com/prod-api';
|
|
|
const url = baseURL.split('/')[2];
|
|
@@ -22,6 +23,8 @@ class WebSocketClient {
|
|
|
this.messageCallbacks = new Map()
|
|
|
this.isConnected = false
|
|
|
this.isReconnecting = false
|
|
|
+
|
|
|
+ this.reconnectCount = 0;
|
|
|
}
|
|
|
|
|
|
// 连接WebSocket
|
|
@@ -76,10 +79,12 @@ class WebSocketClient {
|
|
|
reconnect() {
|
|
|
if (this.isReconnecting) return
|
|
|
|
|
|
+
|
|
|
this.isReconnecting = true
|
|
|
this.reconnectTimer = setTimeout(() => {
|
|
|
console.log('尝试重新连接...')
|
|
|
- this.connect()
|
|
|
+ this.reconnectCount = this.reconnectCount + 1;
|
|
|
+ this.reconnectCount <3 && this.connect()
|
|
|
}, this.options.reconnectInterval)
|
|
|
}
|
|
|
|