bonsoir 5.0.0 copy "bonsoir: ^5.0.0" to clipboard
bonsoir: ^5.0.0 copied to clipboard

A Zeroconf library that allows you to discover network services and to broadcast your own. Based on Apple Bonjour and Android NSD.

Bonsoir is a Zeroconf library that allows you to discover network services and to broadcast your own. It's based on Android NSD and on Apple's popular framework Bonjour. In fact, Bonsoir can be translated into Good evening (and Bonjour into Good morning or Good afternoon depending on the current moment of the day).

Pub Likes Pub Popularity Pub Points Maintained with Melos

Preview #

Bonsoir preview

Code snippet #

Here is how you can broadcast your service using Bonsoir :

// Let's create our service !
BonsoirService service = BonsoirService(
  name: 'My wonderful service', // Put your service name here.
  type: '_wonderful-service._tcp', // Put your service type here. Syntax : _ServiceType._TransportProtocolName. (see http://wiki.ros.org/zeroconf/Tutorials/Understanding%20Zeroconf%20Service%20Types).
  port: 3030, // Put your service port here.
);

// And now we can broadcast it :
BonsoirBroadcast broadcast = BonsoirBroadcast(service: service);
await broadcast.ready;
await broadcast.start();

// ...

// Then if you want to stop the broadcast :
await broadcast.stop();

And here is how you can search for a broadcasted service :

// This is the type of service we're looking for :
String type = '_wonderful-service._tcp';

// Once defined, we can start the discovery :
BonsoirDiscovery discovery = BonsoirDiscovery(type: type);
await discovery.ready;

// If you want to listen to the discovery :
discovery.eventStream!.listen((event) { // `eventStream` is not null as the discovery instance is "ready" !
  if (event.type == BonsoirDiscoveryEventType.discoveryServiceFound) {
    print('Service found : ${event.service.toJson()}')
    event.service!.resolve(discovery.serviceResolver); // Should be called when the user wants to connect to this service.
  } else if (event.type == BonsoirDiscoveryEventType.discoveryServiceResolved) {
    print('Service resolved : ${event.service.toJson()}')
  } else if (event.type == BonsoirDiscoveryEventType.discoveryServiceLost) {
    print('Service lost : ${event.service.toJson()}')
  }
});

// Start discovery **after** having listened to discovery events :
await discovery.start();

// Then if you want to stop the discovery :
await discovery.stop();

If you want a full example, don't hesitate to check this one on Github.

Installation #

Minimum OS requirements #

Depending on your project targets, you need at least :

  • Android : API level 21 (Android 5.0).
  • iOS : 12.0.
  • macOS : 10.11 (El Capitan).
  • Windows 10 (19H1/1903) (Mai 2019 Update).
  • Linux with Avahi.

Update deployment target #

If you want to use this plugin on iOS, you must update your deployment target to at least 13.0. At the top of ios/Podfile, add the following :

platform :ios, '13.0'

Also, open your iOS project in Xcode and select Runner, Targets -> Runner and then the "General" tab. Under the "Minimum Deployments" section, update the iOS version to 13.0 or higher.

You'll have to do the same steps if you want to use this plugin on macOS. Update your deployment target to at least 10.15. At the top of macOS/Podfile :

platform :osx, '10.15'

Open your macOS project in xCode and in the "Minimum Deployments" section, update the macOS version to 10.15 or higher.

Update Info.plist #

If you're building your app for iOS 14 or higher, you have to edit your Info.plist file. Just add the following lines :


<key>NSLocalNetworkUsageDescription</key><string>Describe here why you want to use Bonsoir.
</string><key>NSBonjourServices</key><array>
	<string>_first-service._tcp</string>
	<string>_second-service._tcp</string>
	<string>_third-service._tcp</string>
	<!-- Add more here -->
</array>

Don't forget to edit them according to your needs.

Final notes #

This plugin cannot be tested on an Android emulator (well it can, but the only services that you are able to discover are the ones broadcasted by your emulator).

The hand icon has been created by Vitaly Gorbachev.

Contributions #

You have a lot of options to contribute to this project ! You can :

93
likes
0
pub points
93%
popularity

Publisher

verified publisherskyost.eu

A Zeroconf library that allows you to discover network services and to broadcast your own. Based on Apple Bonjour and Android NSD.

Repository (GitHub)
View/report issues

Funding

Consider supporting this project:

ko-fi.com
paypal.me

License

unknown (LICENSE)

Dependencies

bonsoir_android, bonsoir_darwin, bonsoir_linux, bonsoir_platform_interface, bonsoir_windows, flutter

More

Packages that depend on bonsoir