Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve reconnect logic. #654

Merged
merged 5 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Contributor Author

@cloudwebrtc cloudwebrtc Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to emit a SignalDisconnectedEvent event here, because connect or resumeConnect/restartConnect will catch the ConnectException and take the correct follow-up action.

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
Loading