-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from guyluz11/adding_mdns_ios_support
Adding mdns ios support
- Loading branch information
Showing
19 changed files
with
525 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "example", | ||
"cwd": "example", | ||
"request": "launch", | ||
"type": "dart" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<MdnsScannerPage> createState() => _MdnsScannerPageState(); | ||
} | ||
|
||
class _MdnsScannerPageState extends State<MdnsScannerPage> { | ||
List<ActiveHost>? activeHosts; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
searchMdns(); | ||
} | ||
|
||
searchMdns() async { | ||
NetInterface? netInt = await NetInterface.localInterface(); | ||
if (netInt == null) { | ||
return; | ||
} | ||
List<ActiveHost> 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]), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<MdnsSearchWidget> createState() => _MdnsSearchWidgetState(); | ||
} | ||
|
||
class _MdnsSearchWidgetState extends State<MdnsSearchWidget> { | ||
@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 '), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.