Skip to content

Commit

Permalink
fix: improve reconnect logic. (#654)
Browse files Browse the repository at this point in the history
* fix: improve reconnect logic.

* update.

* change default rendererMode to texture.

* When there is no internet connection, enter reconnect attempt.

* update.
  • Loading branch information
cloudwebrtc authored Dec 17, 2024
1 parent a0ee074 commit 6ae73bc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/src/core/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
events.emit(const EngineFullRestartingEvent());

if (signalClient.connectionState == ConnectionState.connected) {
await signalClient.sendLeave();
await signalClient.cleanUp();
}

await publisher?.dispose();
Expand Down
10 changes: 5 additions & 5 deletions lib/src/core/signal_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class SignalClient extends Disposable with EventsEmittable<SignalEvent> {
String? participantSid;

List<ConnectivityResult> _connectivityResult = [];
StreamSubscription<List<ConnectivityResult>>? connectivitySubscription;
StreamSubscription<List<ConnectivityResult>>? _connectivitySubscription;

Future<bool> networkIsAvailable() async {
// Skip check for web or flutter test
Expand All @@ -81,7 +81,8 @@ class SignalClient extends Disposable with EventsEmittable<SignalEvent> {
await cleanUp();
await events.dispose();
if (!kIsWeb && !lkPlatformIsTest()) {
await connectivitySubscription?.cancel();
await _connectivitySubscription?.cancel();
_connectivitySubscription = null;
}
});
}
Expand All @@ -96,7 +97,8 @@ class SignalClient extends Disposable with EventsEmittable<SignalEvent> {
}) async {
if (!kIsWeb && !lkPlatformIsTest()) {
_connectivityResult = await Connectivity().checkConnectivity();
connectivitySubscription = Connectivity()
await _connectivitySubscription?.cancel();
_connectivitySubscription = Connectivity()
.onConnectivityChanged
.listen((List<ConnectivityResult> result) {
if (_connectivityResult != result) {
Expand All @@ -116,8 +118,6 @@ class SignalClient extends Disposable with EventsEmittable<SignalEvent> {

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);
}
Expand Down
1 change: 0 additions & 1 deletion lib/src/types/other.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ enum DisconnectReason {
joinFailure,
disconnected,
signalingConnectionFailure,
noInternetConnection,
reconnectAttemptsExceeded,
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/widgets/video_track_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 6ae73bc

Please sign in to comment.