|
@@ -43,25 +43,25 @@ class Socket {
|
|
|
}
|
|
|
//打开
|
|
|
onOpen(event: Event) {
|
|
|
- console.log('WebSocket opened:', event)
|
|
|
+ // console.log('WebSocket opened:', event)
|
|
|
this.reconnectAttempts = 0
|
|
|
this.startHeartbeat()
|
|
|
this.emit('open', event)
|
|
|
}
|
|
|
//收到的WebSocket消息
|
|
|
onMessage(event: MessageEvent) {
|
|
|
- console.log('WebSocket message received:', event.data)
|
|
|
+ // console.log('WebSocket message received:', event.data)
|
|
|
this.emit('message', event.data)
|
|
|
}
|
|
|
//错误
|
|
|
onError(event: Event) {
|
|
|
- console.error('WebSocket error:', event)
|
|
|
+ // console.error('WebSocket error:', event)
|
|
|
this.emit('error', event)
|
|
|
}
|
|
|
//重连逻辑中,在连接失败后自动重新连接
|
|
|
onClose(event: CloseEvent) {
|
|
|
- console.log('WebSocket closed:', event)
|
|
|
- this.stopHeartbeat()
|
|
|
+ // console.log('WebSocket closed:', event)
|
|
|
+ // this.stopHeartbeat()
|
|
|
this.emit('close', event)
|
|
|
// 重连逻辑中,在连接失败后自动重新连接,但会限制重连的次数和每次重连之间的间隔时间
|
|
|
if (this.opts.maxReconnectAttempts !== 0 && this.reconnectAttempts < this.opts.maxReconnectAttempts!) {
|
|
@@ -117,7 +117,7 @@ class Socket {
|
|
|
}
|
|
|
|
|
|
export function useSocket(url: string = import.meta.env.VITE_WEBSOCKET_SERVER, opts?: SocketOptions) {
|
|
|
- console.log('websocket-url: ', url)
|
|
|
+ // console.log('websocket-url: ', url)
|
|
|
const socket = new Socket(url, opts)
|
|
|
|
|
|
onUnmounted(() => {
|