Skyost / Bonsoir

A Zeroconf library that allows you to discover network services and to broadcast your own. Based on Apple Bonjour and Android NSD.
http://bonsoir.skyost.eu/
Other
100 stars 43 forks source link

normalizeType error #84

Closed guyluz11 closed 3 months ago

guyluz11 commented 4 months ago

I am searching for srv recireds that I found in my home network and online and getting some errors

For example

flutter: Error searching mdns 'package:bonsoir/src/discovery.dart': Failed assertion: line 19 pos 11: 'type == BonsoirServiceNormalizer.normalizeType(type)': The provided type "_androidtvremote2._tcp" is invalid.

Here are srv's that I am getting error for

The function it crashes on all of them but for a different reasons https://github.com/Skyost/Bonsoir/blob/de335b602e4caf109eaadf14a001ebbf0f2fed3a/packages/bonsoir_platform_interface/lib/src/service/normalizer.dart#L39

Full list of errors

flutter: Error searching mdns 'package:bonsoir/src/discovery.dart': Failed assertion: line 19 pos 11: 'type == BonsoirServiceNormalizer.normalizeType(type)': The provided type "_androidtvremote2._tcp" is invalid.
flutter: Error searching mdns 'package:bonsoir/src/discovery.dart': Failed assertion: line 19 pos 11: 'type == BonsoirServiceNormalizer.normalizeType(type)': The provided type "_zigate-zigbee-gateway._tcp" is invalid.
flutter: Error searching mdns 'package:bonsoir/src/discovery.dart': Failed assertion: line 19 pos 11: 'type == BonsoirServiceNormalizer.normalizeType(type)': The provided type "_nvstream_dbd._tcp" is invalid.
Skyost commented 4 months ago

Hey,

Thanks for the report. Do you have a snippet or something ?

guyluz11 commented 4 months ago

Hey,

Thanks for the report. Do you have a snippet or something ?

import 'package:bonsoir/bonsoir.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  Future search() async {
    String serviceType = '_androidtvremote2._tcp';

    try {
      BonsoirDiscovery discovery = BonsoirDiscovery(type: serviceType);
      await discovery.ready;
      Stream<BonsoirDiscoveryEvent>? 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();
      });

      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;
        }
      }
    } catch (e) {
      print('Error $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: Scaffold(
        body: Center(
          child: TextButton(
            onPressed: search,
            child: const Text('Search android TV Remote service'),
          ),
        ),
      ),
    );
  }
}
Skyost commented 3 months ago

Did some testing today :

That's being said, it's problematic to have an error when invalid types are being used in BonsoirDiscovery. I'm gonna convert it to a warning.

Skyost commented 3 months ago

Fixed in https://github.com/Skyost/Bonsoir/commit/d24cc1d6ec92424184559f970cae054efb845043.