前端当网页不可见时,延迟加载房间

This commit is contained in:
John Smith 2023-09-15 23:18:47 +08:00
parent 7e656ebe09
commit b1916608ee

View File

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