| | |
| | | |
| | | import { message } from 'ant-design-vue' |
| | | import ReconnectingWebSocket from 'reconnecting-websocket' |
| | | import { ELocalStorageKey } from '../types' |
| | | |
| | | interface WebSocketOptions { |
| | | data: any |
| | |
| | | if (!this._url) { |
| | | return |
| | | } |
| | | |
| | | const token: string = localStorage.getItem(ELocalStorageKey.Token) || '' as string |
| | | // 会自动重连,无需处理重连逻辑 |
| | | console.log(token, 'token') |
| | | this._socket = new ReconnectingWebSocket(this._url, [], { |
| | | maxReconnectionDelay: 20000, // 断开后最大的重连时间: 20s,每多一次重连,会增加 1.3 倍,5 * 1.3 * 1.3 * 1.3... |
| | | minReconnectionDelay: 5000, // 断开后最短的重连时间: 5s |
| | | maxRetries: 5 |
| | | maxRetries: 5, |
| | | }) |
| | | |
| | | this._hasInit = true |
| | | |
| | | this._socket.addEventListener('open', this._onOpen.bind(this)) |