From 6ae73bcdb723703d1415de887218ef478dd9cda5 Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Tue, 17 Dec 2024 10:11:22 +0800 Subject: [PATCH] fix: improve reconnect logic. (#654) * fix: improve reconnect logic. * update. * change default rendererMode to texture. * When there is no internet connection, enter reconnect attempt. * update. --- lib/src/core/engine.dart | 2 +- lib/src/core/signal_client.dart | 10 +++++----- lib/src/types/other.dart | 1 - lib/src/widgets/video_track_renderer.dart | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/src/core/engine.dart b/lib/src/core/engine.dart index 42d1db76..e2d2be85 100644 --- a/lib/src/core/engine.dart +++ b/lib/src/core/engine.dart @@ -814,7 +814,7 @@ class Engine extends Disposable with EventsEmittable { events.emit(const EngineFullRestartingEvent()); if (signalClient.connectionState == ConnectionState.connected) { - await signalClient.sendLeave(); + await signalClient.cleanUp(); } await publisher?.dispose(); diff --git a/lib/src/core/signal_client.dart b/lib/src/core/signal_client.dart index e13801bc..2f84d91f 100644 --- a/lib/src/core/signal_client.dart +++ b/lib/src/core/signal_client.dart @@ -59,7 +59,7 @@ class SignalClient extends Disposable with EventsEmittable { String? participantSid; List _connectivityResult = []; - StreamSubscription>? connectivitySubscription; + StreamSubscription>? _connectivitySubscription; Future networkIsAvailable() async { // Skip check for web or flutter test @@ -81,7 +81,8 @@ class SignalClient extends Disposable with EventsEmittable { await cleanUp(); await events.dispose(); if (!kIsWeb && !lkPlatformIsTest()) { - await connectivitySubscription?.cancel(); + await _connectivitySubscription?.cancel(); + _connectivitySubscription = null; } }); } @@ -96,7 +97,8 @@ class SignalClient extends Disposable with EventsEmittable { }) async { if (!kIsWeb && !lkPlatformIsTest()) { _connectivityResult = await Connectivity().checkConnectivity(); - connectivitySubscription = Connectivity() + await _connectivitySubscription?.cancel(); + _connectivitySubscription = Connectivity() .onConnectivityChanged .listen((List result) { if (_connectivityResult != result) { @@ -116,8 +118,6 @@ class SignalClient extends Disposable with EventsEmittable { if (_connectivityResult.contains(ConnectivityResult.none)) { logger.warning('no internet connection'); - events.emit(SignalDisconnectedEvent( - reason: DisconnectReason.noInternetConnection)); throw ConnectException('no internet connection', reason: ConnectionErrorReason.InternalError, statusCode: 503); } diff --git a/lib/src/types/other.dart b/lib/src/types/other.dart index b176eb0a..c6fdcbbd 100644 --- a/lib/src/types/other.dart +++ b/lib/src/types/other.dart @@ -115,7 +115,6 @@ enum DisconnectReason { joinFailure, disconnected, signalingConnectionFailure, - noInternetConnection, reconnectAttemptsExceeded, } diff --git a/lib/src/widgets/video_track_renderer.dart b/lib/src/widgets/video_track_renderer.dart index 6fba7707..c2787203 100644 --- a/lib/src/widgets/video_track_renderer.dart +++ b/lib/src/widgets/video_track_renderer.dart @@ -51,7 +51,7 @@ class VideoTrackRenderer extends StatefulWidget { this.track, { this.fit = rtc.RTCVideoViewObjectFit.RTCVideoViewObjectFitContain, this.mirrorMode = VideoViewMirrorMode.auto, - this.renderMode = VideoRenderMode.auto, + this.renderMode = VideoRenderMode.texture, Key? key, }) : super(key: key);