fix: bug
This commit is contained in:
@@ -20,6 +20,7 @@ export default class WebSocketUtil {
|
||||
this.heartbeatTimer = null; // 心跳计时器
|
||||
this.heartbeatInterval = options.heartbeatInterval || 30000; // 心跳间隔(ms)
|
||||
this.heartbeatMsg = options.heartbeatMsg || 'ping'; // 心跳消息
|
||||
this.isClose = false; // 手动关闭
|
||||
this.callbacks = {
|
||||
open: [], // 连接打开回调
|
||||
message: [], // 消息接收回调
|
||||
@@ -165,6 +166,7 @@ export default class WebSocketUtil {
|
||||
* @returns {WebSocketUtil} - 返回当前实例,支持链式调用
|
||||
*/
|
||||
close(code = 1000, reason = '') {
|
||||
this.isClose = true
|
||||
if (this.socketTask) {
|
||||
clearInterval(this.heartbeatTimer); // 清除心跳计时器
|
||||
clearInterval(this.reconnectTimer); // 清除重连计时器
|
||||
@@ -204,6 +206,7 @@ export default class WebSocketUtil {
|
||||
* 尝试重新连接WebSocket
|
||||
*/
|
||||
tryReconnect() {
|
||||
if(this.isClose) return
|
||||
if (this.reconnectCount < this.maxReconnectCount) {
|
||||
clearInterval(this.reconnectTimer);
|
||||
this.reconnectTimer = setTimeout(() => {
|
||||
|
||||
Reference in New Issue
Block a user