From ff7f221ad285ca1994fc3a780aa8183df2de3e99 Mon Sep 17 00:00:00 2001 From: Matvei Andrienko Date: Tue, 21 Jan 2025 16:17:30 +0100 Subject: [PATCH] fix: restore calling state if SFU connection fails during join (#1652) It's important to reset calling state back to its pre-join state if joining flow fails. We already do this if join request fails, but we also need to do it if SFU connection fails. --- packages/client/src/Call.ts | 43 +++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/packages/client/src/Call.ts b/packages/client/src/Call.ts index 685591c4e..8bf99c0c6 100644 --- a/packages/client/src/Call.ts +++ b/packages/client/src/Call.ts @@ -849,25 +849,32 @@ export class Call { const preferredSubscribeOptions = !isReconnecting ? this.getPreferredSubscribeOptions() : []; - const { callState, fastReconnectDeadlineSeconds, publishOptions } = - await sfuClient.join({ - subscriberSdp, - publisherSdp, - clientDetails, - fastReconnect: performingFastReconnect, - reconnectDetails, - preferredPublishOptions, - preferredSubscribeOptions, - }); - this.currentPublishOptions = publishOptions; - this.fastReconnectDeadlineSeconds = fastReconnectDeadlineSeconds; - if (callState) { - this.state.updateFromSfuCallState( - callState, - sfuClient.sessionId, - reconnectDetails, - ); + try { + const { callState, fastReconnectDeadlineSeconds, publishOptions } = + await sfuClient.join({ + subscriberSdp, + publisherSdp, + clientDetails, + fastReconnect: performingFastReconnect, + reconnectDetails, + preferredPublishOptions, + preferredSubscribeOptions, + }); + + this.currentPublishOptions = publishOptions; + this.fastReconnectDeadlineSeconds = fastReconnectDeadlineSeconds; + if (callState) { + this.state.updateFromSfuCallState( + callState, + sfuClient.sessionId, + reconnectDetails, + ); + } + } catch (error) { + // restore the previous call state if the join-flow fails + this.state.setCallingState(callingState); + throw error; } }