balthazar / react-native-zeroconf

:satellite: Discover Zeroconf services using react-native
MIT License
211 stars 96 forks source link

How to discover all discoverable devices #150

Closed nxtexe closed 3 years ago

nxtexe commented 3 years ago

It seems zeroconf is not working for me on react native version 0.63.3. It is a none expo react app being tested on physical device. I registered a listener for all possible events and none fire. getServices() also returns {}. I know my service is working since I can ping the service from windows command line. Ideas?

jwh-hutchison commented 3 years ago

I have the same issue, have you checked if you receive anything in the found event call? I can pick up the service name but the service never actually resolves.

nxtexe commented 3 years ago

What I did to solve the issue, I used bonjour browser on windows to discover the device. It came up as type: _workstation._tcp, now in react native zeroconf scan method instead of passing http as type I passed workstation as type i.e. scan('workstation', 'tcp', '.local');, this works. I figured this out due to the docs saying when trying to advertise you need to pass name and type underscore prefixed with a dot separating type and protocol for the type argument i.e. _http._tcp. So what I did was try to advertise using publishService('_http._tcp', 'tcp', 'local', 'device', 8000, {'NAME': 'NULL'}), then tried to discover it in the same script with scan('http', 'tcp', 'local'); and it worked! In bonjour browser my phone came up as _http._tcp. So all I did was tried the same thing for the raspberry pi I was originally trying to discover and it worked.

nxtexe commented 3 years ago

Sorry for the long winded reply but this is so confusing I hope this explains it perfectly to the next wanderer. I may open a PR to make it clearer.

jwh-hutchison commented 3 years ago

What I did to solve the issue, I used bonjour browser on windows to discover the device. It came up as type: _workstation._tcp, now in react native zeroconf scan method instead of passing http as type I passed workstation as type i.e. scan('workstation', 'tcp', '.local');, this works. I figured this out due to the docs saying when trying to advertise you need to pass name and type underscore prefixed with a dot separating type and protocol for the type argument i.e. _http._tcp. So what I did was try to advertise using publishService('_http._tcp', 'tcp', 'local', 'device', 8000, {'NAME': 'NULL'}), then tried to discover it in the same script with scan('http', 'tcp', 'local'); and it worked! In bonjour browser my phone came up as _http._tcp. So all I did was tried the same thing for the raspberry pi I was originally trying to discover and it worked.

Was the resolved event ever called though?

nxtexe commented 3 years ago

Yea everything works fine now.

jwh-hutchison commented 3 years ago

I got mine working, turns out battery optimizations were causing the resolve failures, I set com.android.server.NetworkPermissionConfig to 'don't optimise' in my android settings under: Apps & Notifications -> Advanced -> Special App Access -> Battery Optimization, now it works every time.

shoaibarif244 commented 1 year ago

@nxtexe can you please guide me that how to use it??