diff --git a/frontend/package.json b/frontend/package.json index 7e2ebda..555bda3 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "blivechat", - "version": "1.9.0", + "version": "1.9.1-dev", "private": true, "scripts": { "serve": "vue-cli-service serve", diff --git a/frontend/src/api/chat/ChatClientDirectOpenLive.js b/frontend/src/api/chat/ChatClientDirectOpenLive.js index 57c7eba..4312a09 100644 --- a/frontend/src/api/chat/ChatClientDirectOpenLive.js +++ b/frontend/src/api/chat/ChatClientDirectOpenLive.js @@ -41,9 +41,17 @@ export default class ChatClientDirectOpenLive extends ChatClientOfficialBase { if (this.gameId && this.gameHeartbeatTimerId === null) { this.gameHeartbeatTimerId = window.setTimeout(this.onSendGameHeartbeat.bind(this), GAME_HEARTBEAT_INTERVAL) } + + this.msgHandler.onDebugMsg(new chatModels.DebugMsg({ + content: '开始连接房间' + })) } onWsClose() { + this.msgHandler.onDebugMsg(new chatModels.DebugMsg({ + content: '房间连接已断开' + })) + if (this.gameHeartbeatTimerId) { window.clearTimeout(this.gameHeartbeatTimerId) this.gameHeartbeatTimerId = null @@ -69,6 +77,10 @@ export default class ChatClientDirectOpenLive extends ChatClientOfficialBase { } } catch (e) { console.error('startGame failed:', e) + this.msgHandler.onDebugMsg(new chatModels.DebugMsg({ + content: `开放平台开启项目失败:${e}` + })) + if (e instanceof chatModels.ChatClientFatalError) { throw e } @@ -87,6 +99,10 @@ export default class ChatClientDirectOpenLive extends ChatClientOfficialBase { } async endGame() { + this.msgHandler.onDebugMsg(new chatModels.DebugMsg({ + content: '开放平台关闭项目' + })) + if (!this.gameId) { return true } @@ -130,6 +146,9 @@ export default class ChatClientDirectOpenLive extends ChatClientOfficialBase { })).data if (res.code !== 0) { console.error(`sendGameHeartbeat failed: code=${res.code}, message=${res.message}, request_id=${res.request_id}`) + this.msgHandler.onDebugMsg(new chatModels.DebugMsg({ + content: `开放平台项目心跳失败:code=${res.code}, message=${res.message}` + })) if (res.code === 7003 && this.gameId === gameId) { // 项目异常关闭,可能是心跳超时,需要重新开启项目 @@ -141,6 +160,9 @@ export default class ChatClientDirectOpenLive extends ChatClientOfficialBase { } } catch (e) { console.error('sendGameHeartbeat failed:', e) + this.msgHandler.onDebugMsg(new chatModels.DebugMsg({ + content: `开放平台项目心跳失败:${e}` + })) return false } return true @@ -161,6 +183,10 @@ export default class ChatClientDirectOpenLive extends ChatClientOfficialBase { } sendAuth() { + this.msgHandler.onDebugMsg(new chatModels.DebugMsg({ + content: '已连接到房间,发送认证消息' + })) + this.websocket.send(this.makePacket(this.authBody, base.OP_AUTH)) } @@ -171,6 +197,10 @@ export default class ChatClientDirectOpenLive extends ChatClientOfficialBase { this.endGame() } + this.msgHandler.onDebugMsg(new chatModels.DebugMsg({ + content: `计划下次重连,当前页面${document.visibilityState === 'visible' ? '可见' : '不可见'}` + })) + super.delayReconnect() } diff --git a/frontend/src/api/chat/models.js b/frontend/src/api/chat/models.js index 7ab776d..22e0ed0 100644 --- a/frontend/src/api/chat/models.js +++ b/frontend/src/api/chat/models.js @@ -121,3 +121,11 @@ export class ChatClientFatalError extends Error { this.type = type } } + +export class DebugMsg { + constructor({ + content = '', + } = {}) { + this.content = content + } +} diff --git a/frontend/src/views/Room.vue b/frontend/src/views/Room.vue index bdf0717..d57060e 100644 --- a/frontend/src/views/Room.vue +++ b/frontend/src/views/Room.vue @@ -362,6 +362,15 @@ export default { this.$router.push({ name: 'help' }) } }, + /** @param {chatModels.DebugMsg} data */ + onDebugMsg(data) { + this.onAddText(new chatModels.AddTextMsg({ + authorName: 'blivechat', + authorType: constants.AUTHOR_TYPE_ADMIN, + content: data.content, + authorLevel: 60, + })) + }, filterTextMessage(data) { if (this.config.blockGiftDanmaku && data.isGiftDanmaku) {