feat(websoket): websoket

websoket优化
This commit is contained in:
猿小天
2023-03-14 23:52:30 +08:00
parent e79f790d72
commit ab9beff867
2 changed files with 3 additions and 94 deletions

View File

@@ -1,7 +1,7 @@
import {ElNotification as message} from 'element-plus'
import store from '@/store'
import {Session} from "/@/utils/storage";
import {getWsBaseURL} from "/@/utils/baseUrl";
// @ts-ignore
import socket from '@/types/api/socket'
const websocket: socket = {
@@ -77,10 +77,11 @@ const websocket: socket = {
websocket.send(data)
}, websocket.hearbeat_interval)
},
send: (data, callback = null) => {
send: (data:string, callback = null) => {
// 开启状态直接发送
if (websocket.websocket.readyState === websocket.websocket.OPEN) {
websocket.websocket.send(JSON.stringify(data))
// @ts-ignore
callback && callback()
} else {
clearInterval(websocket.hearbeat_timer)