From 76e24a8daaf2cfb4023c0eafd005a2a1359e3405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E8=8D=A3=E5=9F=BA?= Date: Thu, 29 Sep 2022 08:55:10 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BF=AE=E6=AD=A3]=20=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E8=81=8A=E5=A4=A9=E5=AE=A4=E6=97=B6=20HTTP=20=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E9=A1=BA=E5=BA=8F=E9=97=AE=E9=A2=98;=20=E5=BC=83?= =?UTF-8?q?=E7=94=A8=20HTTP=20=E6=94=B9=E4=B8=BA=E7=BA=AF=20WS;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat-window/chat-window.component.ts | 25 +++++++++++++++++-- src/signalRChat.ts | 5 +++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/app/home/commonComponents/chat-window/chat-window.component.ts b/src/app/home/commonComponents/chat-window/chat-window.component.ts index 0776366..ce1be90 100644 --- a/src/app/home/commonComponents/chat-window/chat-window.component.ts +++ b/src/app/home/commonComponents/chat-window/chat-window.component.ts @@ -40,7 +40,7 @@ export class ChatWindowComponent implements OnInit { await signalR.initSR(this.taskId); - await this.getAllMessages(); + // 接收来自中心的消息 (signalR.SR as any).on('receiveMessage', (message: any) => { console.log('收到消息', message) @@ -50,7 +50,28 @@ export class ChatWindowComponent implements OnInit { this.scrollToBottom() }, 0); } - }) + }); + + // 接收群组信息 + (signalR.SR as any).on('receiveGroup', (group: any) => { + try { + console.log('收到群组信息', group) + this.isLoading = true + this.MessagesList = group.taskChatMessages || []; + this.members = group.members || []; + this.members.forEach(item => { + this.chatName += (item.name || '') + ' ' + }); + setTimeout(() => { + this.scrollToBottom() + }, 0); + this.isLoading = false + console.log('chatName', this.chatName) + console.log('消息列表', this.MessagesList) + } catch (error) { + console.log(error, 'error') + } + }); } /** * 消息列表 diff --git a/src/signalRChat.ts b/src/signalRChat.ts index 8aee813..11e954c 100644 --- a/src/signalRChat.ts +++ b/src/signalRChat.ts @@ -26,7 +26,10 @@ export default { try { await that.SR.start(); console.assert(that.SR.state === signalR.HubConnectionState.Connected) - await that.SR.send("joinRoom", id).then(() => console.log("已加入聊天室")); + // await that.SR.send("joinRoom", id).then(() => console.log("已加入聊天室")); + await that.SR.send("joinRoom", id); + console.log("已加入聊天室") + } catch (err) { setTimeout(start, 5000); }