|
|
@@ -20,7 +20,9 @@ export enum CmdType {
|
|
|
/** @name 在线员工列表 */
|
|
|
OnlineBook = 12,
|
|
|
/** @name 员工工作状态 */
|
|
|
- WorkStatus = 14
|
|
|
+ WorkStatus = 14,
|
|
|
+ /** @name 强制退出 */
|
|
|
+ OutLine = 15
|
|
|
}
|
|
|
|
|
|
interface Options {
|
|
|
@@ -103,7 +105,7 @@ class Ws {
|
|
|
|
|
|
// 监听窗口关闭事件,当窗口关闭时,主动去关闭websocket连接,防止连接还没断开就关闭窗口,server端会抛异常。
|
|
|
window.addEventListener('beforeunload', () => {
|
|
|
- this.wsIns?.close()
|
|
|
+ this.disconnect()
|
|
|
})
|
|
|
} catch (error) {
|
|
|
if (isDevMode()) {
|
|
|
@@ -120,11 +122,12 @@ class Ws {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /** 断线重连 */
|
|
|
+ /** 断开连接 */
|
|
|
public disconnect() {
|
|
|
if (this.wsIns?.readyState === ReadyState.Open) {
|
|
|
this.isLock = true
|
|
|
- this.wsIns.close()
|
|
|
+ // this.wsIns.close()
|
|
|
+ this.sendMessage({ cmd: CmdType.OutLine, userid: this.uid })
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -146,17 +149,16 @@ class Ws {
|
|
|
// 重连
|
|
|
private reconnect(): void {
|
|
|
if (
|
|
|
- this.isLock ||
|
|
|
- (this.opts?.reconnectLimit && this.reconnectLimit > this.opts?.reconnectLimit)
|
|
|
+ !this.isLock &&
|
|
|
+ !(this.opts?.reconnectLimit && this.reconnectLimit > this.opts?.reconnectLimit)
|
|
|
) {
|
|
|
- return
|
|
|
+ this.reconnectLimit += 1
|
|
|
+ this.timer && clearTimeout(this.timer)
|
|
|
+ this.timer = setTimeout(() => {
|
|
|
+ this.connectWs()
|
|
|
+ this.isLock = false
|
|
|
+ }, 4000)
|
|
|
}
|
|
|
- this.reconnectLimit += 1
|
|
|
- this.timer && clearTimeout(this.timer)
|
|
|
- this.timer = setTimeout(() => {
|
|
|
- this.connectWs()
|
|
|
- this.isLock = false
|
|
|
- }, 4000)
|
|
|
}
|
|
|
}
|
|
|
export function onMessage(msg: MessageType) {
|