update interval/timeou

This commit is contained in:
2023-11-24 22:24:36 +08:00
parent a0858651d6
commit f3b3e02120
7 changed files with 94 additions and 29 deletions

View File

@@ -3,6 +3,7 @@ import { QueryGetAPI, QueryPostAPI } from '@/api/query'
import ChatClientDirectOpenLive from '@/data/chat/ChatClientDirectOpenLive.js'
import { OPEN_LIVE_API_URL } from './constants'
import { ref, toRef } from 'vue'
import { setInterval, clearInterval } from 'worker-timers'
export interface DanmakuInfo {
room_id: number
@@ -182,7 +183,9 @@ export default class DanmakuClient {
} else {
console.warn('[OPEN-LIVE] 弹幕客户端未被启动, 忽略')
}
clearInterval(this.timer)
if (this.timer) {
clearInterval(this.timer)
}
this.events = {
danmaku: [],
gift: [],
@@ -191,7 +194,7 @@ export default class DanmakuClient {
}
private sendHeartbeat() {
if (this.client) {
;(this.authInfo ? QueryPostAPI<OpenLiveInfo>(OPEN_LIVE_API_URL + 'heartbeat', this.authInfo) : QueryGetAPI<OpenLiveInfo>(OPEN_LIVE_API_URL + 'heartbeat-internal')).then((data) => {
(this.authInfo ? QueryPostAPI<OpenLiveInfo>(OPEN_LIVE_API_URL + 'heartbeat', this.authInfo) : QueryGetAPI<OpenLiveInfo>(OPEN_LIVE_API_URL + 'heartbeat-internal')).then((data) => {
if (data.code != 200) {
console.error('[OPEN-LIVE] 心跳失败: ' + data.message)
this.client.stop()