From f3b3e0212039eeb37de3c269a512cb97fac3e83b Mon Sep 17 00:00:00 2001 From: Megghy Date: Fri, 24 Nov 2023 22:24:36 +0800 Subject: [PATCH] update interval/timeou --- .eslintrc.js | 26 +++++++---- package.json | 3 +- src/data/DanmakuClient.ts | 7 ++- src/data/chat/ChatClientOfficialBase/index.js | 18 ++++---- src/views/open_live/MusicRequest.vue | 8 +--- src/views/open_live/OpenLiveIndex.vue | 16 ++++++- yarn.lock | 45 ++++++++++++++++++- 7 files changed, 94 insertions(+), 29 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index cab3f8f..306209a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,18 +3,28 @@ module.exports = { env: { node: true, }, - extends: [ - '@vue/typescript/recommended', - 'plugin:vue/vue3-essential', - 'prettier', - '@vue/eslint-config-typescript' - ], + extends: ['@vue/typescript/recommended', 'plugin:vue/vue3-essential', 'prettier', '@vue/eslint-config-typescript'], + parser: '@babel/eslint-parser', parserOptions: { ecmaVersion: 'latest', + requireConfigFile: false, }, rules: { 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off', - "vue/component-name-in-template-casing": ["error", "PascalCase"], + 'vue/component-name-in-template-casing': ['error', 'PascalCase'], }, -}; + overrides: [ + { + files: ['**/*.ts', '**/*.tsx'], + parser: '@typescript-eslint/parser', + extends: [ + '@vue/typescript/recommended', + // other TypeScript specific configurations... + ], + rules: { + // TypeScript specific rules... + }, + }, + ], +} diff --git a/package.json b/package.json index 5d5d9be..fba9dea 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,8 @@ "vue-turnstile": "^1.0.0", "vue3-aplayer": "^1.7.3", "vue3-marquee": "^4.1.0", - "vuex": "^4.0.0" + "vuex": "^4.0.0", + "worker-timers": "^7.0.78" }, "devDependencies": { "@babel/eslint-parser": "^7.21.3", diff --git a/src/data/DanmakuClient.ts b/src/data/DanmakuClient.ts index d3aa9b3..91c5b52 100644 --- a/src/data/DanmakuClient.ts +++ b/src/data/DanmakuClient.ts @@ -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(OPEN_LIVE_API_URL + 'heartbeat', this.authInfo) : QueryGetAPI(OPEN_LIVE_API_URL + 'heartbeat-internal')).then((data) => { + (this.authInfo ? QueryPostAPI(OPEN_LIVE_API_URL + 'heartbeat', this.authInfo) : QueryGetAPI(OPEN_LIVE_API_URL + 'heartbeat-internal')).then((data) => { if (data.code != 200) { console.error('[OPEN-LIVE] 心跳失败: ' + data.message) this.client.stop() diff --git a/src/data/chat/ChatClientOfficialBase/index.js b/src/data/chat/ChatClientOfficialBase/index.js index 8f27795..d886a58 100644 --- a/src/data/chat/ChatClientOfficialBase/index.js +++ b/src/data/chat/ChatClientOfficialBase/index.js @@ -1,4 +1,5 @@ import { BrotliDecode } from './brotli_decode' +import { setInterval, clearInterval, setTimeout, clearTimeout } from 'worker-timers' const HEADER_SIZE = 16 @@ -142,8 +143,9 @@ export default class ChatClientOfficialBase { onWsOpen() { this.sendAuth() - this.heartbeatTimerId = window.setInterval(this.sendHeartbeat.bind(this), HEARTBEAT_INTERVAL) + this.heartbeatTimerId = setInterval(this.sendHeartbeat.bind(this), HEARTBEAT_INTERVAL) this.refreshReceiveTimeoutTimer() + console.log('ws 已连接'); } sendHeartbeat() { @@ -152,9 +154,9 @@ export default class ChatClientOfficialBase { refreshReceiveTimeoutTimer() { if (this.receiveTimeoutTimerId) { - window.clearTimeout(this.receiveTimeoutTimerId) + clearTimeout(this.receiveTimeoutTimerId) } - this.receiveTimeoutTimerId = window.setTimeout(this.onReceiveTimeout.bind(this), RECEIVE_TIMEOUT) + this.receiveTimeoutTimerId = setTimeout(this.onReceiveTimeout.bind(this), RECEIVE_TIMEOUT) } onReceiveTimeout() { @@ -164,7 +166,7 @@ export default class ChatClientOfficialBase { discardWebsocket() { if (this.receiveTimeoutTimerId) { - window.clearTimeout(this.receiveTimeoutTimerId) + clearTimeout(this.receiveTimeoutTimerId) this.receiveTimeoutTimerId = null } @@ -177,11 +179,11 @@ export default class ChatClientOfficialBase { onWsClose() { this.websocket = null if (this.heartbeatTimerId) { - window.clearInterval(this.heartbeatTimerId) + clearInterval(this.heartbeatTimerId) this.heartbeatTimerId = null } if (this.receiveTimeoutTimerId) { - window.clearTimeout(this.receiveTimeoutTimerId) + clearTimeout(this.receiveTimeoutTimerId) this.receiveTimeoutTimerId = null } @@ -189,8 +191,8 @@ export default class ChatClientOfficialBase { return } this.retryCount++ - console.warn('掉线重连中', this.retryCount) - window.setTimeout(this.wsConnect.bind(this), 1000) + console.warn('心跳超时, 重连中', this.retryCount) + setTimeout(this.wsConnect.bind(this), 1000) } onWsMessage(event) { diff --git a/src/views/open_live/MusicRequest.vue b/src/views/open_live/MusicRequest.vue index a8d6d7f..66a156a 100644 --- a/src/views/open_live/MusicRequest.vue +++ b/src/views/open_live/MusicRequest.vue @@ -830,19 +830,13 @@ onUnmounted(() => { 如果没有部署 VtsuruEventFetcher - 则其需要保持此页面开启才能点歌 + 则其需要保持此页面开启才能点歌, 也不要同时开多个页面, 会导致点歌重复 !(部署了则不影响) 前往登录或注册
- - 不要同时开多个页面, 会导致点歌重复! 可以考虑使用 - VtsuruEventFetcher - , 部署后还可以记录SC和上舰历史 - -
diff --git a/src/views/open_live/OpenLiveIndex.vue b/src/views/open_live/OpenLiveIndex.vue index f7b18bd..6ccfe1a 100644 --- a/src/views/open_live/OpenLiveIndex.vue +++ b/src/views/open_live/OpenLiveIndex.vue @@ -1,12 +1,15 @@ +
+ + 当浏览器在后台运行时定时器和 Websocket 连接将受到严格限制, 这会导致弹幕接收功能无法正常工作 (详见 + 此文章), 虽然本站已经针对此问题做出了处理, 一般情况下即使掉线了也会重连, + 不过还是有可能会遗漏事件 +
+ 为避免这种情况, 建议注册本站账后使用 VtsuruEventFetcher , + 否则请在使用功能时尽量保持网页在前台运行 +
还有更多 动态抽奖、视频征集、歌单、棉花糖、日程表... diff --git a/yarn.lock b/yarn.lock index fa9fcfe..40c58bc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -50,6 +50,13 @@ dependencies: regenerator-runtime "^0.14.0" +"@babel/runtime@^7.23.4": + version "7.23.4" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.23.4.tgz#36fa1d2b36db873d25ec631dcc4923fdc1cf2e2e" + integrity sha512-2Yv65nlWnWlSpe3fXEyX5i7fx5kIKo4Qbcj+hMO0odwaneFjfXw5fdum+4yL20O0QiaHpia0cYQ9xpNMqrBwHg== + dependencies: + regenerator-runtime "^0.14.0" + "@css-render/plugin-bem@^0.15.12": version "0.15.12" resolved "https://registry.yarnpkg.com/@css-render/plugin-bem/-/plugin-bem-0.15.12.tgz#cd88e46a388e4786436bd622414da0aa6019af3b" @@ -1683,6 +1690,14 @@ fast-levenshtein@^2.0.6: resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" integrity sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw== +fast-unique-numbers@^8.0.11: + version "8.0.11" + resolved "https://registry.yarnpkg.com/fast-unique-numbers/-/fast-unique-numbers-8.0.11.tgz#e2f2dbd681a87f9058056dfa15a52eacb4eeebcc" + integrity sha512-FmTi6tqMymufGgYEGKWez0I3Ji9ykhHjVzhqhPFOQ3j+IM6Y4PMo+Q17BVCKmCjK6QiFJ+YVINaYScOyFrkzew== + dependencies: + "@babel/runtime" "^7.23.4" + tslib "^2.6.2" + fastq@^1.6.0: version "1.15.0" resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.15.0.tgz#d04d07c6a2a68fe4599fea8d2e103a937fae6b3a" @@ -3114,7 +3129,7 @@ tslib@^1.8.1: resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== -tslib@^2.1.0: +tslib@^2.1.0, tslib@^2.6.2: version "2.6.2" resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae" integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q== @@ -3439,6 +3454,34 @@ which@^2.0.1: dependencies: isexe "^2.0.0" +worker-timers-broker@^6.0.98: + version "6.0.98" + resolved "https://registry.yarnpkg.com/worker-timers-broker/-/worker-timers-broker-6.0.98.tgz#d8c062c9304ee55d22b24e610d4f1ffa5dac3798" + integrity sha512-Kq8dTnHBoBGXdMYHGYAtZ+gbxdsV085PF3QoxFZMDKvqPlyTuRFGQvc70k9fHeGOCFlUv6OUREvYF72aquBOFw== + dependencies: + "@babel/runtime" "^7.23.4" + fast-unique-numbers "^8.0.11" + tslib "^2.6.2" + worker-timers-worker "^7.0.62" + +worker-timers-worker@^7.0.62: + version "7.0.62" + resolved "https://registry.yarnpkg.com/worker-timers-worker/-/worker-timers-worker-7.0.62.tgz#e986532c8ea06b5e80a6e228c572e0561dea31a2" + integrity sha512-WuVhWXWEqwcWD2Iy9tNQWQyfl984XF/hoblazHp4KOWiIN50B2PH0l61nBkJUndFhJ9qca0lEZ7SWSqdIMDWDQ== + dependencies: + "@babel/runtime" "^7.23.4" + tslib "^2.6.2" + +worker-timers@^7.0.78: + version "7.0.78" + resolved "https://registry.yarnpkg.com/worker-timers/-/worker-timers-7.0.78.tgz#0e6f243654ca2b43e1cc956c69a9e8c0abba10e1" + integrity sha512-jATkwi6OFe2XwfvoPYl3hr8k19/JgCiFerJ4ZWv5AbMIjsUnayC1C8Dxau/sevqhzCrU4IqXDFDTjNINGNuibQ== + dependencies: + "@babel/runtime" "^7.23.4" + tslib "^2.6.2" + worker-timers-broker "^6.0.98" + worker-timers-worker "^7.0.62" + wrap-ansi@^6.2.0: version "6.2.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53"