@@ -9,16 +9,16 @@ let connection;
99// create a SignalR service object that exposes methods to interact with the hub
1010export const signalr = {
1111
12- /** @type {function } */
12+ /** @type {import('$typedefs').OnConversationInitialized } */
1313 onConversationInitFromClient : ( ) => { } ,
1414
15- /** @type {function } */
15+ /** @type {import('$typedefs').OnMessageReceived } */
1616 onMessageReceivedFromClient : ( ) => { } ,
1717
18- /** @type {function } */
18+ /** @type {import('$typedefs').OnMessageReceived } */
1919 onMessageReceivedFromCsr : ( ) => { } ,
2020
21- /** @type {function } */
21+ /** @type {import('$typedefs').OnMessageReceived } */
2222 onMessageReceivedFromAssistant : ( ) => { } ,
2323
2424 // start the connection
@@ -43,27 +43,35 @@ export const signalr = {
4343 // register handlers for the hub methods
4444 connection . on ( 'OnConversationInitFromClient' , ( conversation ) => {
4545 // do something when receiving a message, such as updating the UI or showing a notification
46- console . log ( `[OnConversationInitFromClient] ${ conversation . id } : ${ conversation . title } ` ) ;
47- this . onConversationInitFromClient ( conversation ) ;
46+ if ( conversationId === conversation . id ) {
47+ console . log ( `[OnConversationInitFromClient] ${ conversation . id } : ${ conversation . title } ` ) ;
48+ this . onConversationInitFromClient ( conversation ) ;
49+ }
4850 } ) ;
4951
5052 // register handlers for the hub methods
5153 connection . on ( 'OnMessageReceivedFromClient' , ( message ) => {
5254 // do something when receiving a message, such as updating the UI or showing a notification
53- console . log ( `[OnMessageReceivedFromClient] ${ message . sender . role } : ${ message . text } ` ) ;
54- this . onMessageReceivedFromClient ( message ) ;
55+ if ( conversationId === message . conversation_id ) {
56+ console . log ( `[OnMessageReceivedFromClient] ${ message . sender . role } : ${ message . text } ` ) ;
57+ this . onMessageReceivedFromClient ( message ) ;
58+ }
5559 } ) ;
5660
5761 connection . on ( 'OnMessageReceivedFromCsr' , ( message ) => {
5862 // do something when receiving a message, such as updating the UI or showing a notification
59- console . log ( `[OnMessageReceivedFromCsr] ${ message . role } : ${ message . content } ` ) ;
60- this . onMessageReceivedFromCsr ( message ) ;
63+ if ( conversationId === message . conversation_id ) {
64+ console . log ( `[OnMessageReceivedFromCsr] ${ message . role } : ${ message . content } ` ) ;
65+ this . onMessageReceivedFromCsr ( message ) ;
66+ }
6167 } ) ;
6268
6369 connection . on ( 'OnMessageReceivedFromAssistant' , ( message ) => {
6470 // do something when receiving a message, such as updating the UI or showing a notification
65- console . log ( `[OnMessageReceivedFromAssistant] ${ message . sender . role } : ${ message . text } ` ) ;
66- this . onMessageReceivedFromAssistant ( message ) ;
71+ if ( conversationId === message . conversation_id ) {
72+ console . log ( `[OnMessageReceivedFromAssistant] ${ message . sender . role } : ${ message . text } ` ) ;
73+ this . onMessageReceivedFromAssistant ( message ) ;
74+ }
6775 } ) ;
6876 } ,
6977
0 commit comments