feat: network type detection. (#156)

* feat: network type detection.

* fix unit test.

* chore: Make the network type consistent with the protocol.
This commit is contained in:
CloudWebRTC
2022-08-25 18:30:43 +08:00
committed by GitHub
parent d66147b840
commit ef81d7b1ff
8 changed files with 184 additions and 3 deletions
@@ -5,6 +5,7 @@
import FlutterMacOS import FlutterMacOS
import Foundation import Foundation
import connectivity_plus_macos
import device_info_plus_macos import device_info_plus_macos
import flutter_webrtc import flutter_webrtc
import livekit_client import livekit_client
@@ -12,6 +13,7 @@ import path_provider_macos
import shared_preferences_macos import shared_preferences_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin")) DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
FlutterWebRTCPlugin.register(with: registry.registrar(forPlugin: "FlutterWebRTCPlugin")) FlutterWebRTCPlugin.register(with: registry.registrar(forPlugin: "FlutterWebRTCPlugin"))
LiveKitPlugin.register(with: registry.registrar(forPlugin: "LiveKitPlugin")) LiveKitPlugin.register(with: registry.registrar(forPlugin: "LiveKitPlugin"))
+12 -2
View File
@@ -1,20 +1,25 @@
PODS: PODS:
- connectivity_plus_macos (0.0.1):
- FlutterMacOS
- ReachabilitySwift
- device_info_plus_macos (0.0.1): - device_info_plus_macos (0.0.1):
- FlutterMacOS - FlutterMacOS
- flutter_webrtc (0.9.4): - flutter_webrtc (0.9.4):
- FlutterMacOS - FlutterMacOS
- WebRTC-SDK (= 104.5112.03) - WebRTC-SDK (= 104.5112.03)
- FlutterMacOS (1.0.0) - FlutterMacOS (1.0.0)
- livekit_client (1.1.0): - livekit_client (1.1.1):
- FlutterMacOS - FlutterMacOS
- WebRTC-SDK (~> 104.5112.03) - WebRTC-SDK (~> 104.5112.03)
- path_provider_macos (0.0.1): - path_provider_macos (0.0.1):
- FlutterMacOS - FlutterMacOS
- ReachabilitySwift (5.0.0)
- shared_preferences_macos (0.0.1): - shared_preferences_macos (0.0.1):
- FlutterMacOS - FlutterMacOS
- WebRTC-SDK (104.5112.03) - WebRTC-SDK (104.5112.03)
DEPENDENCIES: DEPENDENCIES:
- connectivity_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/connectivity_plus_macos/macos`)
- device_info_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/device_info_plus_macos/macos`) - device_info_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/device_info_plus_macos/macos`)
- flutter_webrtc (from `Flutter/ephemeral/.symlinks/plugins/flutter_webrtc/macos`) - flutter_webrtc (from `Flutter/ephemeral/.symlinks/plugins/flutter_webrtc/macos`)
- FlutterMacOS (from `Flutter/ephemeral`) - FlutterMacOS (from `Flutter/ephemeral`)
@@ -24,9 +29,12 @@ DEPENDENCIES:
SPEC REPOS: SPEC REPOS:
trunk: trunk:
- ReachabilitySwift
- WebRTC-SDK - WebRTC-SDK
EXTERNAL SOURCES: EXTERNAL SOURCES:
connectivity_plus_macos:
:path: Flutter/ephemeral/.symlinks/plugins/connectivity_plus_macos/macos
device_info_plus_macos: device_info_plus_macos:
:path: Flutter/ephemeral/.symlinks/plugins/device_info_plus_macos/macos :path: Flutter/ephemeral/.symlinks/plugins/device_info_plus_macos/macos
flutter_webrtc: flutter_webrtc:
@@ -41,11 +49,13 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_macos/macos :path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_macos/macos
SPEC CHECKSUMS: SPEC CHECKSUMS:
connectivity_plus_macos: f6e86fd000e971d361e54b5afcadc8c8fa773308
device_info_plus_macos: 1ad388a1ef433505c4038e7dd9605aadd1e2e9c7 device_info_plus_macos: 1ad388a1ef433505c4038e7dd9605aadd1e2e9c7
flutter_webrtc: 45cd8f5825bb32054e817708bf343ceff2c9cab8 flutter_webrtc: 45cd8f5825bb32054e817708bf343ceff2c9cab8
FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424 FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424
livekit_client: d229104e54e72ec7b5ffad62c14117297b5bbb23 livekit_client: 42da9111e214db06de13279b12a70210294d03dc
path_provider_macos: 3c0c3b4b0d4a76d2bf989a913c2de869c5641a19 path_provider_macos: 3c0c3b4b0d4a76d2bf989a913c2de869c5641a19
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
shared_preferences_macos: a64dc611287ed6cbe28fd1297898db1336975727 shared_preferences_macos: a64dc611287ed6cbe28fd1297898db1336975727
WebRTC-SDK: 9f50fb5a410edc38e6fbb865fe940e3010bc8e7e WebRTC-SDK: 9f50fb5a410edc38e6fbb865fe940e3010bc8e7e
+64 -1
View File
@@ -1,6 +1,13 @@
# Generated by pub # Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile # See https://dart.dev/tools/pub/glossary#lockfile
packages: packages:
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.1"
async: async:
dependency: transitive dependency: transitive
description: description:
@@ -43,6 +50,48 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.16.0" version: "1.16.0"
connectivity_plus:
dependency: transitive
description:
name: connectivity_plus
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.6+1"
connectivity_plus_linux:
dependency: transitive
description:
name: connectivity_plus_linux
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
connectivity_plus_macos:
dependency: transitive
description:
name: connectivity_plus_macos
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.4"
connectivity_plus_platform_interface:
dependency: transitive
description:
name: connectivity_plus_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.1"
connectivity_plus_web:
dependency: transitive
description:
name: connectivity_plus_web
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.3"
connectivity_plus_windows:
dependency: transitive
description:
name: connectivity_plus_windows
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.2"
crypto: crypto:
dependency: transitive dependency: transitive
description: description:
@@ -57,6 +106,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.7" version: "1.0.7"
dbus:
dependency: transitive
description:
name: dbus
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.3"
device_info_plus: device_info_plus:
dependency: transitive dependency: transitive
description: description:
@@ -225,7 +281,7 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "1.1.0-hotifx" version: "1.1.1"
logging: logging:
dependency: "direct main" dependency: "direct main"
description: description:
@@ -261,6 +317,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.0" version: "1.0.0"
nm:
dependency: transitive
description:
name: nm
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.0"
path: path:
dependency: transitive dependency: transitive
description: description:
@@ -6,10 +6,13 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <connectivity_plus_windows/connectivity_plus_windows_plugin.h>
#include <flutter_webrtc/flutter_web_r_t_c_plugin.h> #include <flutter_webrtc/flutter_web_r_t_c_plugin.h>
#include <livekit_client/live_kit_plugin.h> #include <livekit_client/live_kit_plugin.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
FlutterWebRTCPluginRegisterWithRegistrar( FlutterWebRTCPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterWebRTCPlugin")); registry->GetRegistrarForPlugin("FlutterWebRTCPlugin"));
LiveKitPluginRegisterWithRegistrar( LiveKitPluginRegisterWithRegistrar(
@@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
connectivity_plus_windows
flutter_webrtc flutter_webrtc
livekit_client livekit_client
) )
+31
View File
@@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:math' as math; import 'dart:math' as math;
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:device_info_plus/device_info_plus.dart'; import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc; import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
@@ -160,6 +161,7 @@ class Utils {
pathSegments.addAll(lastSegments); pathSegments.addAll(lastSegments);
final clientInfo = await _clientInfo(); final clientInfo = await _clientInfo();
final networkType = await getNetworkType();
return uri.replace( return uri.replace(
scheme: validate ? httpScheme : wsScheme, scheme: validate ? httpScheme : wsScheme,
@@ -172,6 +174,7 @@ class Utils {
'protocol': connectOptions.protocolVersion.toStringValue(), 'protocol': connectOptions.protocolVersion.toStringValue(),
'sdk': 'flutter', 'sdk': 'flutter',
'version': LiveKitClient.version, 'version': LiveKitClient.version,
'network': networkType,
// client info // client info
if (clientInfo != null) ...{ if (clientInfo != null) ...{
if (clientInfo.hasOs()) 'os': clientInfo.os, if (clientInfo.hasOs()) 'os': clientInfo.os,
@@ -286,6 +289,34 @@ class Utils {
return result; return result;
} }
@internal
static FutureOr<String> getNetworkType() async {
if (lkPlatformIsTest()) {
return 'wifi';
}
var connectivityResult = await (Connectivity().checkConnectivity());
// wifi, wired, cellular, vpn, empty if not known
String networkType = 'empty';
switch (connectivityResult) {
case ConnectivityResult.mobile:
networkType = 'cellular';
break;
case ConnectivityResult.wifi:
networkType = 'wifi';
break;
case ConnectivityResult.bluetooth:
networkType = 'bluetooth';
break;
case ConnectivityResult.ethernet:
networkType = 'wired';
break;
case ConnectivityResult.none:
networkType = 'empty';
break;
}
return networkType;
}
@internal @internal
static double findEvenScaleDownBy( static double findEvenScaleDownBy(
VideoDimensions sourceDimensions, VideoDimensions sourceDimensions,
+70
View File
@@ -92,6 +92,48 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.16.0" version: "1.16.0"
connectivity_plus:
dependency: "direct main"
description:
name: connectivity_plus
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.6+1"
connectivity_plus_linux:
dependency: transitive
description:
name: connectivity_plus_linux
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
connectivity_plus_macos:
dependency: transitive
description:
name: connectivity_plus_macos
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.4"
connectivity_plus_platform_interface:
dependency: transitive
description:
name: connectivity_plus_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.1"
connectivity_plus_web:
dependency: transitive
description:
name: connectivity_plus_web
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.3"
connectivity_plus_windows:
dependency: transitive
description:
name: connectivity_plus_windows
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.2"
convert: convert:
dependency: transitive dependency: transitive
description: description:
@@ -120,6 +162,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.7" version: "1.0.7"
dbus:
dependency: transitive
description:
name: dbus
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.4"
device_info_plus: device_info_plus:
dependency: "direct main" dependency: "direct main"
description: description:
@@ -296,6 +345,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "5.2.0" version: "5.2.0"
nm:
dependency: transitive
description:
name: nm
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.0"
package_config: package_config:
dependency: transitive dependency: transitive
description: description:
@@ -359,6 +415,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.6" version: "2.0.6"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.0"
platform: platform:
dependency: transitive dependency: transitive
description: description:
@@ -511,6 +574,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.2.0+1" version: "0.2.0+1"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.0"
yaml: yaml:
dependency: transitive dependency: transitive
description: description:
+1
View File
@@ -25,6 +25,7 @@ dependencies:
flutter_webrtc: 0.9.4 flutter_webrtc: 0.9.4
dart_webrtc: 1.0.7 dart_webrtc: 1.0.7
device_info_plus: ^3.2.3 device_info_plus: ^3.2.3
connectivity_plus: ^2.3.6+1
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: