Skip to content

Commit c44f861

Browse files
authored
upgrade to connectivity plus 6.x. (#503)
* upgrade to connectivity plus 6.x. * fix. * fix.
1 parent eb11920 commit c44f861

File tree

5 files changed

+28
-36
lines changed

5 files changed

+28
-36
lines changed

lib/src/core/engine.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
687687
logger.fine('no internet connection, waiting...');
688688
await signalClient.events.waitFor<SignalConnectivityChangedEvent>(
689689
duration: connectOptions.timeouts.connection * 10,
690-
filter: (event) => event.state != ConnectivityResult.none,
690+
filter: (event) => !event.state.contains(ConnectivityResult.none),
691691
onTimeout: () => throw ConnectException(
692692
'attemptReconnect: Timed out waiting for SignalConnectivityChangedEvent'),
693693
);

lib/src/core/signal_client.dart

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,17 @@ class SignalClient extends Disposable with EventsEmittable<SignalEvent> {
5858
int _pingCount = 0;
5959
String? participantSid;
6060

61-
ConnectivityResult? _connectivityResult;
62-
StreamSubscription<ConnectivityResult>? connectivitySubscription;
61+
List<ConnectivityResult> _connectivityResult = [];
62+
StreamSubscription<List<ConnectivityResult>>? connectivitySubscription;
6363

6464
Future<bool> networkIsAvailable() async {
6565
// Skip check for web or flutter test
6666
if (kIsWeb || lkPlatformIsTest()) {
6767
return true;
6868
}
6969
_connectivityResult = await Connectivity().checkConnectivity();
70-
return _connectivityResult != ConnectivityResult.none;
70+
return _connectivityResult.isNotEmpty &&
71+
!_connectivityResult.contains(ConnectivityResult.none);
7172
}
7273

7374
@internal
@@ -95,27 +96,25 @@ class SignalClient extends Disposable with EventsEmittable<SignalEvent> {
9596
}) async {
9697
if (!kIsWeb && !lkPlatformIsTest()) {
9798
_connectivityResult = await Connectivity().checkConnectivity();
98-
connectivitySubscription ??= Connectivity()
99+
connectivitySubscription = Connectivity()
99100
.onConnectivityChanged
100-
.listen((ConnectivityResult result) {
101+
.listen((List<ConnectivityResult> result) {
101102
if (_connectivityResult != result) {
102-
if (result == ConnectivityResult.none) {
103+
if (result.contains(ConnectivityResult.none)) {
103104
logger.warning('lost connectivity');
104105
} else {
105106
logger.info(
106-
'Connectivity changed, ${_connectivityResult!.name} => ${result.name}');
107+
'Connectivity changed, ${_connectivityResult} => ${result}');
107108
}
108-
109109
events.emit(SignalConnectivityChangedEvent(
110-
oldState: _connectivityResult!,
110+
oldState: _connectivityResult,
111111
state: result,
112112
));
113-
114113
_connectivityResult = result;
115114
}
116115
});
117116

118-
if (_connectivityResult == ConnectivityResult.none) {
117+
if (_connectivityResult.contains(ConnectivityResult.none)) {
119118
logger.warning('no internet connection');
120119
events.emit(SignalDisconnectedEvent(
121120
reason: DisconnectReason.noInternetConnection));

lib/src/internal/events.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ class SignalReconnectResponseEvent with SignalEvent, InternalEvent {
143143

144144
@internal
145145
class SignalConnectivityChangedEvent with SignalEvent, InternalEvent {
146-
final ConnectivityResult oldState;
147-
final ConnectivityResult state;
146+
final List<ConnectivityResult> oldState;
147+
final List<ConnectivityResult> state;
148148
const SignalConnectivityChangedEvent({
149149
required this.oldState,
150150
required this.state,

lib/src/utils.dart

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -336,27 +336,20 @@ class Utils {
336336
var connectivityResult = await (Connectivity().checkConnectivity());
337337
// wifi, wired, cellular, vpn, empty if not known
338338
String networkType = 'empty';
339-
switch (connectivityResult) {
340-
case ConnectivityResult.mobile:
341-
networkType = 'cellular';
342-
break;
343-
case ConnectivityResult.wifi:
344-
networkType = 'wifi';
345-
break;
346-
case ConnectivityResult.bluetooth:
347-
networkType = 'bluetooth';
348-
break;
349-
case ConnectivityResult.ethernet:
350-
networkType = 'wired';
351-
break;
352-
case ConnectivityResult.other:
353-
case ConnectivityResult.vpn:
354-
//TODO: will livekit-server handle vpn and other types correctly?
355-
// networkType = 'vpn';
356-
break;
357-
case ConnectivityResult.none:
358-
networkType = 'empty';
359-
break;
339+
if (connectivityResult.contains(ConnectivityResult.none)) {
340+
networkType = 'empty';
341+
} else if (connectivityResult.contains(ConnectivityResult.mobile)) {
342+
networkType = 'cellular';
343+
} else if (connectivityResult.contains(ConnectivityResult.wifi)) {
344+
networkType = 'wifi';
345+
} else if (connectivityResult.contains(ConnectivityResult.ethernet)) {
346+
networkType = 'wired';
347+
} else if (connectivityResult.contains(ConnectivityResult.bluetooth)) {
348+
networkType = 'bluetooth';
349+
} else if (connectivityResult.contains(ConnectivityResult.other)) {
350+
networkType = 'other';
351+
} else if (connectivityResult.contains(ConnectivityResult.vpn)) {
352+
networkType = 'vpn';
360353
}
361354
return networkType;
362355
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ dependencies:
2929
sdk: flutter
3030
async: ^2.9.0
3131
collection: '>=1.16.0'
32-
connectivity_plus: ^5.0.0
32+
connectivity_plus: ^6.0.2
3333
cryptography: ^2.0.5
3434
fixnum: ^1.0.1
3535
meta: ^1.8.0

0 commit comments

Comments
 (0)