From 873ce3d9408f9ff5270f280995b8764064fdb071 Mon Sep 17 00:00:00 2001 From: zhangzheng Date: Thu, 12 Mar 2026 12:46:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AA=E8=AF=BB=E8=A7=92=E6=A0=87=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebApp/client/public/onebyone/index.html | 4 +++- WebApp/client/public/onebyone/renderer.js | 6 ++++++ WebApp/client/public/onebyone/store.js | 26 +++++++++++++++++------ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/WebApp/client/public/onebyone/index.html b/WebApp/client/public/onebyone/index.html index 9dd954a..d1f34ef 100644 --- a/WebApp/client/public/onebyone/index.html +++ b/WebApp/client/public/onebyone/index.html @@ -492,8 +492,10 @@
-
diff --git a/WebApp/client/public/onebyone/renderer.js b/WebApp/client/public/onebyone/renderer.js index 8e58db3..05f05d8 100644 --- a/WebApp/client/public/onebyone/renderer.js +++ b/WebApp/client/public/onebyone/renderer.js @@ -127,6 +127,12 @@ class UIRenderer { break; case 'SIDEBAR_TOGGLE': this.renderSidebar(changes.isOpen); + // 当侧边栏打开时,重置未读消息计数 + if (changes.isOpen) { + this.renderUnreadCount(0); + } else{ + this.renderUnreadCount(changes.unreadCount); + } break; case 'NETWORK_CHANGE': this.renderNetworkStatus(changes.quality); diff --git a/WebApp/client/public/onebyone/store.js b/WebApp/client/public/onebyone/store.js index 7595a21..001c5bc 100644 --- a/WebApp/client/public/onebyone/store.js +++ b/WebApp/client/public/onebyone/store.js @@ -367,11 +367,12 @@ class CallStateManager { }; // 初始化 RenderStreaming 实例后 this.renderstreaming.onMessage = (data) => { - console.log('收到聊天消息:', data); + console.log('收到聊天:', data); if (data.type === 'chat-message') { - // 处理聊天消息 - // 添加到消息列表并更新UI - store.addMessage(data.message); + // 处理聊天 + // 添加到列表并更新UI + + this.handleChatMessage(data.message); } else if (data.type === 'on-message') { } @@ -447,7 +448,7 @@ class CallStateManager { } - // 更新远端媒体状态 (由 WebSocket 消息触发) + // 更新远端媒体状态 (由 WebSocket 触发) updateRemoteMedia(mediaState) { this.state.session.remoteUser.mediaState = { ...this.state.session.remoteUser.mediaState, @@ -456,13 +457,14 @@ class CallStateManager { this.notify({ type: 'REMOTE_MEDIA_CHANGE', mediaState }); } - // 添加消息 + // 添加 addMessage(message) { this.state.messages.push(message); // 如果侧边栏关闭且不是自己发的,增加未读 if (!this.state.isSidebarOpen && !message.isSelf) { this.state.unreadCount++; + this.notify({ type: 'SIDEBAR_TOGGLE', unreadCount: this.state.unreadCount }); } this.notify({ type: 'NEW_MESSAGE', message, unreadCount: this.state.unreadCount }); @@ -810,6 +812,18 @@ class CallStateManager { } } + // 处理接收到的聊天 + handleChatMessage(data) { + console.log('处理聊天:', data); + store.addMessage(data); + const isImage = data.message && data.message.startsWith('data:image/'); + const messageType = isImage ? 'file' : 'text'; + + + // 显示通知 + showNotification(`${senderName}: ${data.message.substring(0, 20)}${data.message.length > 20 ? '...' : ''}`); + } + // 发送媒体状态到服务器 emitMediaStateChange() { const payload = {