Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for use of meta-query #101

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class AvahiBonsoirDiscovery extends AvahiBonsoirAction<BonsoirDiscoveryEvent> wi
logMessages: BonsoirPlatformInterfaceLogMessages.discoveryMessages,
);

// This returns whether the service is a meta query.
bool get isMetaQuery => type == bonsoirMetaQuery;

@override
Future<void> get ready async {
if (_serviceBrowser == null) {
Expand Down Expand Up @@ -146,7 +149,7 @@ class AvahiBonsoirDiscovery extends AvahiBonsoirAction<BonsoirDiscoveryEvent> wi
/// Triggered when a service has been found.
Future<void> _onServiceFound(DBusSignal signal) async {
AvahiServiceBrowserItemNew event = AvahiServiceBrowserItemNew(signal);
if (event.type != this.type) {
if (event.type != this.type && !isMetaQuery) {
return;
}
BonsoirService? service = _findService(event.serviceName, event.type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,15 @@ abstract class BonsoirPlatformInterface extends PlatformInterface {
/// A Bonsoir class that allows to either broadcast a service or to discover services on the network using a method channel.
class MethodChannelBonsoir extends BonsoirPlatformInterface {
@override
BonsoirAction<BonsoirBroadcastEvent> createBroadcastAction(BonsoirService service, {bool printLogs = kDebugMode}) => MethodChannelBonsoirBroadcastAction(service: service, printLogs: printLogs);
BonsoirAction<BonsoirBroadcastEvent> createBroadcastAction(BonsoirService service, {bool printLogs = kDebugMode}) =>
MethodChannelBonsoirBroadcastAction(service: service, printLogs: printLogs);

@override
BonsoirAction<BonsoirDiscoveryEvent> createDiscoveryAction(String type, {bool printLogs = kDebugMode}) => MethodChannelBonsoirDiscoveryAction(type: type, printLogs: printLogs);
BonsoirAction<BonsoirDiscoveryEvent> createDiscoveryAction(String type, {bool printLogs = kDebugMode}) =>
MethodChannelBonsoirDiscoveryAction(type: type, printLogs: printLogs);
}

/// The DNS-SD meta query.
///
/// Reference : [RFC 6763](https://datatracker.ietf.org/doc/html/rfc6763#section-9).
const String bonsoirMetaQuery = '_services._dns-sd._udp';
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:convert';

import 'package:bonsoir_platform_interface/src/platform_interface.dart';
import 'package:flutter/foundation.dart';

/// Contains various methods that helps conforming to RFC 6335 and RFC 6763.
Expand Down Expand Up @@ -37,6 +38,11 @@ class BonsoirServiceNormalizer {
/// * [RFC 6335](https://datatracker.ietf.org/doc/html/rfc6335#section-5.1);
/// * [RFC 6763](https://datatracker.ietf.org/doc/html/rfc6763#section-7).
static String normalizeType(String type) {
// If the type is the meta query, we return it as is.
if (type == bonsoirMetaQuery) {
return type;
}

List<String> parts = type.split('.');
if (parts.length != 2) {
return defaultServiceType;
Expand Down Expand Up @@ -88,7 +94,7 @@ class BonsoirServiceNormalizer {
/// Normalizes a given service [attributes].
///
/// Reference : [RFC 6763](https://datatracker.ietf.org/doc/html/rfc6763#section-6).
static Map<String, String> normalizeAttributes(Map<String, String> attributes, { bool limitKeyLength = false }) {
static Map<String, String> normalizeAttributes(Map<String, String> attributes, {bool limitKeyLength = false}) {
Map<String, String> result = <String, String>{};

for (MapEntry<String, String> entry in attributes.entries) {
Expand Down