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/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 19b862e..99969a7 100644
--- a/example/android/app/src/main/AndroidManifest.xml
+++ b/example/android/app/src/main/AndroidManifest.xml
@@ -1,4 +1,7 @@
+
+
+
const MdnsScannerPage(),
+ ),
+ );
+ },
+ child: const Text('mDNS Scanner'),
+ ),
],
),
);
diff --git a/example/lib/pages/mdns_search/mdns_scanner_page.dart b/example/lib/pages/mdns_search/mdns_scanner_page.dart
new file mode 100644
index 0000000..b64cfd5
--- /dev/null
+++ b/example/lib/pages/mdns_search/mdns_scanner_page.dart
@@ -0,0 +1,58 @@
+import 'package:example/pages/mdns_search/mdns_widget.dart';
+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(() {
+ if (activeHosts == null) {
+ activeHosts = hosts;
+ } else {
+ 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 == null
+ ? const CircularProgressIndicator()
+ : 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..ccfd9be
--- /dev/null
+++ b/example/lib/pages/mdns_search/mdns_widget.dart
@@ -0,0 +1,90 @@
+import 'package:flutter/material.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 e777c67..2844b6d 100644
--- a/example/macos/Flutter/GeneratedPluginRegistrant.swift
+++ b/example/macos/Flutter/GeneratedPluginRegistrant.swift
@@ -5,8 +5,10 @@
import FlutterMacOS
import Foundation
+import nsd_macos
import path_provider_foundation
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
+ 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 ab4319a..f46d1a3 100644
--- a/example/pubspec.lock
+++ b/example/pubspec.lock
@@ -85,10 +85,10 @@ packages:
dependency: transitive
description:
name: dart_ping_ios
- sha256: "5d27e4d3e7fccbc123bbb5c2803f5cb5933aea2f91b80ee1151d852f51b20cf3"
+ sha256: "17df1b369331ec6c30a91a51db64ac8feed47fad71e444208de06edf2a22415f"
url: "https://pub.dev"
source: hosted
- version: "4.0.1"
+ version: "4.0.2"
fake_async:
dependency: transitive
description:
@@ -167,10 +167,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:
@@ -251,6 +251,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:
@@ -278,26 +286,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:
@@ -310,10 +318,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:
@@ -326,18 +334,18 @@ packages:
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:
@@ -346,6 +354,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:
@@ -358,10 +374,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
@@ -403,10 +419,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:
@@ -475,18 +491,18 @@ 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.3"
+ version: "1.0.4"
yaml:
dependency: transitive
description:
@@ -497,4 +513,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..1be4edb 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) {
+ NsdWindowsPluginCApiRegisterWithRegistrar(
+ registry->GetRegistrarForPlugin("NsdWindowsPluginCApi"));
}
diff --git a/example/windows/flutter/generated_plugins.cmake b/example/windows/flutter/generated_plugins.cmake
index b93c4c3..3429ffa 100644
--- a/example/windows/flutter/generated_plugins.cmake
+++ b/example/windows/flutter/generated_plugins.cmake
@@ -3,6 +3,7 @@
#
list(APPEND FLUTTER_PLUGIN_LIST
+ nsd_windows
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST
diff --git a/lib/src/configure_flutter.dart b/lib/src/configure_flutter.dart
index 46ed3ee..eeaae83 100644
--- a/lib/src/configure_flutter.dart
+++ b/lib/src/configure_flutter.dart
@@ -10,7 +10,7 @@ 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/port_scanner_service_flutter_impl.dart';
-Future configureNetworkToolsFlutter(
+Future configureNetworkToolsFlutter(
String dbDirectory, {
bool enableDebugging = false,
}) async {
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..7168e07
--- /dev/null
+++ b/lib/src/services_impls/mdns_scanner_service_flutter_impl.dart
@@ -0,0 +1,265 @@
+// ignore: depend_on_referenced_packages
+import 'package:multicast_dns/multicast_dns.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 {
+ // TODO: Swtich to improved searchMdnsDevices method when https://github.com/Skyost/Bonsoir/issues/86 is resolved
+
+ @override
+ Future> findingMdnsWithAddress(
+ String serviceType,
+ ) async {
+ // return searchServiceBonjoir(serviceType);
+ if (!Platform.isIOS) {
+ return super.findingMdnsWithAddress(serviceType);
+ }
+
+ disableServiceTypeValidation(true);
+ final List activeHosts = [];
+
+ Discovery? discovery;
+
+ try {
+ discovery =
+ await startDiscovery(serviceType, ipLookupType: IpLookupType.any);
+ } catch (e) {
+ return [];
+ }
+
+ discovery.addServiceListener((service, status) {
+ if (status == ServiceStatus.found) {
+ if (service.host == null ||
+ service.port == null ||
+ service.name == null ||
+ service.addresses == null) {
+ return;
+ }
+
+ 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);
+ }
+ }
+ });
+
+ await Future.delayed(const Duration(seconds: 5));
+ discovery.dispose();
+
+ 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.address,
+ port: port,
+ priority: 1,
+ weight: 1,
+ ),
+ ptrResourceRecord: PtrResourceRecord(name, 0, domainName: ''),
+ );
+
+ return ActiveHost(
+ 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/lib/src/services_impls/port_scanner_service_flutter_impl.dart b/lib/src/services_impls/port_scanner_service_flutter_impl.dart
index 67139b2..54170a3 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 7d1fd90..a05db13 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,8 +30,8 @@ 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.
@@ -41,48 +40,14 @@ dependencies:
intl: ^0.18.0
network_tools: ^5.0.0
path_provider: ^2.1.1
- universal_io: ^2.2.0
+ universal_io: ^2.2.2
+ nsd: ^2.3.1
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 2aee2e7..25cb695 100644
--- a/test/host_scan_flutter_test.dart
+++ b/test/host_scan_flutter_test.dart
@@ -1,7 +1,7 @@
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 'package:network_tools_flutter/src/network_tools_flutter_util.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';