becvert / cordova-plugin-zeroconf

Cordova ZeroConf Plugin
MIT License
81 stars 57 forks source link

zeroconf.watch not working on Android 9 #88

Open sevicbb opened 4 years ago

sevicbb commented 4 years ago
zeroconf.watch('_http._tcp.', 'local.', ({ action, service }) => {
    console.log(service)
    if (action === "resolved") {
      console.log(service)
    } else if (action === "removed") {
      console.log(service)
    }
})

Same code works on iOS. It was working on Android but suddenly it stopped. Any suggestions? Getting this error in failure callback:

Error: Attempt to invoke interface method 'boolean java.util.Enumeration.hasMoreElements()' on a null object reference

emcniece commented 3 years ago

The error line appears to be here: https://github.com/becvert/cordova-plugin-zeroconf/blob/master/src/android/net/becvert/cordova/ZeroConf.java#L555

        Enumeration<String> names = service.getPropertyNames();
        while (names.hasMoreElements()) {

I suppose the service.getPropertyNames() method is returning an unexpected result. A solution might be just to try/catch this call. We should also look at service that gets passed into jsonifyService(ServiceInfo service) too, it could be that service itself is empty and doesn't have any propertyNames to iterate. The mystery then becomes "what kind of service was returned from registrationManager.register() that is invalid?

Does Android 9 change or update app permission structures?

SamuelMichelRiad commented 3 years ago

Does anyone have a clue on how to resolve this? It's also not working on Android 11. Are there any alternative plugins to obtain local network devices?

emcniece commented 3 years ago

Yes, as per my previous comment, https://github.com/becvert/cordova-plugin-zeroconf/blob/master/src/android/net/becvert/cordova/ZeroConf.java#L555 needs error handling and investigation. Apologies, I don't have capacity to do this at the moment :(