From 52978dd15ff121528c33aefc6f6829e3daf0f853 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Tue, 13 Feb 2024 00:19:36 +0200 Subject: [PATCH 1/4] wip using bonsoir for mdns search --- .vscode/launch.json | 11 ++ .../android/app/src/main/AndroidManifest.xml | 2 + example/lib/main.dart | 28 ++-- example/lib/pages/mdns_scanner_page.dart | 62 +++++++++ .../Flutter/GeneratedPluginRegistrant.swift | 2 + example/pubspec.lock | 122 ++++++++++++++---- example/pubspec.yaml | 67 +--------- .../flutter/generated_plugin_registrant.cc | 3 + .../windows/flutter/generated_plugins.cmake | 1 + lib/src/configure_flutter.dart | 2 + .../mdns_scanner_service_flutter_impl.dart | 90 +++++++++++++ .../port_scanner_service_flutter_impl.dart | 2 +- pubspec.yaml | 58 ++------- {lib/src => test}/fake_http_overrides.dart | 2 +- test/host_scan_flutter_test.dart | 2 +- test/port_scan_flutter_test.dart | 2 +- 16 files changed, 300 insertions(+), 156 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 example/lib/pages/mdns_scanner_page.dart create mode 100644 lib/src/services_impls/mdns_scanner_service_flutter_impl.dart rename {lib/src => test}/fake_http_overrides.dart (92%) diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..ba2ca1c --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,11 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "example", + "cwd": "example", + "request": "launch", + "type": "dart" + } + ] +} \ No newline at end of file diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 19b862e..4e4aae7 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,4 +1,6 @@ + + const MdnsScannerPage(), + ), + ); + }, + child: const Text('mDNS Scanner'), + ), ], ), ); diff --git a/example/lib/pages/mdns_scanner_page.dart b/example/lib/pages/mdns_scanner_page.dart new file mode 100644 index 0000000..81a7e60 --- /dev/null +++ b/example/lib/pages/mdns_scanner_page.dart @@ -0,0 +1,62 @@ +import 'package:flutter/material.dart'; +import 'package:network_tools_flutter/network_tools_flutter.dart'; + +class MdnsScannerPage extends StatefulWidget { + const MdnsScannerPage({super.key}); + + @override + State createState() => _MdnsScannerPageState(); +} + +class _MdnsScannerPageState extends State { + List activeHosts = []; + + @override + void initState() { + super.initState(); + searchMdns(); + } + + searchMdns() async { + NetInterface? netInt = await NetInterface.localInterface(); + if (netInt == null) { + return; + } + List hosts = await MdnsScannerService.instance + .searchMdnsDevices(forceUseOfSavedSrvRecordList: true); + + setState(() { + activeHosts.addAll(hosts); + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + backgroundColor: Theme.of(context).colorScheme.inversePrimary, + title: const Text('mDNS Devices'), + ), + body: Center( + child: activeHosts.isEmpty + ? const CircularProgressIndicator() + : ListView.builder( + itemCount: activeHosts.length, + itemBuilder: (context, index) { + final ActiveHost activeHost = activeHosts[index]; + return ListTile( + title: Text(activeHost.weirdHostName), + subtitle: FutureBuilder( + future: activeHost.mdnsInfo, + builder: (BuildContext context, mdnsInfoResult) => + mdnsInfoResult.hasData + ? Text(mdnsInfoResult.data?.mdnsName ?? '') + : const SizedBox(), + ), + ); + }, + ), + ), + ); + } +} diff --git a/example/macos/Flutter/GeneratedPluginRegistrant.swift b/example/macos/Flutter/GeneratedPluginRegistrant.swift index e777c67..5849f84 100644 --- a/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,8 +5,10 @@ import FlutterMacOS import Foundation +import bonsoir_darwin import path_provider_foundation func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + SwiftBonsoirPlugin.register(with: registry.registrar(forPlugin: "SwiftBonsoirPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) } diff --git a/example/pubspec.lock b/example/pubspec.lock index 5daaeba..9ccb7b9 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -17,6 +17,54 @@ packages: url: "https://pub.dev" source: hosted version: "2.11.0" + bonsoir: + dependency: transitive + description: + name: bonsoir + sha256: "7dd7f87f154c0a16ef569b685aa6d0556d4cc281ae7565420d9f639febefa06e" + url: "https://pub.dev" + source: hosted + version: "5.1.1" + bonsoir_android: + dependency: transitive + description: + name: bonsoir_android + sha256: d317c099f9c0a558d3e9e7400b9003f588cd685f1695bb09c36ee76fc79c83c3 + url: "https://pub.dev" + source: hosted + version: "5.1.1" + bonsoir_darwin: + dependency: transitive + description: + name: bonsoir_darwin + sha256: eb45bafe5003352137e07d3b5a122a7250b507095f456f6612de3e7ddaba5e0d + url: "https://pub.dev" + source: hosted + version: "5.1.1" + bonsoir_linux: + dependency: transitive + description: + name: bonsoir_linux + sha256: "24cb232f311acb2e293f0fddcde134eddd51ecfdaf5622883fc087096138fbc0" + url: "https://pub.dev" + source: hosted + version: "5.1.1" + bonsoir_platform_interface: + dependency: transitive + description: + name: bonsoir_platform_interface + sha256: e87a9e26f428be50b934ddfd2bdc0a663d6f2c437ab0052793daaa0dd5aec5c7 + url: "https://pub.dev" + source: hosted + version: "5.1.1" + bonsoir_windows: + dependency: transitive + description: + name: bonsoir_windows + sha256: "8f7dfe941319e89842423322fe1836a6fa9ef35871d644dd8a44c15373f7924d" + url: "https://pub.dev" + source: hosted + version: "5.1.3" boolean_selector: dependency: transitive description: @@ -85,10 +133,18 @@ packages: dependency: transitive description: name: dart_ping_ios - sha256: "5d27e4d3e7fccbc123bbb5c2803f5cb5933aea2f91b80ee1151d852f51b20cf3" + sha256: "17df1b369331ec6c30a91a51db64ac8feed47fad71e444208de06edf2a22415f" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + dbus: + dependency: transitive + description: + name: dbus + sha256: "365c771ac3b0e58845f39ec6deebc76e3276aa9922b0cc60840712094d9047ac" url: "https://pub.dev" source: hosted - version: "4.0.1" + version: "0.7.10" fake_async: dependency: transitive description: @@ -167,10 +223,10 @@ packages: dependency: transitive description: name: intl - sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d" + sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf url: "https://pub.dev" source: hosted - version: "0.18.1" + version: "0.19.0" json_annotation: dependency: transitive description: @@ -253,26 +309,26 @@ packages: dependency: "direct main" description: name: path_provider - sha256: a1aa8aaa2542a6bc57e381f132af822420216c80d4781f7aa085ca3229208aaa + sha256: b27217933eeeba8ff24845c34003b003b2b22151de3c908d0e679e8fe1aa078b url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" path_provider_android: dependency: transitive description: name: path_provider_android - sha256: "6b8b19bd80da4f11ce91b2d1fb931f3006911477cec227cce23d3253d80df3f1" + sha256: "477184d672607c0a3bf68fbbf601805f92ef79c82b64b4d6eb318cbca4c48668" url: "https://pub.dev" source: hosted - version: "2.2.0" + version: "2.2.2" path_provider_foundation: dependency: transitive description: name: path_provider_foundation - sha256: "19314d595120f82aca0ba62787d58dde2cc6b5df7d2f0daf72489e38d1b57f2d" + sha256: "5a7999be66e000916500be4f15a3633ebceb8302719b47b9cc49ce924125350f" url: "https://pub.dev" source: hosted - version: "2.3.1" + version: "2.3.2" path_provider_linux: dependency: transitive description: @@ -285,10 +341,10 @@ packages: dependency: transitive description: name: path_provider_platform_interface - sha256: "94b1e0dd80970c1ce43d5d4e050a9918fce4f4a775e6142424c30a29a363265c" + sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334" url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" path_provider_windows: dependency: transitive description: @@ -297,22 +353,30 @@ packages: url: "https://pub.dev" source: hosted version: "2.2.1" + petitparser: + dependency: transitive + description: + name: petitparser + sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27 + url: "https://pub.dev" + source: hosted + version: "6.0.2" platform: dependency: transitive description: name: platform - sha256: ae68c7bfcd7383af3629daafb32fb4e8681c7154428da4febcff06200585f102 + sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec" url: "https://pub.dev" source: hosted - version: "3.1.2" + version: "3.1.4" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface - sha256: da3fdfeccc4d4ff2da8f8c556704c08f912542c5fb3cf2233ed75372384a034d + sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02" url: "https://pub.dev" source: hosted - version: "2.1.6" + version: "2.1.8" process_run: dependency: transitive description: @@ -333,10 +397,10 @@ packages: dependency: transitive description: name: sembast - sha256: "85ff944434f7b566fdc388be4f85b23e954736b7d6e51f965f4f419d966c15b1" + sha256: "9a9f0c7aca07043fef857b8b365f41592e48832b61462292699b57978e241c11" url: "https://pub.dev" source: hosted - version: "3.5.0+1" + version: "3.6.0" sky_engine: dependency: transitive description: flutter @@ -378,10 +442,10 @@ packages: dependency: transitive description: name: synchronized - sha256: "5fcbd27688af6082f5abd611af56ee575342c30e87541d0245f7ff99faa02c60" + sha256: "539ef412b170d65ecdafd780f924e5be3f60032a1128df156adad6c5b373d558" url: "https://pub.dev" source: hosted - version: "3.1.0" + version: "3.1.0+1" term_glyph: dependency: transitive description: @@ -442,18 +506,26 @@ packages: dependency: transitive description: name: win32 - sha256: c97defd418eef4ec88c0d1652cdce84b9f7b63dd7198e266d06ac1710d527067 + sha256: "464f5674532865248444b4c3daca12bd9bf2d7c47f759ce2617986e7229494a8" url: "https://pub.dev" source: hosted - version: "5.0.8" + version: "5.2.0" xdg_directories: dependency: transitive description: name: xdg_directories - sha256: "589ada45ba9e39405c198fe34eb0f607cddb2108527e658136120892beac46d2" + sha256: faea9dee56b520b55a566385b84f2e8de55e7496104adada9962e0bd11bcff1d + url: "https://pub.dev" + source: hosted + version: "1.0.4" + xml: + dependency: transitive + description: + name: xml + sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226 url: "https://pub.dev" source: hosted - version: "1.0.3" + version: "6.5.0" yaml: dependency: transitive description: @@ -464,4 +536,4 @@ packages: version: "3.1.2" sdks: dart: ">=3.2.0 <4.0.0" - flutter: ">=3.7.0" + flutter: ">=3.10.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 73c95aa..fa0b9f6 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,38 +1,16 @@ name: example description: A new Flutter project. -# The following line prevents the package from being accidentally published to -# pub.dev using `flutter pub publish`. This is preferred for private packages. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev +publish_to: 'none' -# The following defines the version and build number for your application. -# A version number is three numbers separated by dots, like 1.2.43 -# followed by an optional build number separated by a +. -# Both the version and the builder number may be overridden in flutter -# build by specifying --build-name and --build-number, respectively. -# In Android, build-name is used as versionName while build-number used as versionCode. -# Read more about Android versioning at https://developer.android.com/studio/publish/versioning -# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. -# Read more about iOS versioning at -# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -# In Windows, build-name is used as the major, minor, and patch parts -# of the product and file versions while build-number is used as the build suffix. version: 1.0.0+1 environment: sdk: '>=3.1.0 <4.0.0' -# Dependencies specify other packages that your package needs in order to work. -# To automatically upgrade your package dependencies to the latest versions -# consider running `flutter pub upgrade --major-versions`. Alternatively, -# dependencies can be manually updated by changing the version numbers below to -# the latest version available on pub.dev. To see which dependencies have newer -# versions available, run `flutter pub outdated`. dependencies: flutter: sdk: flutter - # The following adds the Cupertino Icons font to your application. - # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 # Debugging and error logging. logging: ^1.2.0 @@ -44,51 +22,8 @@ dev_dependencies: flutter_test: sdk: flutter - # The "flutter_lints" package below contains a set of recommended lints to - # encourage good coding practices. The lint set provided by the package is - # activated in the `analysis_options.yaml` file located at the root of your - # package. See that file for information about deactivating specific lint - # rules and activating additional ones. flutter_lints: ^2.0.0 -# For information on the generic Dart part of this file, see the -# following page: https://dart.dev/tools/pub/pubspec - -# The following section is specific to Flutter packages. flutter: - # The following line ensures that the Material Icons font is - # included with your application, so that you can use the icons in - # the material Icons class. uses-material-design: true - - # To add assets to your application, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg - - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/assets-and-images/#resolution-aware - - # For details regarding adding assets from package dependencies, see - # https://flutter.dev/assets-and-images/#from-packages - - # To add custom fonts to your application, add a fonts section here, - # in this "flutter" section. Each entry in this list should have a - # "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts from package dependencies, - # see https://flutter.dev/custom-fonts/#from-packages diff --git a/example/windows/flutter/generated_plugin_registrant.cc b/example/windows/flutter/generated_plugin_registrant.cc index 8b6d468..3473264 100644 --- a/example/windows/flutter/generated_plugin_registrant.cc +++ b/example/windows/flutter/generated_plugin_registrant.cc @@ -6,6 +6,9 @@ #include "generated_plugin_registrant.h" +#include void RegisterPlugins(flutter::PluginRegistry* registry) { + BonsoirWindowsPluginCApiRegisterWithRegistrar( + registry->GetRegistrarForPlugin("BonsoirWindowsPluginCApi")); } diff --git a/example/windows/flutter/generated_plugins.cmake b/example/windows/flutter/generated_plugins.cmake index b93c4c3..a5cde7e 100644 --- a/example/windows/flutter/generated_plugins.cmake +++ b/example/windows/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + bonsoir_windows ) list(APPEND FLUTTER_FFI_PLUGIN_LIST diff --git a/lib/src/configure_flutter.dart b/lib/src/configure_flutter.dart index 8ee969f..530e3b7 100644 --- a/lib/src/configure_flutter.dart +++ b/lib/src/configure_flutter.dart @@ -7,6 +7,7 @@ import 'package:network_tools/src/services/arp_service.dart'; // ignore: implementation_imports import 'package:network_tools/src/services/impls/arp_service_sembast_impl.dart'; import 'package:network_tools_flutter/src/services_impls/host_scanner_service_flutter_impl.dart'; +import 'package:network_tools_flutter/src/services_impls/mdns_scanner_service_flutter_impl.dart'; import 'package:network_tools_flutter/src/services_impls/port_scanner_service_flutter_impl.dart'; Future configureNetworkToolsFlutter( @@ -32,6 +33,7 @@ Future configureNetworkToolsFlutter( ARPServiceSembastImpl(); HostScannerServiceFlutterImpl(); PortScannerServiceFlutterImpel(); + MdnsScannerServiceFlutterImpl(); final arpService = await ARPService.instance.open(); await arpService.buildTable(); diff --git a/lib/src/services_impls/mdns_scanner_service_flutter_impl.dart b/lib/src/services_impls/mdns_scanner_service_flutter_impl.dart new file mode 100644 index 0000000..3c4fec9 --- /dev/null +++ b/lib/src/services_impls/mdns_scanner_service_flutter_impl.dart @@ -0,0 +1,90 @@ +import 'package:bonsoir/bonsoir.dart'; +// ignore: depend_on_referenced_packages +import 'package:multicast_dns/multicast_dns.dart'; +import 'package:network_tools/network_tools.dart'; +import 'package:universal_io/io.dart'; +// ignore: implementation_imports +import 'package:network_tools/src/services/impls/mdns_scanner_service_impl.dart'; + +class MdnsScannerServiceFlutterImpl extends MdnsScannerServiceImpl { + // Using bonsoire untill https://github.com/flutter/flutter/issues/52733 is fix + // After that we can delete this method and let network tool use of multicast_dns handle all this logic + @override + Future> findingMdnsWithAddress( + String serviceType, + ) async { + List listOfActiveHost = []; + + try { + BonsoirDiscovery discovery = BonsoirDiscovery(type: serviceType); + await discovery.ready; + Stream? discoverStream = discovery.eventStream; + if (discoverStream == null) { + return []; + } + + Future.delayed(const Duration(milliseconds: 1)).then((value) { + discovery.start(); + }); + + Future.delayed(const Duration(seconds: 5)).then((value) { + discovery.stop(); + }); + + await for (BonsoirDiscoveryEvent event in discoverStream) { + if (event.type == BonsoirDiscoveryEventType.discoveryServiceFound) { + event.service?.resolve(discovery.serviceResolver); + continue; + } else if (event.type == + BonsoirDiscoveryEventType.discoveryServiceResolved) { + } else { + continue; + } + + ActiveHost? activeHost = convert(event); + if (activeHost == null) { + continue; + } + listOfActiveHost.add(activeHost); + } + } catch (e) { + print('Error searching mdns $e'); + } + return listOfActiveHost; + } + + ActiveHost? convert(BonsoirDiscoveryEvent event) { + final port = event.service?.port; + final host = event.service?.toJson()['service.ip'] ?? + event.service?.toJson()['service.host']; + + String name = [ + event.service?.attributes['md'], + event.service?.attributes['fn'], + ].whereType().join(' - '); + if (name.isEmpty) { + name = event.service!.name; + } + + if (port == null || host == null) { + return null; + } + + final MdnsInfo mdnsInfo = MdnsInfo( + srvResourceRecord: SrvResourceRecord( + name, + 0, + target: host, + port: port, + priority: 1, + weight: 1, + ), + ptrResourceRecord: PtrResourceRecord(name, 0, domainName: ''), + ); + + return ActiveHost( + internetAddress: InternetAddress(host), + mdnsInfoVar: mdnsInfo, + ); + } +} diff --git a/lib/src/services_impls/port_scanner_service_flutter_impl.dart b/lib/src/services_impls/port_scanner_service_flutter_impl.dart index 151dd3a..a4b94cd 100644 --- a/lib/src/services_impls/port_scanner_service_flutter_impl.dart +++ b/lib/src/services_impls/port_scanner_service_flutter_impl.dart @@ -1,5 +1,5 @@ import 'dart:async'; -import 'dart:io'; +import 'package:universal_io/io.dart'; import 'package:dart_ping_ios/dart_ping_ios.dart'; import 'package:network_tools/network_tools.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index 38b9d57..7680f93 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,8 +5,7 @@ issue_tracker: https://github.com/osociety/network_tools_flutter/issues repository: https://github.com/osociety/network_tools_flutter environment: - sdk: ">=2.17.6 <4.0.0" - flutter: ">=1.17.0" + sdk: ">=3.2.0 <4.0.0" platforms: android: @@ -31,62 +30,29 @@ dependencies: sdk: flutter # Multi-platform network ping utility. - dart_ping: ^9.0.0 - dart_ping_ios: ^4.0.0 + dart_ping: ^9.0.1 + dart_ping_ios: ^4.0.2 fake_http_client: ^1.0.0 flutter_isolate: ^2.0.4 # Debugging and error logging. logging: ^1.2.0 # Deal with internationalized/localized messages and more. - intl: ^0.18.0 + intl: ^0.19.0 # network_tools: ^4.0.3 network_tools: - git: - url: "https://github.com/guyluz11/network_tools.git" - ref: "abstracting_services" + # git: + # url: "https://github.com/guyluz11/network_tools.git" + # ref: "abstracting_services" + path: '../network_tools' path_provider: ^2.1.1 - universal_io: ^2.2.0 + universal_io: ^2.2.2 + bonsoir: ^5.1.8 dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^2.0.0 + flutter_lints: ^3.0.1 # Standalone generator and watcher for Dart - build_runner: ^2.4.6 + build_runner: ^2.4.7 -# For information on the generic Dart part of this file, see the -# following page: https://dart.dev/tools/pub/pubspec - -# The following section is specific to Flutter packages. flutter: - - # To add assets to your package, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg - # - # For details regarding assets in packages, see - # https://flutter.dev/assets-and-images/#from-packages - # - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/assets-and-images/#resolution-aware - - # To add custom fonts to your package, add a fonts section here, - # in this "flutter" section. Each entry in this list should have a - # "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts in packages, see - # https://flutter.dev/custom-fonts/#from-packages diff --git a/lib/src/fake_http_overrides.dart b/test/fake_http_overrides.dart similarity index 92% rename from lib/src/fake_http_overrides.dart rename to test/fake_http_overrides.dart index 2ab0456..89a22dc 100644 --- a/lib/src/fake_http_overrides.dart +++ b/test/fake_http_overrides.dart @@ -1,4 +1,4 @@ -import 'dart:io'; +import 'package:universal_io/io.dart'; import 'package:fake_http_client/fake_http_client.dart'; diff --git a/test/host_scan_flutter_test.dart b/test/host_scan_flutter_test.dart index e6fff69..9e440e6 100644 --- a/test/host_scan_flutter_test.dart +++ b/test/host_scan_flutter_test.dart @@ -1,6 +1,6 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:network_tools_flutter/network_tools_flutter.dart'; -import 'package:network_tools_flutter/src/fake_http_overrides.dart'; +import 'fake_http_overrides.dart'; import 'package:universal_io/io.dart'; void main() { diff --git a/test/port_scan_flutter_test.dart b/test/port_scan_flutter_test.dart index 261995d..7b49d0f 100644 --- a/test/port_scan_flutter_test.dart +++ b/test/port_scan_flutter_test.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'package:flutter_test/flutter_test.dart'; -import 'package:network_tools_flutter/src/fake_http_overrides.dart'; +import 'fake_http_overrides.dart'; import 'package:universal_io/io.dart'; import 'package:network_tools_flutter/network_tools_flutter.dart'; From 28da02cb967ebe987f760efc4a3af8119d3a9194 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Thu, 15 Feb 2024 17:13:56 +0200 Subject: [PATCH 2/4] Progress for iOS support --- README.md | 25 +- example/android/app/build.gradle | 2 +- .../android/app/src/main/AndroidManifest.xml | 1 + example/lib/main.dart | 2 +- .../{ => mdns_search}/mdns_scanner_page.dart | 34 +-- .../lib/pages/mdns_search/mdns_widget.dart | 91 ++++++ .../Flutter/GeneratedPluginRegistrant.swift | 4 +- example/pubspec.lock | 136 ++++----- .../flutter/generated_plugin_registrant.cc | 6 +- .../windows/flutter/generated_plugins.cmake | 2 +- lib/src/configure_flutter.dart | 3 +- .../mdns_scanner_service_flutter_impl.dart | 284 ++++++++++++++---- pubspec.yaml | 9 +- 13 files changed, 439 insertions(+), 160 deletions(-) rename example/lib/pages/{ => mdns_search}/mdns_scanner_page.dart (55%) create mode 100644 example/lib/pages/mdns_search/mdns_widget.dart diff --git a/README.md b/README.md index 2a17e90..c73cc2a 100644 --- a/README.md +++ b/README.md @@ -28,4 +28,27 @@ And initialize the pacakge in the main function await configureNetworkToolsFlutter((await getApplicationDocumentsDirectory()).path); ``` -From here please follow the documentation of [network_tools](https://pub.dev/packages/network_tools) as they are the same. \ No newline at end of file +From here please follow the documentation of [network_tools](https://pub.dev/packages/network_tools) as they are the same. + + +## mDNS search + +For mDNS search on android make sure your min Android API level is 21 and add the following permissiongs to the manifest file + +``` + + +``` + +And for iOS add permissions to the Info.plist (replace service type with your own): + +``` +NSLocalNetworkUsageDescription +Required to discover local network devices +NSBonjourServices + + _http._tcp + + +``` + diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 53af1f4..85f0605 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -45,7 +45,7 @@ android { applicationId "org.fsociety.network_tools_flutter_example.example" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. - minSdkVersion flutter.minSdkVersion + minSdkVersion 21 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 4e4aae7..99969a7 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ + { - List activeHosts = []; + List? activeHosts; @override void initState() { @@ -26,7 +27,11 @@ class _MdnsScannerPageState extends State { .searchMdnsDevices(forceUseOfSavedSrvRecordList: true); setState(() { - activeHosts.addAll(hosts); + if (activeHosts == null) { + activeHosts = hosts; + } else { + activeHosts!.addAll(hosts); + } }); } @@ -38,24 +43,15 @@ class _MdnsScannerPageState extends State { title: const Text('mDNS Devices'), ), body: Center( - child: activeHosts.isEmpty + child: activeHosts == null ? const CircularProgressIndicator() - : ListView.builder( - itemCount: activeHosts.length, - itemBuilder: (context, index) { - final ActiveHost activeHost = activeHosts[index]; - return ListTile( - title: Text(activeHost.weirdHostName), - subtitle: FutureBuilder( - future: activeHost.mdnsInfo, - builder: (BuildContext context, mdnsInfoResult) => - mdnsInfoResult.hasData - ? Text(mdnsInfoResult.data?.mdnsName ?? '') - : const SizedBox(), - ), - ); - }, - ), + : activeHosts!.isEmpty + ? const SizedBox() + : ListView.builder( + itemCount: activeHosts!.length, + itemBuilder: (context, index) => + MdnsSearchWidget(activeHost: activeHosts![index]), + ), ), ); } diff --git a/example/lib/pages/mdns_search/mdns_widget.dart b/example/lib/pages/mdns_search/mdns_widget.dart new file mode 100644 index 0000000..25ad431 --- /dev/null +++ b/example/lib/pages/mdns_search/mdns_widget.dart @@ -0,0 +1,91 @@ +import 'package:flutter/material.dart'; +import 'package:network_tools/src/models/active_host.dart'; +import 'package:network_tools_flutter/network_tools_flutter.dart'; + +class MdnsSearchWidget extends StatefulWidget { + const MdnsSearchWidget({ + super.key, + required this.activeHost, + }); + + final ActiveHost activeHost; + + @override + State createState() => _MdnsSearchWidgetState(); +} + +class _MdnsSearchWidgetState extends State { + @override + initState() { + super.initState(); + initialzeActiveHost(); + } + + MdnsInfo? mdnsInfo; + bool mdnsInfoFound = false; + + String? hostName; + bool hostNameFound = false; + + String? deviceName; + bool deviceNameFound = false; + + String? macAddress; + bool macAddressFound = false; + + initialzeActiveHost() { + widget.activeHost.mdnsInfo.then((value) { + setState(() { + mdnsInfo = value; + mdnsInfoFound = true; + }); + }); + + widget.activeHost.hostName.then((value) { + setState(() { + hostName = value; + hostNameFound = true; + }); + }); + + widget.activeHost.deviceName.then((value) { + setState(() { + deviceName = value; + deviceNameFound = true; + }); + }); + + widget.activeHost.getMacAddress().then((value) { + setState(() { + macAddress = value; + macAddressFound = true; + }); + }); + } + + @override + Widget build(BuildContext context) { + if (!mdnsInfoFound || + !hostNameFound || + !deviceNameFound || + !macAddressFound) { + return const SizedBox(); + } + + return ListTile( + title: Text(widget.activeHost.weirdHostName), + subtitle: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('mDNS: ${mdnsInfo?.mdnsName}'), + const SizedBox(height: 5), + Text('Device: $deviceName'), + const SizedBox(height: 5), + Text('Mac: $macAddress'), + const SizedBox(height: 5), + Text('Host: $hostName '), + ], + ), + ); + } +} diff --git a/example/macos/Flutter/GeneratedPluginRegistrant.swift b/example/macos/Flutter/GeneratedPluginRegistrant.swift index 5849f84..2844b6d 100644 --- a/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,10 +5,10 @@ import FlutterMacOS import Foundation -import bonsoir_darwin +import nsd_macos import path_provider_foundation func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { - SwiftBonsoirPlugin.register(with: registry.registrar(forPlugin: "SwiftBonsoirPlugin")) + NsdMacosPlugin.register(with: registry.registrar(forPlugin: "NsdMacosPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) } diff --git a/example/pubspec.lock b/example/pubspec.lock index 9ccb7b9..5d2c305 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -17,54 +17,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.11.0" - bonsoir: - dependency: transitive - description: - name: bonsoir - sha256: "7dd7f87f154c0a16ef569b685aa6d0556d4cc281ae7565420d9f639febefa06e" - url: "https://pub.dev" - source: hosted - version: "5.1.1" - bonsoir_android: - dependency: transitive - description: - name: bonsoir_android - sha256: d317c099f9c0a558d3e9e7400b9003f588cd685f1695bb09c36ee76fc79c83c3 - url: "https://pub.dev" - source: hosted - version: "5.1.1" - bonsoir_darwin: - dependency: transitive - description: - name: bonsoir_darwin - sha256: eb45bafe5003352137e07d3b5a122a7250b507095f456f6612de3e7ddaba5e0d - url: "https://pub.dev" - source: hosted - version: "5.1.1" - bonsoir_linux: - dependency: transitive - description: - name: bonsoir_linux - sha256: "24cb232f311acb2e293f0fddcde134eddd51ecfdaf5622883fc087096138fbc0" - url: "https://pub.dev" - source: hosted - version: "5.1.1" - bonsoir_platform_interface: - dependency: transitive - description: - name: bonsoir_platform_interface - sha256: e87a9e26f428be50b934ddfd2bdc0a663d6f2c437ab0052793daaa0dd5aec5c7 - url: "https://pub.dev" - source: hosted - version: "5.1.1" - bonsoir_windows: - dependency: transitive - description: - name: bonsoir_windows - sha256: "8f7dfe941319e89842423322fe1836a6fa9ef35871d644dd8a44c15373f7924d" - url: "https://pub.dev" - source: hosted - version: "5.1.3" boolean_selector: dependency: transitive description: @@ -137,14 +89,6 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.2" - dbus: - dependency: transitive - description: - name: dbus - sha256: "365c771ac3b0e58845f39ec6deebc76e3276aa9922b0cc60840712094d9047ac" - url: "https://pub.dev" - source: hosted - version: "0.7.10" fake_async: dependency: transitive description: @@ -283,6 +227,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.3.2+6" + nested: + dependency: transitive + description: + name: nested + sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20" + url: "https://pub.dev" + source: hosted + version: "1.0.0" network_tools: dependency: transitive description: @@ -297,6 +249,54 @@ packages: relative: true source: path version: "1.0.5" + nsd: + dependency: transitive + description: + name: nsd + sha256: "88a3ba4e6dc38363f1256b4b482abdeec396d99df31a064d545e559cb4cb6ba9" + url: "https://pub.dev" + source: hosted + version: "2.3.1" + nsd_android: + dependency: transitive + description: + name: nsd_android + sha256: "7a38d0b2d21f1e578cd3020940b95b22d5260413dc0c8cf30a987a4e410b166d" + url: "https://pub.dev" + source: hosted + version: "1.2.2" + nsd_ios: + dependency: transitive + description: + name: nsd_ios + sha256: "7034134dd89595362d5e464030081b0d542120a558ab7fe6227df44365df3e8a" + url: "https://pub.dev" + source: hosted + version: "1.0.3" + nsd_macos: + dependency: transitive + description: + name: nsd_macos + sha256: "2403b8d599f50fc9179db1420a0ffc25bfa8bbeb814aa31ca0a71f804fc938da" + url: "https://pub.dev" + source: hosted + version: "1.0.3" + nsd_platform_interface: + dependency: transitive + description: + name: nsd_platform_interface + sha256: "2f4033fa13cc45375253bf348abdb9712004e656462205543ec9506b43c67bb2" + url: "https://pub.dev" + source: hosted + version: "1.6.0" + nsd_windows: + dependency: transitive + description: + name: nsd_windows + sha256: "06601efdd3268cbce4b90f8e23ae1dab445c97c661fba417821ce118add722e7" + url: "https://pub.dev" + source: hosted + version: "2.0.1" path: dependency: transitive description: @@ -353,14 +353,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.2.1" - petitparser: - dependency: transitive - description: - name: petitparser - sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27 - url: "https://pub.dev" - source: hosted - version: "6.0.2" platform: dependency: transitive description: @@ -385,6 +377,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.14.1+3" + provider: + dependency: transitive + description: + name: provider + sha256: "9a96a0a19b594dbc5bf0f1f27d2bc67d5f95957359b461cd9feb44ed6ae75096" + url: "https://pub.dev" + source: hosted + version: "6.1.1" pub_semver: dependency: transitive description: @@ -518,14 +518,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.4" - xml: - dependency: transitive - description: - name: xml - sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226 - url: "https://pub.dev" - source: hosted - version: "6.5.0" yaml: dependency: transitive description: diff --git a/example/windows/flutter/generated_plugin_registrant.cc b/example/windows/flutter/generated_plugin_registrant.cc index 3473264..1be4edb 100644 --- a/example/windows/flutter/generated_plugin_registrant.cc +++ b/example/windows/flutter/generated_plugin_registrant.cc @@ -6,9 +6,9 @@ #include "generated_plugin_registrant.h" -#include +#include void RegisterPlugins(flutter::PluginRegistry* registry) { - BonsoirWindowsPluginCApiRegisterWithRegistrar( - registry->GetRegistrarForPlugin("BonsoirWindowsPluginCApi")); + NsdWindowsPluginCApiRegisterWithRegistrar( + registry->GetRegistrarForPlugin("NsdWindowsPluginCApi")); } diff --git a/example/windows/flutter/generated_plugins.cmake b/example/windows/flutter/generated_plugins.cmake index a5cde7e..3429ffa 100644 --- a/example/windows/flutter/generated_plugins.cmake +++ b/example/windows/flutter/generated_plugins.cmake @@ -3,7 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST - bonsoir_windows + nsd_windows ) list(APPEND FLUTTER_FFI_PLUGIN_LIST diff --git a/lib/src/configure_flutter.dart b/lib/src/configure_flutter.dart index 530e3b7..86b4c0e 100644 --- a/lib/src/configure_flutter.dart +++ b/lib/src/configure_flutter.dart @@ -10,7 +10,7 @@ import 'package:network_tools_flutter/src/services_impls/host_scanner_service_fl import 'package:network_tools_flutter/src/services_impls/mdns_scanner_service_flutter_impl.dart'; import 'package:network_tools_flutter/src/services_impls/port_scanner_service_flutter_impl.dart'; -Future configureNetworkToolsFlutter( +Future configureNetworkToolsFlutter( String dbDirectory, { bool enableDebugging = false, }) async { @@ -34,7 +34,6 @@ Future configureNetworkToolsFlutter( HostScannerServiceFlutterImpl(); PortScannerServiceFlutterImpel(); MdnsScannerServiceFlutterImpl(); - final arpService = await ARPService.instance.open(); await arpService.buildTable(); await pacakges_page.VendorTable.createVendorTableMap(); diff --git a/lib/src/services_impls/mdns_scanner_service_flutter_impl.dart b/lib/src/services_impls/mdns_scanner_service_flutter_impl.dart index 3c4fec9..8b26bdf 100644 --- a/lib/src/services_impls/mdns_scanner_service_flutter_impl.dart +++ b/lib/src/services_impls/mdns_scanner_service_flutter_impl.dart @@ -1,80 +1,110 @@ -import 'package:bonsoir/bonsoir.dart'; +import 'dart:isolate'; + +import 'package:flutter/services.dart'; // ignore: depend_on_referenced_packages import 'package:multicast_dns/multicast_dns.dart'; -import 'package:network_tools/network_tools.dart'; +import 'package:network_tools_flutter/network_tools_flutter.dart'; +import 'package:nsd/nsd.dart'; import 'package:universal_io/io.dart'; + // ignore: implementation_imports import 'package:network_tools/src/services/impls/mdns_scanner_service_impl.dart'; +class IsolateTypeSearch { + IsolateTypeSearch({ + required this.sendPort, + required this.serviceType, + required this.token, + required this.appDocDirectory, + }); + + final SendPort sendPort; + final String serviceType; + final RootIsolateToken token; + Directory appDocDirectory; +} + class MdnsScannerServiceFlutterImpl extends MdnsScannerServiceImpl { - // Using bonsoire untill https://github.com/flutter/flutter/issues/52733 is fix - // After that we can delete this method and let network tool use of multicast_dns handle all this logic + // TODO: Swtich to improved searchMdnsDevices method when https://github.com/Skyost/Bonsoir/issues/86 is resolved + @override Future> findingMdnsWithAddress( String serviceType, ) async { - List listOfActiveHost = []; + // return searchServiceBonjoir(serviceType); + if (Platform.isLinux) { + return super.findingMdnsWithAddress(serviceType); + } + + disableServiceTypeValidation(true); + final List activeHosts = []; + + Discovery? discovery; try { - BonsoirDiscovery discovery = BonsoirDiscovery(type: serviceType); - await discovery.ready; - Stream? discoverStream = discovery.eventStream; - if (discoverStream == null) { - return []; - } + discovery = + await startDiscovery(serviceType, ipLookupType: IpLookupType.any); + } catch (e) { + return []; + } - Future.delayed(const Duration(milliseconds: 1)).then((value) { - discovery.start(); - }); - - Future.delayed(const Duration(seconds: 5)).then((value) { - discovery.stop(); - }); - - await for (BonsoirDiscoveryEvent event in discoverStream) { - if (event.type == BonsoirDiscoveryEventType.discoveryServiceFound) { - event.service?.resolve(discovery.serviceResolver); - continue; - } else if (event.type == - BonsoirDiscoveryEventType.discoveryServiceResolved) { - } else { - continue; + discovery.addServiceListener((service, status) { + if (status == ServiceStatus.found) { + if (service.host == null || + service.port == null || + service.name == null || + service.addresses == null) { + return; } - ActiveHost? activeHost = convert(event); - if (activeHost == null) { - continue; + String? md = service.txt?['md'] != null + ? String.fromCharCodes(service.txt!['md']!) + : null; + String? fn = service.txt?['fn'] != null + ? String.fromCharCodes(service.txt!['fn']!) + : null; + + String name = [ + md, + fn, + ].whereType().join(' - '); + if (name.isEmpty) { + name = service.name!; + } + + String? mac = service.txt?['bt'] != null + ? String.fromCharCodes(service.txt!['bt']!) + : null; + + for (final InternetAddress address in service.addresses!) { + ActiveHost host = convert( + host: address, + port: service.port!, + name: name, + mac: mac, + ); + activeHosts.add(host); } - listOfActiveHost.add(activeHost); } - } catch (e) { - print('Error searching mdns $e'); - } - return listOfActiveHost; - } + }); - ActiveHost? convert(BonsoirDiscoveryEvent event) { - final port = event.service?.port; - final host = event.service?.toJson()['service.ip'] ?? - event.service?.toJson()['service.host']; - - String name = [ - event.service?.attributes['md'], - event.service?.attributes['fn'], - ].whereType().join(' - '); - if (name.isEmpty) { - name = event.service!.name; - } + await Future.delayed(const Duration(seconds: 5)); + discovery.dispose(); - if (port == null || host == null) { - return null; - } + return activeHosts; + } + ActiveHost convert({ + required InternetAddress host, + required int port, + required String name, + required String? mac, + }) { final MdnsInfo mdnsInfo = MdnsInfo( srvResourceRecord: SrvResourceRecord( name, 0, - target: host, + target: host.address, port: port, priority: 1, weight: 1, @@ -83,8 +113,156 @@ class MdnsScannerServiceFlutterImpl extends MdnsScannerServiceImpl { ); return ActiveHost( - internetAddress: InternetAddress(host), + internetAddress: host, + macAddress: mac, mdnsInfoVar: mdnsInfo, ); } + + // // Using bonsoire untill https://github.com/flutter/flutter/issues/52733 is fix + // // After that we can delete this method and let network tool use of multicast_dns handle all this logic + // @override + // Future> findingMdnsWithAddress( + // String serviceType, + // ) async { + // ReceivePort receivePort = ReceivePort(); + // final RootIsolateToken rootToken = RootIsolateToken.instance!; + // final Directory appDocDirectory = await getApplicationDocumentsDirectory(); + + // final IsolateTypeSearch typeSearch = IsolateTypeSearch( + // sendPort: receivePort.sendPort, + // serviceType: serviceType, + // token: rootToken, + // appDocDirectory: appDocDirectory, + // ); + + // final Isolate isolate = await Isolate.spawn(discoverService, typeSearch); + + // List listOfActiveHost = []; + + // await for (final message in receivePort) { + // if (message is ActiveHost) { + // listOfActiveHost.add(message); + // } + // } + // isolate.kill(); + // return listOfActiveHost; + // } + + // Future discoverService( + // IsolateTypeSearch isolateTypeSearch, + // ) async { + // BackgroundIsolateBinaryMessenger.ensureInitialized(isolateTypeSearch.token); + + // final SendPort sendPort = isolateTypeSearch.sendPort; + + // configureNetworkToolsFlutter( + // isolateTypeSearch.appDocDirectory.path, + // ); + + // try { + // List activeHosts = + // await searchServiceBonjoir(isolateTypeSearch.serviceType); + // for (ActiveHost activeHost in activeHosts) { + // sendPort.send(activeHost); + // } + // } catch (e) { + // print('Error searching mdns $e'); + // } + // } + + // Future> searchServiceBonjoir(String serviceType) async { + // BonsoirDiscovery discovery = BonsoirDiscovery(type: serviceType); + // await discovery.ready; + // Stream? discoverStream = discovery.eventStream; + // if (discoverStream == null) { + // return []; + // } + + // Future.delayed(const Duration(milliseconds: 1)).then((value) { + // discovery.start(); + // }); + + // Future.delayed(const Duration(seconds: 5)).then((value) { + // discovery.stop(); + // }); + + // final List foundHosts = []; + + // await for (BonsoirDiscoveryEvent event in discoverStream) { + // if (event.type == BonsoirDiscoveryEventType.discoveryServiceFound) { + // event.service?.resolve(discovery.serviceResolver); + // print('Found bonsoir ${event.service?.attributes}'); + // continue; + // } else if (event.type == + // BonsoirDiscoveryEventType.discoveryServiceResolved) { + // } else { + // continue; + // } + // if (event.service == null) { + // continue; + // } + // final int port = event.service!.port; + // final host = event.service!.toJson()['service.ip'] ?? + // event.service!.toJson()['service.host']; + + // String name = [ + // event.service?.attributes['md'], + // event.service?.attributes['fn'], + // ].whereType().join(' - '); + // if (name.isEmpty) { + // name = event.service!.name; + // } + + // if (host == null) { + // continue; + // } + + // ActiveHost activeHost = convert( + // host: host, + // port: port, + // name: name, + // ); + + // // ActiveHost? activeHost = convert2(event); + // print('activeHost ${activeHost.address}'); + // foundHosts.add(activeHost); + // } + // return foundHosts; + // } + + // ActiveHost? convert2(BonsoirDiscoveryEvent event) { + // final port = event.service?.port; + // final host = event.service?.toJson()['service.ip'] ?? + // event.service?.toJson()['service.host']; + + // String name = [ + // event.service?.attributes['md'], + // event.service?.attributes['fn'], + // ].whereType().join(' - '); + // if (name.isEmpty) { + // name = event.service!.name; + // } + + // if (port == null || host == null) { + // return null; + // } + + // final MdnsInfo mdnsInfo = MdnsInfo( + // srvResourceRecord: SrvResourceRecord( + // name, + // 0, + // target: host, + // port: port, + // priority: 1, + // weight: 1, + // ), + // ptrResourceRecord: PtrResourceRecord(name, 0, domainName: ''), + // ); + + // return ActiveHost( + // internetAddress: InternetAddress(host), + // mdnsInfoVar: mdnsInfo, + // ); + // } } diff --git a/pubspec.yaml b/pubspec.yaml index 7680f93..862c7a4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,13 +40,12 @@ dependencies: intl: ^0.19.0 # network_tools: ^4.0.3 network_tools: - # git: - # url: "https://github.com/guyluz11/network_tools.git" - # ref: "abstracting_services" - path: '../network_tools' + git: + url: "https://github.com/guyluz11/network_tools.git" + ref: "adding_ios_support" path_provider: ^2.1.1 universal_io: ^2.2.2 - bonsoir: ^5.1.8 + nsd: ^2.3.1 dev_dependencies: flutter_test: From e9abd9f103d47ddf8a5d2e31ef13ca0cee5e523c Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Sat, 24 Feb 2024 17:33:44 +0200 Subject: [PATCH 3/4] wip --- .../lib/pages/mdns_search/mdns_widget.dart | 1 - .../mdns_scanner_service_flutter_impl.dart | 31 +++++++++---------- pubspec.yaml | 11 ++++--- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/example/lib/pages/mdns_search/mdns_widget.dart b/example/lib/pages/mdns_search/mdns_widget.dart index 25ad431..ccfd9be 100644 --- a/example/lib/pages/mdns_search/mdns_widget.dart +++ b/example/lib/pages/mdns_search/mdns_widget.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:network_tools/src/models/active_host.dart'; import 'package:network_tools_flutter/network_tools_flutter.dart'; class MdnsSearchWidget extends StatefulWidget { diff --git a/lib/src/services_impls/mdns_scanner_service_flutter_impl.dart b/lib/src/services_impls/mdns_scanner_service_flutter_impl.dart index 8b26bdf..7168e07 100644 --- a/lib/src/services_impls/mdns_scanner_service_flutter_impl.dart +++ b/lib/src/services_impls/mdns_scanner_service_flutter_impl.dart @@ -1,6 +1,3 @@ -import 'dart:isolate'; - -import 'package:flutter/services.dart'; // ignore: depend_on_referenced_packages import 'package:multicast_dns/multicast_dns.dart'; import 'package:network_tools_flutter/network_tools_flutter.dart'; @@ -10,19 +7,19 @@ import 'package:universal_io/io.dart'; // ignore: implementation_imports import 'package:network_tools/src/services/impls/mdns_scanner_service_impl.dart'; -class IsolateTypeSearch { - IsolateTypeSearch({ - required this.sendPort, - required this.serviceType, - required this.token, - required this.appDocDirectory, - }); - - final SendPort sendPort; - final String serviceType; - final RootIsolateToken token; - Directory appDocDirectory; -} +// class IsolateTypeSearch { +// IsolateTypeSearch({ +// required this.sendPort, +// required this.serviceType, +// required this.token, +// required this.appDocDirectory, +// }); + +// final SendPort sendPort; +// final String serviceType; +// final RootIsolateToken token; +// Directory appDocDirectory; +// } class MdnsScannerServiceFlutterImpl extends MdnsScannerServiceImpl { // TODO: Swtich to improved searchMdnsDevices method when https://github.com/Skyost/Bonsoir/issues/86 is resolved @@ -32,7 +29,7 @@ class MdnsScannerServiceFlutterImpl extends MdnsScannerServiceImpl { String serviceType, ) async { // return searchServiceBonjoir(serviceType); - if (Platform.isLinux) { + if (!Platform.isIOS) { return super.findingMdnsWithAddress(serviceType); } diff --git a/pubspec.yaml b/pubspec.yaml index 862c7a4..230b418 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -37,12 +37,13 @@ dependencies: # Debugging and error logging. logging: ^1.2.0 # Deal with internationalized/localized messages and more. - intl: ^0.19.0 + intl: ^0.18.1 # network_tools: ^4.0.3 - network_tools: - git: - url: "https://github.com/guyluz11/network_tools.git" - ref: "adding_ios_support" + network_tools: + path: "../network_tools" + # git: + # url: "https://github.com/guyluz11/network_tools.git" + # ref: "adding_ios_support" path_provider: ^2.1.1 universal_io: ^2.2.2 nsd: ^2.3.1 From 35c575dc06fcaaa04d0a471576cab727afd0f1c0 Mon Sep 17 00:00:00 2001 From: git-elliot Date: Sat, 30 Mar 2024 14:48:27 +0530 Subject: [PATCH 4/4] remove unused import --- lib/src/configure_flutter.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/configure_flutter.dart b/lib/src/configure_flutter.dart index 3073e6a..eeaae83 100644 --- a/lib/src/configure_flutter.dart +++ b/lib/src/configure_flutter.dart @@ -8,7 +8,6 @@ import 'package:network_tools/src/services/impls/arp_service_sembast_impl.dart'; import 'package:network_tools/src/services/impls/mdns_scanner_service_impl.dart'; import 'package:network_tools_flutter/src/network_tools_flutter_util.dart'; import 'package:network_tools_flutter/src/services_impls/host_scanner_service_flutter_impl.dart'; -import 'package:network_tools_flutter/src/services_impls/mdns_scanner_service_flutter_impl.dart'; import 'package:network_tools_flutter/src/services_impls/port_scanner_service_flutter_impl.dart'; Future configureNetworkToolsFlutter(