@@ -631,29 +631,28 @@ public class Call(
631631 val sfuUrl = result.value.credentials.server.url
632632 val sfuWsUrl = result.value.credentials.server.wsEndpoint
633633 val iceServers = result.value.credentials.iceServers.map { it.toIceServer() }
634+ try {
635+ session = if (testInstanceProvider.rtcSessionCreator != null ) {
636+ testInstanceProvider.rtcSessionCreator!! .invoke()
637+ } else {
638+ RtcSession (
639+ sessionId = this .sessionId,
640+ apiKey = clientImpl.apiKey,
641+ lifecycle = clientImpl.coordinatorConnectionModule.lifecycle,
642+ client = client,
643+ call = this ,
644+ sfuUrl = sfuUrl,
645+ sfuWsUrl = sfuWsUrl,
646+ sfuToken = sfuToken,
647+ remoteIceServers = iceServers,
648+ powerManager = powerManager,
649+ )
650+ }
634651
635- session = if (testInstanceProvider.rtcSessionCreator != null ) {
636- testInstanceProvider.rtcSessionCreator!! .invoke()
637- } else {
638- RtcSession (
639- sessionId = this .sessionId,
640- apiKey = clientImpl.apiKey,
641- lifecycle = clientImpl.coordinatorConnectionModule.lifecycle,
642- client = client,
643- call = this ,
644- sfuUrl = sfuUrl,
645- sfuWsUrl = sfuWsUrl,
646- sfuToken = sfuToken,
647- remoteIceServers = iceServers,
648- powerManager = powerManager,
649- )
650- }
651-
652- session?.let {
653- state._connection .value = RealtimeConnection .Joined (it)
654- }
652+ session?.let {
653+ state._connection .value = RealtimeConnection .Joined (it)
654+ }
655655
656- try {
657656 session?.connect()
658657 } catch (e: Exception ) {
659658 return Failure (Error .GenericError (e.message ? : " RtcSession error occurred." ))
@@ -791,24 +790,31 @@ public class Call(
791790 )
792791 this .state.removeParticipant(prevSessionId)
793792 session.prepareRejoin()
794- this .session = RtcSession (
795- clientImpl,
796- reconnectAttepmts,
797- powerManager,
798- this ,
799- sessionId,
800- clientImpl.apiKey,
801- clientImpl.coordinatorConnectionModule.lifecycle,
802- cred.server.url,
803- cred.server.wsEndpoint,
804- cred.token,
805- cred.iceServers.map { ice ->
806- ice.toIceServer()
807- },
808- )
809- this .session?.connect(reconnectDetails, currentOptions)
810- session.cleanup()
811- monitorSession(joinResponse.value)
793+ try {
794+ this .session = RtcSession (
795+ clientImpl,
796+ reconnectAttepmts,
797+ powerManager,
798+ this ,
799+ sessionId,
800+ clientImpl.apiKey,
801+ clientImpl.coordinatorConnectionModule.lifecycle,
802+ cred.server.url,
803+ cred.server.wsEndpoint,
804+ cred.token,
805+ cred.iceServers.map { ice ->
806+ ice.toIceServer()
807+ },
808+ )
809+ this .session?.connect(reconnectDetails, currentOptions)
810+ session.cleanup()
811+ monitorSession(joinResponse.value)
812+ } catch (ex: Exception ) {
813+ logger.e(ex) {
814+ " [rejoin] Failed to join response with ex: ${ex.message} "
815+ }
816+ state._connection .value = RealtimeConnection .Failed (ex)
817+ }
812818 } else {
813819 logger.e {
814820 " [rejoin] Failed to get a join response ${joinResponse.errorOrNull()} "
@@ -847,27 +853,35 @@ public class Call(
847853 reconnect_attempt = reconnectAttepmts,
848854 )
849855 session.prepareRejoin()
850- val newSession = RtcSession (
851- clientImpl,
852- reconnectAttepmts,
853- powerManager,
854- this ,
855- sessionId,
856- clientImpl.apiKey,
857- clientImpl.coordinatorConnectionModule.lifecycle,
858- cred.server.url,
859- cred.server.wsEndpoint,
860- cred.token,
861- cred.iceServers.map { ice ->
862- ice.toIceServer()
863- },
864- )
865- val oldSession = this .session
866- this .session = newSession
867- this .session?.connect(reconnectDetails, currentOptions)
868- monitorSession(joinResponse.value)
869- oldSession?.leaveWithReason(" migrating" )
870- oldSession?.cleanup()
856+ try {
857+ val newSession = RtcSession (
858+ clientImpl,
859+ reconnectAttepmts,
860+ powerManager,
861+ this ,
862+ sessionId,
863+ clientImpl.apiKey,
864+ clientImpl.coordinatorConnectionModule.lifecycle,
865+ cred.server.url,
866+ cred.server.wsEndpoint,
867+ cred.token,
868+ cred.iceServers.map { ice ->
869+ ice.toIceServer()
870+ },
871+ )
872+ val oldSession = this .session
873+ this .session = newSession
874+ this .session?.connect(reconnectDetails, currentOptions)
875+ monitorSession(joinResponse.value)
876+ oldSession?.leaveWithReason(" migrating" )
877+ oldSession?.cleanup()
878+ } catch (ex: Exception ) {
879+ logger.e(ex) {
880+ " [switchSfu] Failed to join during " +
881+ " migration - Error ${ex.message} "
882+ }
883+ state._connection .value = RealtimeConnection .Failed (ex)
884+ }
871885 } else {
872886 logger.e {
873887 " [switchSfu] Failed to get a join response during " +
0 commit comments