@@ -56,7 +56,7 @@ function isIgnorableChatMessage(msg: ReceivedChatMessage | LegacyReceivedChatMes
5656const decodeLegacyMsg = ( message : Uint8Array ) =>
5757 JSON . parse ( new TextDecoder ( ) . decode ( message ) ) as LegacyReceivedChatMessage | ReceivedChatMessage ;
5858
59- const encodeLegacyMsg = ( message : LegacyReceivedChatMessage ) =>
59+ const encodeLegacyMsg = ( message : LegacyChatMessage ) =>
6060 new TextEncoder ( ) . encode ( JSON . stringify ( message ) ) ;
6161
6262export function setupChat ( room : Room , options ?: ChatOptions ) {
@@ -154,18 +154,30 @@ export function setupChat(room: Room, options?: ChatOptions) {
154154
155155 try {
156156 const info = await room . localParticipant . sendText ( message , options ) ;
157- const chatMsg : ReceivedChatMessage = {
157+
158+ const legacyChatMsg : LegacyChatMessage = {
158159 id : info . id ,
159160 timestamp : Date . now ( ) ,
160161 message,
161- from : room . localParticipant ,
162+ } ;
163+
164+ const chatMsg : ChatMessage = {
165+ ...legacyChatMsg ,
162166 attachedFiles : options . attachments ,
163167 } ;
164- messageSubject . next ( chatMsg ) ;
165- const encodedLegacyMsg = finalMessageEncoder ( {
168+
169+ const receivedChatMsg : ReceivedChatMessage = {
166170 ...chatMsg ,
171+ from : room . localParticipant ,
172+ } ;
173+
174+ messageSubject . next ( receivedChatMsg ) ;
175+
176+ const encodedLegacyMsg = finalMessageEncoder ( {
177+ ...legacyChatMsg ,
167178 ignoreLegacy : serverSupportsDataStreams ( ) ,
168179 } ) ;
180+
169181 try {
170182 await sendMessage ( room . localParticipant , encodedLegacyMsg , {
171183 reliable : true ,
@@ -174,7 +186,8 @@ export function setupChat(room: Room, options?: ChatOptions) {
174186 } catch ( error ) {
175187 log . info ( 'could not send message in legacy chat format' , error ) ;
176188 }
177- return chatMsg ;
189+
190+ return receivedChatMsg ;
178191 } finally {
179192 isSending$ . next ( false ) ;
180193 }
0 commit comments