no message
This commit is contained in:
parent
a15732a789
commit
50fa3fe16e
@ -1,13 +1,14 @@
|
||||
import config from '@/config';
|
||||
import {
|
||||
ref
|
||||
} from 'vue';
|
||||
import { ref } from 'vue';
|
||||
import tool from '@/utils/tool';
|
||||
|
||||
let socket;
|
||||
let reconnectAttempts = 1;
|
||||
let intervalId; // 用于保存心跳请求的定时器id
|
||||
const maxReconnectAttempts = 5;
|
||||
const heartbeatInterval = 50000;
|
||||
const socketState = ref(socket);
|
||||
|
||||
export function createWebSocket() {
|
||||
let socketurl = config.WEBSOCKET || null;
|
||||
if (socketurl) {
|
||||
@ -32,8 +33,11 @@ export function createWebSocket() {
|
||||
}
|
||||
reconnectAttempts = 0; // reset reconnect attempts
|
||||
|
||||
// 清除之前的定时器
|
||||
clearInterval(intervalId);
|
||||
|
||||
// 定时发送心跳请求
|
||||
setInterval(function() {
|
||||
intervalId = setInterval(function () {
|
||||
socket.send(JSON.stringify({
|
||||
type: 'ping'
|
||||
}));
|
||||
@ -67,7 +71,9 @@ function reconnect() {
|
||||
console.log('WebSocket重连失败');
|
||||
}
|
||||
}
|
||||
|
||||
createWebSocket();
|
||||
|
||||
export default {
|
||||
state: socketState
|
||||
}
|
Loading…
Reference in New Issue
Block a user