Skip to content

Commit

Permalink
feat: network type detection. (#156)
Browse files Browse the repository at this point in the history
* feat: network type detection.

* fix unit test.

* chore: Make the network type consistent with the protocol.
  • Loading branch information
cloudwebrtc authored Aug 25, 2022
1 parent d66147b commit ef81d7b
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 3 deletions.
2 changes: 2 additions & 0 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import FlutterMacOS
import Foundation

import connectivity_plus_macos
import device_info_plus_macos
import flutter_webrtc
import livekit_client
import path_provider_macos
import shared_preferences_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
FlutterWebRTCPlugin.register(with: registry.registrar(forPlugin: "FlutterWebRTCPlugin"))
LiveKitPlugin.register(with: registry.registrar(forPlugin: "LiveKitPlugin"))
Expand Down
14 changes: 12 additions & 2 deletions example/macos/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
PODS:
- connectivity_plus_macos (0.0.1):
- FlutterMacOS
- ReachabilitySwift
- device_info_plus_macos (0.0.1):
- FlutterMacOS
- flutter_webrtc (0.9.4):
- FlutterMacOS
- WebRTC-SDK (= 104.5112.03)
- FlutterMacOS (1.0.0)
- livekit_client (1.1.0):
- livekit_client (1.1.1):
- FlutterMacOS
- WebRTC-SDK (~> 104.5112.03)
- path_provider_macos (0.0.1):
- FlutterMacOS
- ReachabilitySwift (5.0.0)
- shared_preferences_macos (0.0.1):
- FlutterMacOS
- WebRTC-SDK (104.5112.03)

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`)
- flutter_webrtc (from `Flutter/ephemeral/.symlinks/plugins/flutter_webrtc/macos`)
- FlutterMacOS (from `Flutter/ephemeral`)
Expand All @@ -24,9 +29,12 @@ DEPENDENCIES:

SPEC REPOS:
trunk:
- ReachabilitySwift
- WebRTC-SDK

EXTERNAL SOURCES:
connectivity_plus_macos:
:path: Flutter/ephemeral/.symlinks/plugins/connectivity_plus_macos/macos
device_info_plus_macos:
:path: Flutter/ephemeral/.symlinks/plugins/device_info_plus_macos/macos
flutter_webrtc:
Expand All @@ -41,11 +49,13 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_macos/macos

SPEC CHECKSUMS:
connectivity_plus_macos: f6e86fd000e971d361e54b5afcadc8c8fa773308
device_info_plus_macos: 1ad388a1ef433505c4038e7dd9605aadd1e2e9c7
flutter_webrtc: 45cd8f5825bb32054e817708bf343ceff2c9cab8
FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424
livekit_client: d229104e54e72ec7b5ffad62c14117297b5bbb23
livekit_client: 42da9111e214db06de13279b12a70210294d03dc
path_provider_macos: 3c0c3b4b0d4a76d2bf989a913c2de869c5641a19
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
shared_preferences_macos: a64dc611287ed6cbe28fd1297898db1336975727
WebRTC-SDK: 9f50fb5a410edc38e6fbb865fe940e3010bc8e7e

Expand Down
65 changes: 64 additions & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.1"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -43,6 +50,48 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
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:
dependency: transitive
description:
Expand All @@ -57,6 +106,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.7"
dbus:
dependency: transitive
description:
name: dbus
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.3"
device_info_plus:
dependency: transitive
description:
Expand Down Expand Up @@ -225,7 +281,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.1.0-hotifx"
version: "1.1.1"
logging:
dependency: "direct main"
description:
Expand Down Expand Up @@ -261,6 +317,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
nm:
dependency: transitive
description:
name: nm
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.0"
path:
dependency: transitive
description:
Expand Down
3 changes: 3 additions & 0 deletions example/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

#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 <livekit_client/live_kit_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
FlutterWebRTCPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterWebRTCPlugin"));
LiveKitPluginRegisterWithRegistrar(
Expand Down
1 change: 1 addition & 0 deletions example/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
connectivity_plus_windows
flutter_webrtc
livekit_client
)
Expand Down
31 changes: 31 additions & 0 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:math' as math;

import 'package:collection/collection.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
Expand Down Expand Up @@ -160,6 +161,7 @@ class Utils {
pathSegments.addAll(lastSegments);

final clientInfo = await _clientInfo();
final networkType = await getNetworkType();

return uri.replace(
scheme: validate ? httpScheme : wsScheme,
Expand All @@ -172,6 +174,7 @@ class Utils {
'protocol': connectOptions.protocolVersion.toStringValue(),
'sdk': 'flutter',
'version': LiveKitClient.version,
'network': networkType,
// client info
if (clientInfo != null) ...{
if (clientInfo.hasOs()) 'os': clientInfo.os,
Expand Down Expand Up @@ -286,6 +289,34 @@ class Utils {
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
static double findEvenScaleDownBy(
VideoDimensions sourceDimensions,
Expand Down
70 changes: 70 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,48 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
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:
dependency: transitive
description:
Expand Down Expand Up @@ -120,6 +162,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.7"
dbus:
dependency: transitive
description:
name: dbus
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.4"
device_info_plus:
dependency: "direct main"
description:
Expand Down Expand Up @@ -296,6 +345,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "5.2.0"
nm:
dependency: transitive
description:
name: nm
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.0"
package_config:
dependency: transitive
description:
Expand Down Expand Up @@ -359,6 +415,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.6"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.0"
platform:
dependency: transitive
description:
Expand Down Expand Up @@ -511,6 +574,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0+1"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.0"
yaml:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies:
flutter_webrtc: 0.9.4
dart_webrtc: 1.0.7
device_info_plus: ^3.2.3
connectivity_plus: ^2.3.6+1

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit ef81d7b

Please sign in to comment.