Skip to content
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
3 changes: 1 addition & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include: package:pedantic/analysis_options.yaml
include: package:lints/recommended.yaml

analyzer:
exclude:
Expand All @@ -10,7 +10,6 @@ linter:
# Error Rules
avoid_empty_else: true
avoid_relative_lib_imports: true
avoid_returning_null_for_future: true
avoid_slow_async_io: true
avoid_types_as_parameter_names: true
control_flow_in_finally: true
Expand Down
2 changes: 0 additions & 2 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import FlutterMacOS
import Foundation

import bonsoir_darwin
import connectivity_plus

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
SwiftBonsoirPlugin.register(with: registry.registrar(forPlugin: "SwiftBonsoirPlugin"))
ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin"))
}
448 changes: 263 additions & 185 deletions lib/cast_channel/cast_channel.pb.dart

Large diffs are not rendered by default.

69 changes: 46 additions & 23 deletions lib/cast_channel/cast_channel.pbenum.dart
Original file line number Diff line number Diff line change
@@ -1,54 +1,77 @@
///
// Generated code. Do not modify.
// source: cast_channel.proto
// This is a generated file - do not edit.
//
// @dart = 2.12
// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields
// Generated from cast_channel.proto.

// @dart = 3.3

// ignore_for_file: annotate_overrides, camel_case_types, comment_references
// ignore_for_file: constant_identifier_names
// ignore_for_file: curly_braces_in_flow_control_structures
// ignore_for_file: deprecated_member_use_from_same_package, library_prefixes
// ignore_for_file: non_constant_identifier_names

// ignore_for_file: UNDEFINED_SHOWN_NAME
import 'dart:core' as $core;

import 'package:protobuf/protobuf.dart' as $pb;

/// Always pass a version of the protocol for future compatibility
/// requirements.
class CastMessage_ProtocolVersion extends $pb.ProtobufEnum {
static const CastMessage_ProtocolVersion CASTV2_1_0 = CastMessage_ProtocolVersion._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'CASTV2_1_0');
static const CastMessage_ProtocolVersion CASTV2_1_0 =
CastMessage_ProtocolVersion._(0, _omitEnumNames ? '' : 'CASTV2_1_0');

static const $core.List<CastMessage_ProtocolVersion> values = <CastMessage_ProtocolVersion> [
static const $core.List<CastMessage_ProtocolVersion> values =
<CastMessage_ProtocolVersion>[
CASTV2_1_0,
];

static final $core.Map<$core.int, CastMessage_ProtocolVersion> _byValue = $pb.ProtobufEnum.initByValue(values);
static CastMessage_ProtocolVersion? valueOf($core.int value) => _byValue[value];
static final $core.List<CastMessage_ProtocolVersion?> _byValue =
$pb.ProtobufEnum.$_initByValueList(values, 0);
static CastMessage_ProtocolVersion? valueOf($core.int value) =>
value < 0 || value >= _byValue.length ? null : _byValue[value];

const CastMessage_ProtocolVersion._($core.int v, $core.String n) : super(v, n);
const CastMessage_ProtocolVersion._(super.value, super.name);
}

/// What type of data do we have in this message.
class CastMessage_PayloadType extends $pb.ProtobufEnum {
static const CastMessage_PayloadType STRING = CastMessage_PayloadType._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'STRING');
static const CastMessage_PayloadType BINARY = CastMessage_PayloadType._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'BINARY');
static const CastMessage_PayloadType STRING =
CastMessage_PayloadType._(0, _omitEnumNames ? '' : 'STRING');
static const CastMessage_PayloadType BINARY =
CastMessage_PayloadType._(1, _omitEnumNames ? '' : 'BINARY');

static const $core.List<CastMessage_PayloadType> values = <CastMessage_PayloadType> [
static const $core.List<CastMessage_PayloadType> values =
<CastMessage_PayloadType>[
STRING,
BINARY,
];

static final $core.Map<$core.int, CastMessage_PayloadType> _byValue = $pb.ProtobufEnum.initByValue(values);
static CastMessage_PayloadType? valueOf($core.int value) => _byValue[value];
static final $core.List<CastMessage_PayloadType?> _byValue =
$pb.ProtobufEnum.$_initByValueList(values, 1);
static CastMessage_PayloadType? valueOf($core.int value) =>
value < 0 || value >= _byValue.length ? null : _byValue[value];

const CastMessage_PayloadType._($core.int v, $core.String n) : super(v, n);
const CastMessage_PayloadType._(super.value, super.name);
}

