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); }