@@ -90,7 +90,8 @@ class CallContext {
9090 this . setState ( { ...this . state , isLocalPreviewMicrophoneEnabled } ) ;
9191 }
9292
93- public setCallId ( callId : string | undefined ) : void {
93+ // This is the key to find current call object in client state
94+ public setCurrentCallId ( callId : string | undefined ) : void {
9495 this . callId = callId ;
9596 }
9697
@@ -170,6 +171,15 @@ export class AzureCommunicationCallAdapter implements CallAdapter {
170171 callClient . offStateChange ( onStateChange ) ;
171172 return ;
172173 }
174+
175+ // `updateClientState` searches for the current call from all the calls in the state using a cached `call.id`
176+ // from the call object. `call.id` can change during a call. We must update the cached `call.id` before
177+ // calling `updateClientState` so that we find the correct state object for the call even when `call.id`
178+ // has changed.
179+ // https://github.com/Azure/communication-ui-library/pull/1820
180+ if ( this . call ?. id ) {
181+ this . context . setCurrentCallId ( this . call . id ) ;
182+ }
173183 this . context . updateClientState ( clientState ) ;
174184 } ;
175185
@@ -293,7 +303,7 @@ export class AzureCommunicationCallAdapter implements CallAdapter {
293303 this . unsubscribeCallEvents ( ) ;
294304 this . call = undefined ;
295305 this . handlers = createDefaultCallingHandlers ( this . callClient , this . callAgent , this . deviceManager , undefined ) ;
296- this . context . setCallId ( undefined ) ;
306+ this . context . setCurrentCallId ( undefined ) ;
297307 // Resync state after callId is set
298308 this . context . updateClientState ( this . callClient . getState ( ) ) ;
299309 this . stopCamera ( ) ;
@@ -393,7 +403,7 @@ export class AzureCommunicationCallAdapter implements CallAdapter {
393403
394404 private processNewCall ( call : Call ) : void {
395405 this . call = call ;
396- this . context . setCallId ( call . id ) ;
406+ this . context . setCurrentCallId ( call . id ) ;
397407
398408 // Resync state after callId is set
399409 this . context . updateClientState ( this . callClient . getState ( ) ) ;
@@ -491,9 +501,6 @@ export class AzureCommunicationCallAdapter implements CallAdapter {
491501 }
492502
493503 private callIdChanged ( ) : void {
494- this . context . setCallId ( this . call ?. id ) ;
495- // Resync state after callId is set
496- this . context . updateClientState ( this . callClient . getState ( ) ) ;
497504 this . emitter . emit ( 'callIdChanged' , { callId : this . callIdChanged . bind ( this ) } ) ;
498505 }
499506
0 commit comments