From b1916608eee550a910579398dff74c7cf896c5c1 Mon Sep 17 00:00:00 2001 From: John Smith Date: Fri, 15 Sep 2023 23:18:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E7=AB=AF=E5=BD=93=E7=BD=91=E9=A1=B5?= =?UTF-8?q?=E4=B8=8D=E5=8F=AF=E8=A7=81=E6=97=B6=EF=BC=8C=E5=BB=B6=E8=BF=9F?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E6=88=BF=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/views/Room.vue | 40 ++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/frontend/src/views/Room.vue b/frontend/src/views/Room.vue index fbf576b..6107d31 100644 --- a/frontend/src/views/Room.vue +++ b/frontend/src/views/Room.vue @@ -77,26 +77,42 @@ export default { } }, mounted() { - this.initConfig() - this.initChatClient() - this.initTextEmoticons() - if (this.config.giftUsernamePronunciation !== '') { - this.pronunciationConverter = new pronunciation.PronunciationConverter() - this.pronunciationConverter.loadDict(this.config.giftUsernamePronunciation) + if (document.visibilityState === 'visible') { + this.init() + } else { + // 当前窗口不可见,延迟到可见时加载,防止OBS中一次并发太多请求(OBS中浏览器不可见时也会加载网页,除非显式设置) + document.addEventListener('visibilitychange', this.onVisibilityChange) } - - // 提示用户已加载 - this.$message({ - message: 'Loaded', - duration: 500 - }) }, beforeDestroy() { + document.removeEventListener('visibilitychange', this.onVisibilityChange) if (this.chatClient) { this.chatClient.stop() } }, methods: { + onVisibilityChange() { + if (document.visibilityState !== 'visible') { + return + } + document.removeEventListener('visibilitychange', this.onVisibilityChange) + this.init() + }, + init() { + this.initConfig() + this.initChatClient() + this.initTextEmoticons() + if (this.config.giftUsernamePronunciation !== '') { + this.pronunciationConverter = new pronunciation.PronunciationConverter() + this.pronunciationConverter.loadDict(this.config.giftUsernamePronunciation) + } + + // 提示用户已加载 + this.$message({ + message: 'Loaded', + duration: 500 + }) + }, initConfig() { let locale = this.strConfig.lang if (locale) {