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,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...
},
},
],
}

View File

@@ -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",

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()

View File

@@ -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) {

View File

@@ -830,19 +830,13 @@ onUnmounted(() => {
<NText depth="3">
如果没有部署
<NButton text type="primary" tag="a" href="https://www.yuque.com/megghy/dez70g/vfvcyv3024xvaa1p" target="_blank"> VtsuruEventFetcher </NButton>
则其需要保持此页面开启才能点歌
则其需要保持此页面开启才能点歌, 也不要同时开多个页面, 会导致点歌重复 !(部署了则不影响)
</NText>
</NAlert>
<NAlert type="warning" v-else title="你尚未注册并登录 VTsuru.live, 大部分规则设置将不可用 (因为我懒得在前段重写一遍逻辑">
<NButton @click="$router.push({ name: 'manage-index' })" type="primary"> 前往登录或注册 </NButton>
</NAlert>
<br />
<NAlert v-if="accountInfo?.eventFetcherOnline != true" type="warning" closable>
不要同时开多个页面, 会导致点歌重复! 可以考虑使用
<NButton text type="primary" tag="a" href="https://www.yuque.com/megghy/dez70g/vfvcyv3024xvaa1p" target="_blank"> VtsuruEventFetcher </NButton>
, 部署后还可以记录SC和上舰历史
</NAlert>
<br />
<NCard size="small">
<NSpace align="center">
<NTooltip>

View File

@@ -1,12 +1,15 @@
<script setup lang="ts">
import DanmakuClient, { RoomAuthInfo } from '@/data/DanmakuClient';
import { NButton, NCard, NDivider, NSpace } from 'naive-ui'
import { useAccount } from '@/api/account'
import DanmakuClient, { RoomAuthInfo } from '@/data/DanmakuClient'
import { NAlert, NButton, NCard, NDivider, NSpace } from 'naive-ui'
const props = defineProps<{
client: DanmakuClient
roomInfo: RoomAuthInfo
code: string | undefined
}>()
const accountInfo = useAccount()
</script>
<template>
@@ -25,6 +28,15 @@ const props = defineProps<{
</template>
</NCard>
</NSpace>
<br />
<NAlert v-if="accountInfo?.eventFetcherOnline != true" type="warning" title="可用性警告" style="max-width: 600px; margin: 0 auto">
当浏览器在后台运行时定时器和 Websocket 连接将受到严格限制, 这会导致弹幕接收功能无法正常工作 (详见
<NButton text tag="a" href="https://developer.chrome.com/blog/background_tabs/" target="_blank" type="info">此文章</NButton>), 虽然本站已经针对此问题做出了处理, 一般情况下即使掉线了也会重连,
不过还是有可能会遗漏事件
<br />
为避免这种情况, 建议注册本站账后使用 <NButton type="primary" text size="tiny" tag="a" href="https://www.yuque.com/megghy/dez70g/vfvcyv3024xvaa1p" target="_blank"> VtsuruEventFetcher </NButton>,
否则请在使用功能时尽量保持网页在前台运行
</NAlert>
<NDivider> 还有更多 </NDivider>
<NSpace justify="center" align="center" vertical>
动态抽奖视频征集歌单棉花糖日程表...

View File

@@ -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"