Closed home-grown-engineer closed 7 years ago
That's odd. I'll have a look.
if you're interested in ipv4 addresses only, you may be interested in these brand new options for Android:
var zeroconf = cordova.plugins.zeroconf;
zeroconf.registerAddressFamily = 'ipv4'; // or 'ipv6' ('any' by default)
zeroconf.watchAddressFamily = 'ipv4'; // or 'ipv6' ('any' by default)
Could you console.log the whole service object to see what's inside? thank you
Okay.
Console log of
var zeroconf = cordova.plugins.zeroconf;
This is screenshot with services of registered object and watcher object.
So I added
zeroconf.registerAddressFamily = 'ipv4';
It helps. I do not received any information with undefined address after watch()
was called first time.
But I still have duplicating messages from watcher.
I tried to add new device again
And then remove it and got added
device with undefined
address
And again add another device
I will be glad if you find some solution, because this functionality is very important for me. Yours plugin is unique (any of other plugin can't work with iOS) and I glad that you still working on it.
Thank you!
Please try this branch cordova plugin add https://github.com/becvert/cordova-plugin-zeroconf#1.2.6-dev
You should now check if (action === 'resolved')
Tell us how it goes.
Thank you for answer.
That is great that we have now one more action. Yes, it help remove duplicate items, but sometimes.
I tried test it as much as possible and found next behaviors.
Sometimes on first start watching I have duplicates
After some time, I again got it. I do not off application between time on first screenshot and second.
Next flow will be with deleting.
I restart my application without any devices in network and then UP couples devices and again saw duplicates.
I tried to remove on of them
And start watching some interesting flow of watcher
So resolved
action helps. But do not fix duplicating sometimes and not fix caching.
If you need, I can record video with flow of adding and removing devices in network.
Thanks for your help!
OK. I'm not sure I can do more than that. I'm just passing on the results of the operations of the underlying libraries.
Duplicates could be explained by the following;
before downing your devices be sure to unregister. That may help.
I found that a service can be resolved multiple times, for instance first time just the hostname is resolved then the ip adresses then again the ip addresses changes (see that with ipv6 with apple devices) then the txtRecord are resolved...
The mdns/bonjour protocols imply some latency and caching, it's not instantaneous. And maybe, but maybe I'm wrong, at interval it sends refresh on the network that trigger new resolve events.
I'd say at this stage you should handle duplicates at the application level. Figure out what you can do according to the added, resolved and removed actions.
Look into the code for improvements. Learn how the the mdns/bonjour protocols work.
I can't spend much more time on this right now. But thanks to you, I feel this plugin's been improved. I'll do a new release sometime soon
@becvert Okay, I understand. Thank you for you help 👍
I working on module that should sync in one local network devices and share data between them.
My problem is next:
After I register new device in network, watcher start looking on network and waiting for some event. After device is UP, watcher found a bunch of devices in network and start send their info to my device twice. First two times I receive just
undefined
address of devices. After 15 - 20 seconds I finally got all information about devices and again twice.Okay. Then I up new device in network and watcher triggered on it. And again I got information about device twice. Then I down device and watcher triggered on it again and on the first time I receive
undefined
and second one I again got this device asup
device.I try to up second device and again got data twice: first time is the new device data, and second is the old device that should be off.
Is it problem of zeroconf plugin? Because my code doesn't have anything that can call watcher function twice.