Closed ed-oo closed 8 months ago
Hey,
Would it be possible to see your code please ? Also, please note that the example app has been updated to 3.0.0
, feel free to check it out to adapt your code to this new version.
@Skyost, I also see this happening. The first time I start discovery, the services are found, and they are also resolved after I request for them to be resolved. Then I stop discovery.
After that first discovery, resolve never works anymore. Immediately after BonsoirDiscoveryEventType.discoveryServiceFound, a BonsoirDiscoveryEventType.discoveryStopped comes right after. Resolution of the services never happens anymore, no success and no failure.
Here's the code:
Future<void> scan(String mdnsName) async {
final discovery = BonsoirDiscovery(type: mdnsName);
await discovery.ready;
discovery.eventStream?.listen((event) {
print('Bonsoir event received: ${event.type}');
if (event.type == BonsoirDiscoveryEventType.discoveryServiceFound) {
print('Service found: ${event.service?.toJson()}');
event.service!.resolve(discovery.serviceResolver);
} else if (event.type == BonsoirDiscoveryEventType.discoveryServiceResolved) {
print('Service resolved: ${event.service?.toJson()}');
}
});
await discovery.start();
// wait 5 seconds
await Future.delayed(const Duration(seconds: 5));
await discovery.stop();
}
This same code runs fine and services are resolved the first time it runs. Any time I call this function again, discovery is stopped automatically after the services are found, and resolve never works again.
Using Bonsoir 3.0.0+1
Thanks. Does it occur only on iOS, or do you experience a similar problem on Android ?
I don't have an Android device to test on, but I see the same behavior on both iOS and macOS. After downgrading to version 2.2.0+1 and commenting out the line with the resolve request, it works fine every time the function is called.
I found another problem in 2.2.0+1 on android in resolver_service.dart My code:
BonsoirService service = BonsoirService(
name: "Serveur John",
type: "_john-server._tcp",
port: 8299,
);
this._bonsoirBroadcast = BonsoirBroadcast(service: service);
await this._bonsoirBroadcast!.ready;
await this._bonsoirBroadcast!.start();
On Debug:
static String _filterType(String type) {
if (type.startsWith('._')) {
type = type.substring(1);
}
if (type.endsWith('_tcp.') || type.endsWith('_udp.')) {
type = type.substring(0, type.length - 1);
}
return type;
}
_filterType have String not nullable parameter and service.type == null (even if i specified a type, i don't understand)
@fptavares I'll finally have the time to test your code tomorrow. Will tell you if I'm able to reproduce. @ed-oo I don't understand your last message, and as I don't have access to your prior code, I may not be able to reproduce your issue.
I can confirm this issue exists on macOS as well. Can also easily reproduced by just doing a hot restart. After the first hot restart the discovery stops immediately after services are found.
Same problem here using iOS.
Okay so it seems to be a problem with the Darwin implementation. Anyway, we have to rewrite it in order to get rid of NetService
.
@ed-oo, @julianscheel, @rope50, @fptavares :
I've rewritten the Darwin project to remove the dependence on NetService
. I've already tested it on macOS (not 100%, attributes are still untested, but the major features seem to work).
Can you please it on your side ? To do so, in your pubspec.yaml
:
dependency_overrides:
bonsoir:
git:
url: https://github.com/Skyost/Bonsoir.git
ref: darwin-network
path: bonsoir
bonsoir_android:
git:
url: https://github.com/Skyost/Bonsoir.git
ref: darwin-network
path: bonsoir_android
bonsoir_darwin:
git:
url: https://github.com/Skyost/Bonsoir.git
ref: darwin-network
path: bonsoir_darwin
bonsoir_platform_interface:
git:
url: https://github.com/Skyost/Bonsoir.git
ref: darwin-network
path: bonsoir_platform_interface
then flutter pub get
. May also need pod update
.
Had the time to test it. It works, I'm merging the PR.
After version 2.2.0+1, we have to use
event.service !.resolve(discovery.serviceResolver);
manually, but 99% of the time this call triggers BonsoirDiscoveryEventType.discoveryStopped directly afterwards. The service is never resolved (except in 1% of cases by magic).Another problem is that when BonsoirDiscoveryEventType.discoveryServiceFound occurs, the service type is correct but the port is always equal to -1, except in 1% of cases by magic (the problem is also present in version 2.2.0+1, but the service is resolved in this version and handles BonsoirDiscoveryEventType.discoveryServiceResolved correctly afterwards, event if port == -1).
The problem is present on both IOS and Android.
I'm going back to version 2.2.0+1 while waiting for a solution to my problem.
Thank you