class AuthError_ErrorType extends $pb.ProtobufEnum {
static const AuthError_ErrorType INTERNAL_ERROR = AuthError_ErrorType._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'INTERNAL_ERROR');
static const AuthError_ErrorType NO_TLS = AuthError_ErrorType._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'NO_TLS');
static const AuthError_ErrorType INTERNAL_ERROR =
AuthError_ErrorType._(0, _omitEnumNames ? '' : 'INTERNAL_ERROR');
static const AuthError_ErrorType NO_TLS =
AuthError_ErrorType._(1, _omitEnumNames ? '' : 'NO_TLS');

static const $core.List<AuthError_ErrorType> values = <AuthError_ErrorType> [
static const $core.List<AuthError_ErrorType> values = <AuthError_ErrorType>[
INTERNAL_ERROR,
NO_TLS,
];

static final $core.Map<$core.int, AuthError_ErrorType> _byValue = $pb.ProtobufEnum.initByValue(values);
static AuthError_ErrorType? valueOf($core.int value) => _byValue[value];
static final $core.List<AuthError_ErrorType?> _byValue =
$pb.ProtobufEnum.$_initByValueList(values, 1);
static AuthError_ErrorType? valueOf($core.int value) =>
value < 0 || value >= _byValue.length ? null : _byValue[value];

const AuthError_ErrorType._($core.int v, $core.String n) : super(v, n);
const AuthError_ErrorType._(super.value, super.name);
}

const $core.bool _omitEnumNames =
$core.bool.fromEnvironment('protobuf.omit_enum_names');
173 changes: 126 additions & 47 deletions lib/cast_channel/cast_channel.pbjson.dart
Original file line number Diff line number Diff line change
@@ -1,95 +1,174 @@
///
// Generated code. Do not modify.
// source: cast_channel.proto
// This is a generated file - do not edit.
//
// @dart = 2.12
// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package
// Generated from cast_channel.proto.

// @dart = 3.3

// ignore_for_file: annotate_overrides, camel_case_types, comment_references
// ignore_for_file: constant_identifier_names
// ignore_for_file: curly_braces_in_flow_control_structures
// ignore_for_file: deprecated_member_use_from_same_package, library_prefixes
// ignore_for_file: non_constant_identifier_names, unused_import

import 'dart:core' as $core;
import 'dart:convert' as $convert;
import 'dart:core' as $core;
import 'dart:typed_data' as $typed_data;

