From 68fd680ec414afcee0b53b9048b53ffe58e69304 Mon Sep 17 00:00:00 2001 From: John Smith Date: Sat, 13 Apr 2024 18:05:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E4=B8=80=E4=B8=AA=E6=88=BF=E9=97=B4?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=95=B0=E8=B6=85=E8=BF=87=E4=B8=8A=E9=99=90?= =?UTF-8?q?=E6=97=B6=E6=8A=A5=E8=87=B4=E5=91=BD=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/chat.py | 1 + frontend/src/api/chat/ChatClientDirectOpenLive.js | 9 ++++++--- frontend/src/api/chat/ChatClientOfficialBase/index.js | 8 ++++---- frontend/src/api/chat/models.js | 1 + frontend/src/views/Room.vue | 2 +- services/chat.py | 8 ++++++++ 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/api/chat.py b/api/chat.py index 470be83..93c628d 100644 --- a/api/chat.py +++ b/api/chat.py @@ -44,6 +44,7 @@ class ContentType(enum.IntEnum): class FatalErrorType(enum.IntEnum): AUTH_CODE_ERROR = 1 TOO_MANY_RETRIES = 2 + TOO_MANY_CONNECTIONS = 3 def make_message_body(cmd, data): diff --git a/frontend/src/api/chat/ChatClientDirectOpenLive.js b/frontend/src/api/chat/ChatClientDirectOpenLive.js index b640f2e..bae289d 100644 --- a/frontend/src/api/chat/ChatClientDirectOpenLive.js +++ b/frontend/src/api/chat/ChatClientDirectOpenLive.js @@ -45,8 +45,11 @@ export default class ChatClientDirectOpenLive extends ChatClientOfficialBase { if (res.code === 7007) { // 身份码错误 throw new chatModels.ChatClientFatalError(chatModels.FATAL_ERROR_TYPE_AUTH_CODE_ERROR, msg) + } else if (res.code === 7010) { + // 同一个房间连接数超过上限 + throw new chatModels.ChatClientFatalError(chatModels.FATAL_ERROR_TYPE_TOO_MANY_CONNECTIONS, msg) } - throw Error(msg) + throw new Error(msg) } } catch (e) { console.error('startGame failed:', e) @@ -87,7 +90,7 @@ export default class ChatClientDirectOpenLive extends ChatClientOfficialBase { })).data // 项目已经关闭了也算成功 if ([0, 7000, 7003].indexOf(res.code) === -1) { - throw Error(`code=${res.code}, message=${res.message}, request_id=${res.request_id}`) + throw new Error(`code=${res.code}, message=${res.message}, request_id=${res.request_id}`) } } catch (e) { console.error('endGame failed:', e) @@ -125,7 +128,7 @@ export default class ChatClientDirectOpenLive extends ChatClientOfficialBase { this.needInitRoom = true this.discardWebsocket() } - throw Error(`code=${res.code}, message=${res.message}, request_id=${res.request_id}`) + throw new Error(`code=${res.code}, message=${res.message}, request_id=${res.request_id}`) } } catch (e) { console.error('sendGameHeartbeat failed:', e) diff --git a/frontend/src/api/chat/ChatClientOfficialBase/index.js b/frontend/src/api/chat/ChatClientOfficialBase/index.js index 38af21d..7a0f191 100644 --- a/frontend/src/api/chat/ChatClientOfficialBase/index.js +++ b/frontend/src/api/chat/ChatClientOfficialBase/index.js @@ -69,7 +69,7 @@ export default class ChatClientOfficialBase { } async initRoom() { - throw Error('Not implemented') + throw new Error('Not implemented') } makePacket(data, operation) { @@ -95,7 +95,7 @@ export default class ChatClientOfficialBase { } sendAuth() { - throw Error('Not implemented') + throw new Error('Not implemented') } addDebugMsg(content) { @@ -139,13 +139,13 @@ export default class ChatClientOfficialBase { if (!res) { window.setTimeout(() => this.onWsClose(), 0) - throw Error('initRoom failed') + throw new Error('initRoom failed') } this.needInitRoom = false } getWsUrl() { - throw Error('Not implemented') + throw new Error('Not implemented') } onWsOpen() { diff --git a/frontend/src/api/chat/models.js b/frontend/src/api/chat/models.js index 22e0ed0..96d7e2a 100644 --- a/frontend/src/api/chat/models.js +++ b/frontend/src/api/chat/models.js @@ -114,6 +114,7 @@ export class UpdateTranslationMsg { export const FATAL_ERROR_TYPE_AUTH_CODE_ERROR = 1 export const FATAL_ERROR_TYPE_TOO_MANY_RETRIES = 2 +export const FATAL_ERROR_TYPE_TOO_MANY_CONNECTIONS = 3 export class ChatClientFatalError extends Error { constructor(type, message) { diff --git a/frontend/src/views/Room.vue b/frontend/src/views/Room.vue index ba69c93..f26959a 100644 --- a/frontend/src/views/Room.vue +++ b/frontend/src/views/Room.vue @@ -349,7 +349,7 @@ export default { onFatalError(error) { this.$message.error({ message: error.toString(), - duration: 10 * 1000 + duration: 30 * 1000 }) this.onAddText(new chatModels.AddTextMsg({ authorName: 'blivechat', diff --git a/services/chat.py b/services/chat.py index c4b3df7..02444d8 100644 --- a/services/chat.py +++ b/services/chat.py @@ -278,6 +278,14 @@ class OpenLiveClient(blivedm.OpenLiveClient): 'type': api.chat.FatalErrorType.AUTH_CODE_ERROR, 'msg': str(e) }) + elif e.code == 7010: + # 同一个房间连接数超过上限 + room = client_room_manager.get_room(self.room_key) + if room is not None: + room.send_cmd_data(api.chat.Command.FATAL_ERROR, { + 'type': api.chat.FatalErrorType.TOO_MANY_CONNECTIONS, + 'msg': str(e) + }) return False return self._parse_start_game(data['data'])