@$core.Deprecated('Use castMessageDescriptor instead')
const CastMessage$json = const {
const CastMessage$json = {
'1': 'CastMessage',
'2': const [
const {'1': 'protocol_version', '3': 1, '4': 2, '5': 14, '6': '.extensions.api.cast_channel.CastMessage.ProtocolVersion', '10': 'protocolVersion'},
const {'1': 'source_id', '3': 2, '4': 2, '5': 9, '10': 'sourceId'},
const {'1': 'destination_id', '3': 3, '4': 2, '5': 9, '10': 'destinationId'},
const {'1': 'namespace', '3': 4, '4': 2, '5': 9, '10': 'namespace'},
const {'1': 'payload_type', '3': 5, '4': 2, '5': 14, '6': '.extensions.api.cast_channel.CastMessage.PayloadType', '10': 'payloadType'},
const {'1': 'payload_utf8', '3': 6, '4': 1, '5': 9, '10': 'payloadUtf8'},
const {'1': 'payload_binary', '3': 7, '4': 1, '5': 12, '10': 'payloadBinary'},
'2': [
{
'1': 'protocol_version',
'3': 1,
'4': 2,
'5': 14,
'6': '.extensions.api.cast_channel.CastMessage.ProtocolVersion',
'10': 'protocolVersion'
},
{'1': 'source_id', '3': 2, '4': 2, '5': 9, '10': 'sourceId'},
{'1': 'destination_id', '3': 3, '4': 2, '5': 9, '10': 'destinationId'},
{'1': 'namespace', '3': 4, '4': 2, '5': 9, '10': 'namespace'},
{
'1': 'payload_type',
'3': 5,
'4': 2,
'5': 14,
'6': '.extensions.api.cast_channel.CastMessage.PayloadType',
'10': 'payloadType'
},
{'1': 'payload_utf8', '3': 6, '4': 1, '5': 9, '10': 'payloadUtf8'},
{'1': 'payload_binary', '3': 7, '4': 1, '5': 12, '10': 'payloadBinary'},
],
'4': const [CastMessage_ProtocolVersion$json, CastMessage_PayloadType$json],
'4': [CastMessage_ProtocolVersion$json, CastMessage_PayloadType$json],
};

@$core.Deprecated('Use castMessageDescriptor instead')
const CastMessage_ProtocolVersion$json = const {
const CastMessage_ProtocolVersion$json = {
'1': 'ProtocolVersion',
'2': const [
const {'1': 'CASTV2_1_0', '2': 0},
'2': [
{'1': 'CASTV2_1_0', '2': 0},
],
};

@$core.Deprecated('Use castMessageDescriptor instead')
const CastMessage_PayloadType$json = const {
const CastMessage_PayloadType$json = {
'1': 'PayloadType',
'2': const [
const {'1': 'STRING', '2': 0},
const {'1': 'BINARY', '2': 1},
'2': [
{'1': 'STRING', '2': 0},
{'1': 'BINARY', '2': 1},
],
};

/// Descriptor for `CastMessage`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List castMessageDescriptor = $convert.base64Decode('CgtDYXN0TWVzc2FnZRJjChBwcm90b2NvbF92ZXJzaW9uGAEgAigOMjguZXh0ZW5zaW9ucy5hcGkuY2FzdF9jaGFubmVsLkNhc3RNZXNzYWdlLlByb3RvY29sVmVyc2lvblIPcHJvdG9jb2xWZXJzaW9uEhsKCXNvdXJjZV9pZBgCIAIoCVIIc291cmNlSWQSJQoOZGVzdGluYXRpb25faWQYAyACKAlSDWRlc3RpbmF0aW9uSWQSHAoJbmFtZXNwYWNlGAQgAigJUgluYW1lc3BhY2USVwoMcGF5bG9hZF90eXBlGAUgAigOMjQuZXh0ZW5zaW9ucy5hcGkuY2FzdF9jaGFubmVsLkNhc3RNZXNzYWdlLlBheWxvYWRUeXBlUgtwYXlsb2FkVHlwZRIhCgxwYXlsb2FkX3V0ZjgYBiABKAlSC3BheWxvYWRVdGY4EiUKDnBheWxvYWRfYmluYXJ5GAcgASgMUg1wYXlsb2FkQmluYXJ5IiEKD1Byb3RvY29sVmVyc2lvbhIOCgpDQVNUVjJfMV8wEAAiJQoLUGF5bG9hZFR5cGUSCgoGU1RSSU5HEAASCgoGQklOQVJZEAE=');
final $typed_data.Uint8List castMessageDescriptor = $convert.base64Decode(
'CgtDYXN0TWVzc2FnZRJjChBwcm90b2NvbF92ZXJzaW9uGAEgAigOMjguZXh0ZW5zaW9ucy5hcG'
'kuY2FzdF9jaGFubmVsLkNhc3RNZXNzYWdlLlByb3RvY29sVmVyc2lvblIPcHJvdG9jb2xWZXJz'
'aW9uEhsKCXNvdXJjZV9pZBgCIAIoCVIIc291cmNlSWQSJQoOZGVzdGluYXRpb25faWQYAyACKA'
'lSDWRlc3RpbmF0aW9uSWQSHAoJbmFtZXNwYWNlGAQgAigJUgluYW1lc3BhY2USVwoMcGF5bG9h'
'ZF90eXBlGAUgAigOMjQuZXh0ZW5zaW9ucy5hcGkuY2FzdF9jaGFubmVsLkNhc3RNZXNzYWdlLl'
'BheWxvYWRUeXBlUgtwYXlsb2FkVHlwZRIhCgxwYXlsb2FkX3V0ZjgYBiABKAlSC3BheWxvYWRV'
'dGY4EiUKDnBheWxvYWRfYmluYXJ5GAcgASgMUg1wYXlsb2FkQmluYXJ5IiEKD1Byb3RvY29sVm'
'Vyc2lvbhIOCgpDQVNUVjJfMV8wEAAiJQoLUGF5bG9hZFR5cGUSCgoGU1RSSU5HEAASCgoGQklO'
'QVJZEAE=');

@$core.Deprecated('Use authChallengeDescriptor instead')
const AuthChallenge$json = const {
const AuthChallenge$json = {
'1': 'AuthChallenge',
};

/// Descriptor for `AuthChallenge`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List authChallengeDescriptor = $convert.base64Decode('Cg1BdXRoQ2hhbGxlbmdl');
final $typed_data.Uint8List authChallengeDescriptor =
$convert.base64Decode('Cg1BdXRoQ2hhbGxlbmdl');

@$core.Deprecated('Use authResponseDescriptor instead')
const AuthResponse$json = const {
const AuthResponse$json = {
'1': 'AuthResponse',
'2': const [
const {'1': 'signature', '3': 1, '4': 2, '5': 12, '10': 'signature'},
const {'1': 'client_auth_certificate', '3': 2, '4': 2, '5': 12, '10': 'clientAuthCertificate'},
const {'1': 'client_ca', '3': 3, '4': 3, '5': 12, '10': 'clientCa'},
'2': [
{'1': 'signature', '3': 1, '4': 2, '5': 12, '10': 'signature'},
{
'1': 'client_auth_certificate',
'3': 2,
'4': 2,
'5': 12,
'10': 'clientAuthCertificate'
},
{'1': 'client_ca', '3': 3, '4': 3, '5': 12, '10': 'clientCa'},
],
};

/// Descriptor for `AuthResponse`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List authResponseDescriptor = $convert.base64Decode('CgxBdXRoUmVzcG9uc2USHAoJc2lnbmF0dXJlGAEgAigMUglzaWduYXR1cmUSNgoXY2xpZW50X2F1dGhfY2VydGlmaWNhdGUYAiACKAxSFWNsaWVudEF1dGhDZXJ0aWZpY2F0ZRIbCgljbGllbnRfY2EYAyADKAxSCGNsaWVudENh');
final $typed_data.Uint8List authResponseDescriptor = $convert.base64Decode(
'CgxBdXRoUmVzcG9uc2USHAoJc2lnbmF0dXJlGAEgAigMUglzaWduYXR1cmUSNgoXY2xpZW50X2'
'F1dGhfY2VydGlmaWNhdGUYAiACKAxSFWNsaWVudEF1dGhDZXJ0aWZpY2F0ZRIbCgljbGllbnRf'
'Y2EYAyADKAxSCGNsaWVudENh');

@$core.Deprecated('Use authErrorDescriptor instead')
const AuthError$json = const {
const AuthError$json = {
'1': 'AuthError',
'2': const [
const {'1': 'error_type', '3': 1, '4': 2, '5': 14, '6': '.extensions.api.cast_channel.AuthError.ErrorType', '10': 'errorType'},
'2': [
{
'1': 'error_type',
'3': 1,
'4': 2,
'5': 14,
'6': '.extensions.api.cast_channel.AuthError.ErrorType',
'10': 'errorType'
},
],
'4': const [AuthError_ErrorType$json],
'4': [AuthError_ErrorType$json],
};

@$core.Deprecated('Use authErrorDescriptor instead')
const AuthError_ErrorType$json = const {
const AuthError_ErrorType$json = {
'1': 'ErrorType',
'2': const [
const {'1': 'INTERNAL_ERROR', '2': 0},
const {'1': 'NO_TLS', '2': 1},
'2': [
{'1': 'INTERNAL_ERROR', '2': 0},
{'1': 'NO_TLS', '2': 1},
],
};

/// Descriptor for `AuthError`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List authErrorDescriptor = $convert.base64Decode('CglBdXRoRXJyb3ISTwoKZXJyb3JfdHlwZRgBIAIoDjIwLmV4dGVuc2lvbnMuYXBpLmNhc3RfY2hhbm5lbC5BdXRoRXJyb3IuRXJyb3JUeXBlUgllcnJvclR5cGUiKwoJRXJyb3JUeXBlEhIKDklOVEVSTkFMX0VSUk9SEAASCgoGTk9fVExTEAE=');
final $typed_data.Uint8List authErrorDescriptor = $convert.base64Decode(
'CglBdXRoRXJyb3ISTwoKZXJyb3JfdHlwZRgBIAIoDjIwLmV4dGVuc2lvbnMuYXBpLmNhc3RfY2'
'hhbm5lbC5BdXRoRXJyb3IuRXJyb3JUeXBlUgllcnJvclR5cGUiKwoJRXJyb3JUeXBlEhIKDklO'
'VEVSTkFMX0VSUk9SEAASCgoGTk9fVExTEAE=');

@$core.Deprecated('Use deviceAuthMessageDescriptor instead')
const DeviceAuthMessage$json = const {
const DeviceAuthMessage$json = {
'1': 'DeviceAuthMessage',
'2': const [
const {'1': 'challenge', '3': 1, '4': 1, '5': 11, '6': '.extensions.api.cast_channel.AuthChallenge', '10': 'challenge'},
const {'1': 'response', '3': 2, '4': 1, '5': 11, '6': '.extensions.api.cast_channel.AuthResponse', '10': 'response'},
const {'1': 'error', '3': 3, '4': 1, '5': 11, '6': '.extensions.api.cast_channel.AuthError', '10': 'error'},
'2': [
{
'1': 'challenge',
'3': 1,
'4': 1,
'5': 11,
'6': '.extensions.api.cast_channel.AuthChallenge',
'10': 'challenge'
},
{
'1': 'response',
'3': 2,
'4': 1,
'5': 11,
'6': '.extensions.api.cast_channel.AuthResponse',
'10': 'response'
},
{
'1': 'error',
'3': 3,
'4': 1,
'5': 11,
'6': '.extensions.api.cast_channel.AuthError',
'10': 'error'
},
],
};

/// Descriptor for `DeviceAuthMessage`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List deviceAuthMessageDescriptor = $convert.base64Decode('ChFEZXZpY2VBdXRoTWVzc2FnZRJICgljaGFsbGVuZ2UYASABKAsyKi5leHRlbnNpb25zLmFwaS5jYXN0X2NoYW5uZWwuQXV0aENoYWxsZW5nZVIJY2hhbGxlbmdlEkUKCHJlc3BvbnNlGAIgASgLMikuZXh0ZW5zaW9ucy5hcGkuY2FzdF9jaGFubmVsLkF1dGhSZXNwb25zZVIIcmVzcG9uc2USPAoFZXJyb3IYAyABKAsyJi5leHRlbnNpb25zLmFwaS5jYXN0X2NoYW5uZWwuQXV0aEVycm9yUgVlcnJvcg==');
final $typed_data.Uint8List deviceAuthMessageDescriptor = $convert.base64Decode(
'ChFEZXZpY2VBdXRoTWVzc2FnZRJICgljaGFsbGVuZ2UYASABKAsyKi5leHRlbnNpb25zLmFwaS'
'5jYXN0X2NoYW5uZWwuQXV0aENoYWxsZW5nZVIJY2hhbGxlbmdlEkUKCHJlc3BvbnNlGAIgASgL'
'MikuZXh0ZW5zaW9ucy5hcGkuY2FzdF9jaGFubmVsLkF1dGhSZXNwb25zZVIIcmVzcG9uc2USPA'
'oFZXJyb3IYAyABKAsyJi5leHRlbnNpb25zLmFwaS5jYXN0X2NoYW5uZWwuQXV0aEVycm9yUgVl'
'cnJvcg==');
30 changes: 12 additions & 18 deletions lib/discovery_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,32 @@ class CastDiscoveryService {
final results = <CastDevice>[];

final discovery = BonsoirDiscovery(type: _domain);
await discovery.ready;
await discovery.initialize();

discovery.eventStream!.listen((event) {
if (event.type == BonsoirDiscoveryEventType.discoveryServiceFound) {
event.service?.resolve(discovery.serviceResolver);
} else if (event.type == BonsoirDiscoveryEventType.discoveryServiceResolved) {
if (event.service == null || event.service?.attributes == null) {
return;
}

final port = event.service?.port;
final host = event.service?.toJson()['service.ip'] ?? event.service?.toJson()['service.host'];
if (event is BonsoirDiscoveryServiceFoundEvent) {
event.service.resolve(discovery.serviceResolver);
} else if (event is BonsoirDiscoveryServiceResolvedEvent) {
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'],
event.service.attributes['md'],
event.service.attributes['fn'],
].whereType<String>().join(' - ');
if (name.isEmpty) {
name = event.service!.name;
name = event.service.name;
}

if (port == null || host == null) {
return;
}
if (host == null) return;

results.add(
CastDevice(
serviceName: event.service!.name,
serviceName: event.service.name,
name: name,
port: port,
host: host,
extras: event.service!.attributes ?? {},
extras: event.service.attributes,
),
);
}
Expand Down
Loading