Giter VIP home page Giter VIP logo

cordova-plugin-zeroconf's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cordova-plugin-zeroconf's Issues

Android build failed

.../platforms/android/src/net/becvert/cordova/ZeroConf.java:32: error: package org.apache.http.conn.util does not exist
import org.apache.http.conn.util.InetAddressUtils;
^
.../platforms/android/src/net/becvert/cordova/ZeroConf.java:381: error: cannot find symbol
if (InetAddressUtils.isIPv4Address(sAddr)) {
^
symbol: variable InetAddressUtils
location: class ZeroConf
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors
FAILED

Service aren't added on iOS

I use this library to announce my service on a Windows 10 machine.

If i use an Android phone it works, while if i use an iPhone the service is never listed as "added", and i get a "removed" message after several minutes.

image

If i use an macOS machine to announce the service it works on both Android and iOS

cordova-build error

Hello, i'm trying to compile your plugin with cordova in visual studio and I'm getting this error:

 Executing "after_prepare"  hook for all plugins.
1>  Resolving module name for cordova-lib/src/cordova/platform_metadata => ../cordova/platform_metadata
1>  Resolving module name for glob => glob
1>MSBUILD : cordova-build error : TypeError: undefined is not a function

I can't find this error. Do you knowwhat could it be? I'm using the last version of cordova i think

cordova.plugins.zeroconf is undefined

Hello,

I'm testing your plugin to simply display the hostname (for now) of the device on Android 6.0.1 from a computer running on Ubuntu 16.04.

I'm using the getHostname function in the same exact way as shown on the readme for this plugin and the console logs tell me cordova.plugins.zeroconf is Undefined.

Would you have an idea as to why I can't get it to work?

Use Android's Network Service Discovery (NSD)

NSD is available since Jelly Bean (API 16)

Objective:
Pre-Jelly Bean devices will use JmDNS
Jelly Bean and more recent devices will use NSD by default.

Important notes:
DnsSdTxtRecord support is only enabled since Lollilop (API 21) but does not seem to work.
Possible workaround using tinydnssd

Todos:
An option to disable NSD altogether

References:
http://developer.android.com/training/connect-devices-wirelessly/nsd.html
https://code.google.com/p/android/issues/detail?id=136099

[iOS] Adobe phonegap cloud build error

Since a couple of days I get the following error when trying to build my app for iOS.

Check dependencies
Not running swift-stdlib-tool: ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES is enabled, but the product type 'Static Library' is not a wrapper type.

[...]

Check dependencies
“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.
“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

** BUILD FAILED **

The following build commands failed:
Check dependencies
(1 failure)

Used plugins:

Installing "cordova-plugin-add-swift-support" at "1.6.0" for ios
Installing "cordova-plugin-device" at "1.1.4" for ios
Installing "cordova-plugin-console" at "1.0.5" for ios
Installing "cordova-plugin-whitelist" at "1.3.1" for ios
Installing "cordova-plugin-splashscreen" at "4.0.1" for ios
Installing "cordova-plugin-statusbar" at "2.2.1" for ios
Installing "ionic-plugin-keyboard" at "2.2.1" for ios
Installing "cordova-plugin-zeroconf" at "1.2.1" for ios

PhoneGap (iOS / Android / Windows):

cli-6.3.0 (4.2.0 / 5.2.1 / 4.4.1)

Is this something Adobe has to fix? The build is successful if the zeroconf plugin is removed form the config.xml

iOS PhoneGap Build error for undeclared type

Don't know if related to #10 but I can't get it built with Phonegap Build, also trying with cordova-plugin-add-swift-support added to plugin list.
Error is:

tmp/gimlet/2078210/project/build/JarvisDev.build/Release-iphoneos/JarvisDev.build/Objects-normal/arm64/ZeroConf.swiftdeps -o /tmp/gimlet/2078210/project/build/JarvisDev.build/Release-iphoneos/JarvisDev.build/Objects-normal/arm64/ZeroConf.o
/tmp/gimlet/2078210/project/JarvisDev/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:10:34: error: use of undeclared type 'CDVPlugin'
@objc(ZeroConf) class ZeroConf : CDVPlugin  {
                                 ^~~~~~~~~
/tmp/gimlet/2078210/project/JarvisDev/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:10:2: error: only classes that inherit from NSObject can be declared @objc
@objc(ZeroConf) class ZeroConf : CDVPlugin  {
~^~~~
/tmp/gimlet/2078210/project/JarvisDev/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:15:19: error: method does not override any method from its superclass
    override func pluginInitialize() {
    ~~~~~~~~      ^

Watcher call twice on each event.

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.

scn-20170725-171849-6yoab

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 as up 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.

scn-20170725-172524-j78f6

Is it problem of zeroconf plugin?
Because my code doesn't have anything that can call watcher function twice.

`watchOld() {
        console.log("Watch!")
         this.zeroconf.watch(this.config.connection_type, this.config.domain, (result) => {
               const action = result.action;
               const service = result.service;
                if (action === 'added') {
                   const address = service.ipv4Addresses.length > 1
                    ? service.hostname.replace(/\.$/, '')
                    : service.ipv4Addresses[0];
                console.log("Zeroconf watch result : ", address)
                this.emit('serviceUp', [address], service.port);
            } else if (action === 'removed') {
                this.emit('serviceDown', id);
            }
        }, (err) => {
            throw err;
        });
}`

Limiting connections

Is it possible to limit the number of connections to the server? or at least filter out the connections, like accept or decline a connection ??

cordova built error

Hi,

I'm getting a "build error " when building the project for android..
"undefined is no a function"
i'm using cordova version 6.1.1 with VS5015...

thanks

watch() never finds anything in my network on Android

Hello,
watch() function never returns a result. Even if I try .zeroconf.watch('local.', function(result) { and there a lot of services on my local network. Other Android Bonjour apps find these services without problems.

This is Android 6.0.1

[Android] Black Screen on Suspend/Resume

Hello,

After adding the plugin to our project and flashing the app on an Android device, we are experiencing a black screen when the app is suspended then launched again (hit the Back button till the Home screen is visible, wait for a minute or two then launch the app again) - there is a completely black screen which appears for around 10-15 seconds before the app launches itself again.

The black screen was not appearing before the plugin was added.

Here is the code, used pretty much as-is from the example on the Readme page:

$ionicPlatform.ready(function() {

         window.cordova.plugins.zeroconf.watch('_myservice._tcp.', 'local.', function(result) {

          var action = result.action;

          var service = result.service;

          if ('added' === action) {

              $window.alert('$ionicPlatform.ready: Found My service ' + service.name + " at " +
                        service.host + " at " + service.ipv4Addresses[0] + ", Port " + service.port);

          } else {

              $window.alert('$ionicPlatform.ready: Lost My service  ' + service.name + " at " +
                        service.host + " at " + service.ipv4Addresses[0] + ", Port " + service.port);

          }

      });    

}

Regards,
Manav

[Android] Nothing happens when wifi is enabled, Error when wifi is disabled

I am using this plugin along with cordova-plugin-websocket-server to make a multiplayer Android game. The server plugin is working fine, but the zeroconf plugin is not working . Nothing happens when I publish a service, no Success or Failure callback is fired . . . Same for "watch(type, domain, success, failure)", nothing happens .

ZeroConf freezing UI

Hi,

I set up a quick test to discover users present on the network.
When running in the iOS simulator (or on a real iPhone, Android phone) Xcode gives me following warning

ZeroConf: watch _http._tcp.local.
2016-02-21 16:23:28.528 HelloCordova[41819:3077447] THREAD WARNING: ['ZeroConf'] took '19.701172' ms. Plugin should use a background thread.

I get the same warning for other methods, e.g. "register".

I was not worrying about this warning until I added a button so that clicking the button calls the "stop" method. Clicking the button does not call my function which calls the "stop" method. Hence, I assume Xcode was right and ZeroConf is freezing the UI ?

This is the very basic code I have,

index.html :

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <title>ZeroConf Plugin Test</title>
        <script type="text/javascript">
            function stp() {
                document.getElementById("devices").innerHTML = "STOPPED";
                cordova.plugins.zeroconf.stop(); // Unregisters all published services
            }
        </script>
    </head>
    <body>
        <div class="app">
            <h1>Devices on network</h1>
            <button onclick="stp()">STOP</button>
            <div id="deviceready" class="blink">
                <p id="devices"></p>
            </div>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
    </body>
</html>

And index.js :

var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    // Bind any events that are required on startup.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    onDeviceReady: function() {
        var el = document.getElementById("devices");
        var zeroconf = cordova.plugins.zeroconf;

        if(!(cordova.plugins && (typeof zeroconf !== 'undefined'))) {
            el.innerHTML = "ZEROCONF NOT READY";
        }

        zeroconf.watch('_http._tcp.local.', function(result) {
            var action = result.action;
            var service = result.service;

            if(action == 'added') {
                el.innerHTML = el.innerHTML + "Found device : " + result.service['name'] + "<br/>";
            }
            else {
                el.innerHTML = el.innerHTML + "Device " + result.service['name'] + " disconnected<br />";
            }
        });

        zeroconf.register('_http._tcp.local.', 'Test Name', 80, {
            'foo' : 'bar'
        });
    },
};

app.initialize();

Running this test you'll notice the "stp" function is not called upon clicking the button.

Thanks in advance! :)

Find services without WiFi

  1. Wifi on -> Find services
  2. Wifi off, only 3G:
  • this.zeroconf.stop();
  • this.zeroconf.unwatch('_name._tcp.', 'local.');
    After user press button, I reload everything, even bonjour (watch..)

BONJOUR FIND SAME SERVICES (as added)

Is there any kind of cache that it needs to be clean?

[Android] zeroconf.watch Error

Hi . . .I am trying to use this plugin in an Android app, but whenever I start to watch for server, i get an error saying "Error: setsockopt failed: ENODEV (No such device)" . . . What does it mean and how to fix it ?? By the way, for the server part I'm using cordova-plugin-websocket-server . . . Thanks in advance.

[iOS] watch return 'null'

I wrote this code in Ionic 2 project:

    var zeroconf = (<any>window).cordova.plugins.zeroconf;
    zeroconf.registerAddressFamily = 'ipv4'; // or 'ipv6' ('any' by default)
    zeroconf.watchAddressFamily = 'ipv4'; // or 'ipv6' ('any' by default)
    zeroconf.watch('_myservice._tcp', '.local.',
      function(result:any) {
        console.log("dev:" + JSON.stringify(result));
      },
      function(err:any){
          console.log("err: "+err)
        }
      );

This code works on Android (tested), but in iOS doesn't work (it doesn't find my device). In particular, in iOS returns "null" in failure callback. I'm using Xcode 8.3.3 and Swift 3. How can I resolve this? What version of Xcode did you use?

Many thanks!

[Android] zeroconf.watch event with service without ipv4Addresses

Hi becvert,
I've a problem using your plugin with Android device. In particular, I receive, on "watch", event without ipv4Addresses; at first call, I can simply check if service does not contain ipv4Addresses (because I receive duplicate service, one with ipv4Addresses, one without ipv4Addresses). When I go out and return in a app page that use zeroconf, it returns only service without ipv4Addresses. How can I resolve this? This is my code:

  ionViewDidLoad(){
    var self = this;
    this.platform.ready().then(() =>{
      if((<any>window).cordova && (<any>window).cordova.plugins){
        var zeroconf = (<any>window).cordova.plugins.zeroconf;
        zeroconf.registerAddressFamily = 'ipv4'; // or 'ipv6' ('any' by default)
        zeroconf.watchAddressFamily = 'ipv4'; // or 'ipv6' ('any' by default)
        zeroconf.watch('_myservice._tcp.', 'local.',
          function(result:any) {
            var exists_name = false;
            for(var i = 0; i < self.List.length; i++){
              if(self.List[i].name == result.service.name)
                exists_name = true;
            }
            if(!exists_name && result.service.ipv4Addresses.length > 0){
              self.List.push(result.service);
              self.zone.run(() => { }); // update ngFor externally
            }
          },
          function(err:any){
              console.log("err: "+err)
            }
          );
        }
    })

      var self = this;
      var foo_timeout2 = true;
      setTimeout(
        function(){
          if(foo_timeout2){
            self.timeElapsed = true;
          }
      },10000);
  }

I'm using Ionic (3.13.0 but same problem with previous versions), tested on Samsung Galaxy S4 (Android 5.0.1) and Wiko Fever (Android 6.0).
Thanks for help!

Not finding some services

Sometimes, it doesnt find all services I have on. I double checked they were on with with Safari bonjour. After closing zeroconf and opening it several times, it found it.

This happens very often.

Zeroconf 1.2.4 - Android 7 - ionic 3.3.0

How do I use this?

Hi,

I want to run the code inside cordova android app to map 192.168.43.1:8080 to my-android.local, so that if I type http://my-android.local:8080 in Google Chrome chrome on the Android device, it will resolve. Is this possible ? Or, would it work if I remove the port number altogether?

I was trying to use the plugin, and registered things like these:

zeroconf.register('_http._tcp.', 'local', 'kukureku7', 8080, {
    'foo2' : 'bar2'
}, function success(result){
    var action = result.action; // 'registered'
    var service = result.service;
    console.log("in callback: ", action, service);
});

and I got this response,

{domain: "local.", type: "_http._tcp.", name: "kukureku7", port: 8080, hostname: "android-4ce82332a09e2883.local.", …}

What is the weird android domain android-4ce... -- is this the device name of my Google Nexus ?
In any case, accessing using kukureku7.local:8080 or just kukureku7.local didn't work. Neither from the phone nor macbook.

I have registered with the watch api, and I got this in the log,

service resolved 
{domain: "local.", type: "_http._tcp.", name: "kukureku7", port: 8080, hostname: "android-4ce82332a09e2883.local.", …}

So, someone is resolving it, but I don't know who.

I installed Zeroconf Browser app, and it shows an "HTTP server", but doesn't provide any detail.

Boris

iOS production release crash

An iOS build using Ionic (not sure applicable to other frameworks but possibly) works in debug mode but it causes an immediate application crash in the production/release mode.

Problem can be solved by adding "@executable_path/Frameworks" to Runpath Search Paths for Release (it is already there for Debug).

There used to be instructions for this in the README before, but they were removed by f5d2a77 commit.

[Android] Nullpointer exception for unwatch

Hi,

since upgrading from version 1.2.4 to 1.2.7 android devices cannot find advertised mdns services. Error log gives me the following:

java.lang.NullPointerException: Attempt to invoke direct method 'void net.becvert.cordova.ZeroConf$BrowserManager.unwatch(java.lang.String, java.lang.String)' on a null object reference
at net.becvert.cordova.ZeroConf$BrowserManager.access$700(ZeroConf.java:384)
at net.becvert.cordova.ZeroConf$5.run(ZeroConf.java:276)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)

I've since gone back to using 1.2.4 again.
Great plugin, hope the above details suffice to solve the issue!

Regards

Failing to find a service if already running

Hi there,

thanks for the great plugin.

I am using Tuneblade (PC) and trying to find the Tuneblade service (from Android).
But the service only shows up if I start Tuneblade (PC) after I start zeroconf.watch (Android)

Further I saw the other bugs and it takes at least 20 seconds for the first device to show up.

For me it would be good enough to have a zeroconf.list to show all currently registered devices (not sure if zeroconf supports this).

Discovering all services

Hi,

The plugin works great to discover service by known types, for example

zeroconf.watch('_http._tcp.', 'local.', function(result) { ...

It works perfectly on android and ios.

But is there a way to discover for exemple all _tcp. services ?

I tried:

zeroconf.watch('_tcp.', 'local.', function(result) {

...nothing

Any idea ?

Regards,

Zeroconf on 169.254.x.x

My apologies for asking this hear, but I figured someone looking this plug-in would probably have the correct answer. I am using this zerocof plugin to discover a device on my network, however when we first connect to the device to configure it we do it directly. i.e., choose that wifi network, and perform the connection. The device doesn't have a DHCP service on it, so it doesn't set an IP address and we fall back to the 169.254.x.x address. I see the device through this plug-in, so I know we can find it. But I can't connect to that device using the hostname. Note that the device defaults its own IP address as 192.168.1.23 and if I change my TCPIP settings manually to make my computer 192.168.1.100 (or anything) I can use this hostname to control it. Can anyone confirm that you can't actually talk to the device if it is set-up as above?

I really appreciate the feedback!

If anyone else has a better place for me to ask this, please let me know too!

No error callback in watch

Thanks for creating this plugin, i've been looking for it for quite a while! However, i am unable to check if a certain device is present. If the the service is not found, i cannot get an error or timeout event. Can you help me?

zeroconf.watch('_customservice._tcp.local.', function(result) {
var action = result.action;
var service = result.service;
if(!result) {
//do something here
}
if (action == 'added') {
console.log('service found', JSON.stringify(service.addresses[0]));
} else {
console.log('something else');
}
});

or

zeroconf.watch('service._tcp', function(succes, error) {
// etc.
}

or zeroconf.watch('service._tcp')
.then, function (data) {
//etc
}
.catch, function(error) {
}

Would that be possible?

[iOS] zeroconf.close never invokes success/error callback

The behaviour of zeroconf.close() is inconsistent between Android and iOS. While Android sends a plugin result, iOS does not. As the Android version uses a background thread, it is necessary to rely on the callback to make sure the action has finished.

A simple solution would be to send a success plugin result in iOS as well.

Service not found on android when name is ip address

Hi,

I'm using the plugin for one of my projects, until now I tested it on iOS and it works fine.
However, on Android (Nexus 5 phone) the published services are not found.

Because I don't want my app to publish accidentally a service with the same name as another one I'm using the machine's ip address as name, hence it will be unique. But Android refuses to publish them.

I made a minimal example that shows the problem :

var zeroconf = cordova.plugins.zeroconf;
zeroconf.watch('_http._tcp.local.', function(result) { 
    // Display result.service.name --> Displayed on iOS but not on Android
});

// If below i provide as name '192/168/0/205' it also works on Android, but with the points not...
zeroconf.register('_http._tcp.local.', '192.168.0.205', 80, {
        'foo' : 'bar'
});

[Android, iOS] Expose init to accommodate wifi AP changes

Associated PR: #50

I am dealing with a scenario in which users are required to change their Wifi AP connection while the app is running. This app uses Wifi to connect to a hardware device in AP mode - the hardware device then broadcasts services, and the app scans the "network" (really just the phone and the single hardware device) for services to connect to. The app tells users how to change Wifi networks, and guides them towards the proper Wifi settings screen in their OS. The hardware devices can also be added to an existing network (ie. they can operate in STA mode), but our primary setup for now is to have the hardware create an access point.

We have discovered that scanning for services is very unreliable when switching Wifi networks. Each OS "caches" scan results a bit differently, but in general the services discovered when the app first starts persist even when Wifi networks are changed.

My testing scenario looks like this: DEVICE_1 and DEVICE_2 exist in the office. DEVICE_1 is STA mode and connects to OFFICE_AP, while DEVICE_2 is in AP mode and creates DEVICE_2_AP. The phone/app first connects to OFFICE_AP and discovered DEVICE_1, then the user changes the phone Wifi connection over to DEVICE_2_AP. At this point, DEVICE_2 does not get discovered, and DEVICE_1 remains in the scan results list, even if zeroconf.watch() is called again.

This is problematic even for only 1 device, as the device will never be discovered if the user changes Wifi networks while the app is open. Right now we show users a big warning that tells them to completely close and re-open the app - doing so gets the scan to find the correct services.

I believe that this is primarily due to the Zeroconf browser instantiation being performed on app init, particularly in Android's case. https://github.com/becvert/cordova-plugin-zeroconf/blob/master/src/android/net/becvert/cordova/ZeroConf.java#L66 is only called on app startup, and as such the Wifi instances here seem to be bound to the network that is connected during boot.

I have tested the close() method and discovered that it throws an error if you call it after changing Wifi networks. Here is an example of me calling watch(), changing Wifi networks, then calling close():

[ 11-20 17:36:04.961  4334: 4458 D/ZeroConf ]
Watch _emcniece._tcp.local.

[ 11-20 17:36:05.017  4334: 5606 E/ZeroConf ]
setsockopt failed: ENODEV (No such device)
java.net.SocketException: setsockopt failed: ENODEV (No such device)
	at libcore.io.IoBridge.setSocketOption(IoBridge.java:321)
	at java.net.PlainDatagramSocketImpl.setOption(PlainDatagramSocketImpl.java:189)
	at java.net.PlainDatagramSocketImpl.join(PlainDatagramSocketImpl.java:128)
	at java.net.MulticastSocket.joinGroup(MulticastSocket.java:149)
	at javax.jmdns.impl.JmDNSImpl.openMulticastSocket(JmDNSImpl.java:474)
	at javax.jmdns.impl.JmDNSImpl.<init>(JmDNSImpl.java:423)
	at javax.jmdns.JmDNS.create(JmDNS.java:155)
	at net.becvert.cordova.ZeroConf$BrowserManager.<init>(ZeroConf.java:434)
	at net.becvert.cordova.ZeroConf$4.run(ZeroConf.java:276)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
	at java.lang.Thread.run(Thread.java:818)
Caused by: android.system.ErrnoException: setsockopt failed: ENODEV (No such device)
	at libcore.io.Posix.setsockoptGroupReq(Native Method)
	at libcore.io.ForwardingOs.setsockoptGroupReq(ForwardingOs.java:153)
	at libcore.io.IoBridge.setSocketOptionErrno(IoBridge.java:391)
	at libcore.io.IoBridge.setSocketOption(IoBridge.java:319)
	... 11 more

The solution to this may be to create a method in which we can re-init the plugin. https://github.com/becvert/cordova-plugin-zeroconf/pull/50/files#diff-a9beaeb5801c88e06e5384461d466bd3R337 is a (probably not great) example of how this can be accomplished - here I am directly calling the destroy and init functions for Android.

... and it works! With this, I am able to watch network changes with @ionic-native/network and call zeroconf.reInit() - the previously results are cleared, and the new results are detected immediately.

iOS seems to have this problem as well, but I have done less testing there as my iOS device has been absent for a few days. In any case, this PR clones the behaviour in iOS to ensure symmetry.

Though I can't confirm it, this proposal may help with a few issues:

To test this, I have been using my fork with a hacked @ionic-native/zeroconf version. The Ionic Native module needs a few things added to it:

node_modules/@ionic-native/zeroconf/index.d.ts:

// tack on at the bottom
reInit(): Promise<void>;

node_modules/@ionic-native/zeroconf/index.js (generated, I know - just not sure when or where):

// existing code...
__decorate([
        Cordova(),
        __metadata("design:type", Function),
        __metadata("design:paramtypes", []),
        __metadata("design:returntype", Promise)
    ], Zeroconf.prototype, "close", null);
// new stuff here:
    __decorate([
        Cordova(),
        __metadata("design:type", Function),
        __metadata("design:paramtypes", []),
        __metadata("design:returntype", Promise)
    ], Zeroconf.prototype, "reInit", null);

Since I want to use the Rx model provided with @ionic-native/zeroconf, this is a bit of a pain to develop around... my CI pipe is unusable until I fork @ionic-native/zeroconf or until this proposal gets accepted and integrated.

What are your thoughts on this @becvert ?

Closing the service is too slow

Hi,

It takes about 10 seconds to get the promise's result from the close() method. Why is it so slow? What is it really doing when closing the service?

Thanks!

[iOS] "OBJC_CLASS$_Hostname" not found

I keep getting this error, no matter what i try:

Undefined symbols for architecture x86_64:
"OBJC_CLASS$_Hostname", referenced from:
objc-class-ref in ZeroConf.o
ld: symbol(s) not found for architecture x86_64

Any clue as to what is happening?

Cordova 4 update

Hi !

cordova-plugin-zeroconf was perfectly woking until I upgraded to cordova 4.
It seems to have also upgraded swift. Now at runtime I have a crash here: ZeroConf.swift:52.
publishers[fullType + "@@@" + name] = publisher

Im absolutly not fluent in swift, so I dont know why it is broken :)

[Browser] Any interest in a browser version?

Currently I am using a small mock server to produce mDNS query results during browser-based development. It does look like I could convert this standalone service into a package that could be used inside this plugin.

Functionality might not be identical, but it would at least give us something to work with during local development.

Would this be useful for anyone else?

unwatch crash on android

Hi !

You should check browser in unwatch method:
private void unwatch(String type) { if (browser != null) browser.removeServiceListener(type, this); }

All Platforms: scanning now fails consistently

After the 1.2.6 upgrade, our app started failing to produce scan results. We are manually filtering for Ipv4 addresses, so Android shows nothing (more details in the following comments), while iOS seems to be unwatching when we don't expect it to. This issue may be caused by us handling this plugin in a way that was not intended, and it might be because of some recent changes.

Currently investigating, wanted to send a heads up. I updated this plugin today and it has started failing on every scan. Our recent build moved cordova-plugin-zeroconf from 1.2.5 to 1.2.6. Details to follow asap.

$ ionic info

cli packages:

    @ionic/cli-plugin-cordova       : 1.6.2
    @ionic/cli-plugin-ionic-angular : 1.4.1
    @ionic/cli-utils                : 1.7.0
    ionic (Ionic CLI)               : 3.7.0

global packages:

    Cordova CLI : 7.0.1

local packages:

    @ionic/app-scripts : 2.0.2
    Cordova Platforms  : android 6.2.3 browser 4.1.0 ios 4.4.0
    Ionic Framework    : ionic-angular 3.5.2

System:

    Android SDK Tools : 25.2.5
    Node              : v8.3.0
    OS                : macOS Sierra
    Xcode             : Xcode 8.3.3 Build version 8E3004b
    ios-deploy        : 1.9.1
    npm               : 4.2.0
$ cordova plugins
cordova-fabric-plugin 1.1.9 "cordova-fabric-plugin"
cordova-ios-export-compliance 1.0.2 "iOS Export Compliance"
cordova-open-native-settings 1.4.1 "Native settings"
cordova-plugin-add-swift-support 1.7.0 "AddSwiftSupport"
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-console 1.0.7 "Console"
cordova-plugin-device 1.1.6 "Device"
cordova-plugin-ios-disableshaketoedit 1.0.0 "iOS Disable Shake to Edit"
cordova-plugin-network-information 1.3.3 "Network Information"
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-statusbar 2.2.3 "StatusBar"
cordova-plugin-whitelist 1.3.2 "Whitelist"
cordova-plugin-zeroconf 1.2.6 "ZeroConf"
cordova-sqlite-storage 2.0.4 "Cordova sqlite storage plugin"

Unwatch never send success callback

Hello!

I notice that unwatch function never send success callback.

never-unwatch

My code

return new Promise((resolve, reject) => this.zeroconf.unwatch(this.config.connection_type, this.config.domain, (result) => resolve(result), (err) => reject(err)));

Right now Im using service.closeforunwatch`.

Hostname for iOS

Is it possible to add a resolved hostname of the service into the watch callback?

So that I would be possible to build an URL like "http://"+service.host+":"+service.port (e.g. to get http://myserver.local:8080) instead of looking up the right IP from the addresses array.

If I'm right, there should already the right thing, which could be passed into the service object of the callback:
https://developer.apple.com/reference/foundation/netservice/1413300-hostname
However, I'm not (yet) familiar with swift/objective-c, so I could not implement it myself :(
Android has this already in the property "service.server", but iOS not.

Background story:
the server, which publishes the service, has IPv6 & IPv4 and sometimes the zeroconf plugin only receives the IPv6 address (sometime only IPv4 and sometime both). Since I use the IP for opening an InAppBrowser and the InAppBrowser cannot handle URLs with IPv6 addresses, I cannot connect to the server. Therefore, a hostname would be working - regardless of the type of IP and the underlaying network type (v6 or v4). Furthermore, Apple has also a new requirement that forces the usage of IPv6, so it would be better to use the hostname and let the local DNS resolving the IP address instead of using the IP directly.

Unable to build application on Phonegap 5.1.1

Hi! I have tried to build phonegap application using your plugin, here's how I included it in config.xml:

    <gap:plugin name="cordova-plugin-zeroconf" source="npm" />
    <preference name="deployment-target" value="7.0" />

But I got this error:

** BUILD FAILED **


The following build commands failed:
    CompileSwift normal arm64 /project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift
    CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(2 failures)

Here is full stack trace from Phonegap ios log:

CompileSwift normal arm64 /project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift
    cd /project
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift -target arm64-apple-ios7.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.1.sdk -I /project/build -F /project/build -g -serialize-debugging-options -Xcc -I/project/build/AcmlControl.build/Release-iphoneos/AcmlControl.build/swift-overrides.hmap -Xcc -iquote -Xcc /project/build/AcmlControl.build/Release-iphoneos/AcmlControl.build/AcmlControl-generated-files.hmap -Xcc -I/project/build/AcmlControl.build/Release-iphoneos/AcmlControl.build/AcmlControl-own-target-headers.hmap -Xcc -I/project/build/AcmlControl.build/Release-iphoneos/AcmlControl.build/AcmlControl-all-target-headers.hmap -Xcc -iquote -Xcc /project/build/AcmlControl.build/Release-iphoneos/AcmlControl.build/AcmlControl-project-headers.hmap -Xcc -I/project/build/include -Xcc -I/project/build/usr/local/lib/include -Xcc -I/project/build/UninstalledProducts/include -Xcc -I/project/build -Xcc -I/project/build/AcmlControl.build/Release-iphoneos/AcmlControl.build/DerivedSources/arm64 -Xcc -I/project/build/AcmlControl.build/Release-iphoneos/AcmlControl.build/DerivedSources -Xcc -working-directory/project -emit-module-doc-path /project/build/AcmlControl.build/Release-iphoneos/AcmlControl.build/Objects-normal/arm64/ZeroConf~partial.swiftdoc -O -parse-as-library -module-name AcmlControl -emit-module-path /project/build/AcmlControl.build/Release-iphoneos/AcmlControl.build/Objects-normal/arm64/ZeroConf~partial.swiftmodule -serialize-diagnostics-path /project/build/AcmlControl.build/Release-iphoneos/AcmlControl.build/Objects-normal/arm64/ZeroConf.dia -emit-dependencies-path /project/build/AcmlControl.build/Release-iphoneos/AcmlControl.build/Objects-normal/arm64/ZeroConf.d -emit-reference-dependencies-path /project/build/AcmlControl.build/Release-iphoneos/AcmlControl.build/Objects-normal/arm64/ZeroConf.swiftdeps -o /project/build/AcmlControl.build/Release-iphoneos/AcmlControl.build/Objects-normal/arm64/ZeroConf.o
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:10:34: error: use of undeclared type 'CDVPlugin'
@objc(ZeroConf) class ZeroConf : CDVPlugin  {
                                 ^~~~~~~~~
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:10:2: error: only classes that inherit from NSObject can be declared @objc
@objc(ZeroConf) class ZeroConf : CDVPlugin  {
~^~~~
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:15:19: error: method does not override any method from its superclass
    override func pluginInitialize() {
    ~~~~~~~~      ^
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:20:19: error: method does not override any method from its superclass
    override func onAppTerminate() {
    ~~~~~~~~      ^
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:32:28: error: use of undeclared type 'CDVInvokedUrlCommand'
    func register(command: CDVInvokedUrlCommand) {
                           ^~~~~~~~~~~~~~~~~~~~
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:59:30: error: use of undeclared type 'CDVInvokedUrlCommand'
    func unregister(command: CDVInvokedUrlCommand) {
                             ^~~~~~~~~~~~~~~~~~~~
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:75:24: error: use of undeclared type 'CDVInvokedUrlCommand'
    func stop(command: CDVInvokedUrlCommand) {
                       ^~~~~~~~~~~~~~~~~~~~
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:86:25: error: use of undeclared type 'CDVInvokedUrlCommand'
    func watch(command: CDVInvokedUrlCommand) {
                        ^~~~~~~~~~~~~~~~~~~~
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:104:27: error: use of undeclared type 'CDVInvokedUrlCommand'
    func unwatch(command: CDVInvokedUrlCommand) {
                          ^~~~~~~~~~~~~~~~~~~~
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:119:25: error: use of undeclared type 'CDVInvokedUrlCommand'
    func close(command: CDVInvokedUrlCommand) {
                        ^~~~~~~~~~~~~~~~~~~~
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:138:30: error: use of undeclared type 'CDVCommandDelegate'
        var commandDelegate: CDVCommandDelegate?
                             ^~~~~~~~~~~~~~~~~~
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:194:30: error: use of undeclared type 'CDVCommandDelegate'
        var commandDelegate: CDVCommandDelegate?
                             ^~~~~~~~~~~~~~~~~~
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:53:37: error: use of unresolved identifier 'commandDelegate'
        publisher.commandDelegate = commandDelegate
                                    ^~~~~~~~~~~~~~~
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:98:35: error: use of unresolved identifier 'commandDelegate'
        browser.commandDelegate = commandDelegate
                                  ^~~~~~~~~~~~~~~
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:213:32: error: use of unresolved identifier 'CDVPluginResult'
            let pluginResult = CDVPluginResult(status: CDVCommandStatus_NO_RESULT)
                               ^~~~~~~~~~~~~~~
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:213:56: error: use of unresolved identifier 'CDVCommandStatus_NO_RESULT'
            let pluginResult = CDVPluginResult(status: CDVCommandStatus_NO_RESULT)
                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:231:32: error: use of unresolved identifier 'CDVPluginResult'
            let pluginResult = CDVPluginResult(status: CDVCommandStatus_NO_RESULT)
                               ^~~~~~~~~~~~~~~
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:231:56: error: use of unresolved identifier 'CDVCommandStatus_NO_RESULT'
            let pluginResult = CDVPluginResult(status: CDVCommandStatus_NO_RESULT)
                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:269:36: error: use of unresolved identifier 'CDVPluginResult'
                let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAsDictionary: message as [NSObject : AnyObject])
                                   ^~~~~~~~~~~~~~~
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:269:60: error: use of unresolved identifier 'CDVCommandStatus_OK'
                let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAsDictionary: message as [NSObject : AnyObject])
                                                           ^~~~~~~~~~~~~~~~~~~
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:282:32: error: use of unresolved identifier 'CDVPluginResult'
            let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAsDictionary: message as [NSObject : AnyObject])
                               ^~~~~~~~~~~~~~~
/project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift:282:56: error: use of unresolved identifier 'CDVCommandStatus_OK'
            let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAsDictionary: message as [NSObject : AnyObject])
                                                       ^~~~~~~~~~~~~~~~~~~

** BUILD FAILED **


The following build commands failed:
    CompileSwift normal arm64 /project/AcmlControl/Plugins/cordova-plugin-zeroconf/ZeroConf.swift
    CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(2 failures)

I am using 5.1.1 version:
<preference name="phonegap-version" value="cli-5.1.1" />

Please answer if you need more information, I will provide it as soon as possible. Thank you in advance for looking for this problem.

Greetings,
Radek.

P.S.

It happened for both 1.0.1 and 1.1.0 versions.

Service Announcements delayed on Android

The zeroconf.watch method takes up to 30 seconds-1 minute to receive a service announcement on Android, whereas the announcement is almost instant on iOS. Any idea what might account for the difference in user experience and how it might be resolved?

Bad_access error in watch function on IOS

watch function caused Bad_access error. It appears that the browsers object is not allocated at the time when a new browser is added.

`

func watch(command: CDVInvokedUrlCommand)
.............
browser.commandDelegate = commandDelegate
browser.watch()

  browsers = [String: Browser]()    < added  this line, fixed the issue.

browsers[fullType] = browser
`

Proposal: expose DHCP Info

@becvert what are your thoughts on making the DHCP information available through this plugin? Should DHCP info be available here, or should it be a separate plugin?

I have a use-case for handling services differently based on the network that a mobile device is connected to. Especially in the case that mobile data is enabled and I can't rely on jmDNS to return accurate results.

I haven't found any other @ionic-native plugins that make this information available, and cordova-plugin-zeroconf already has access to the API methods that make this data available.

Example:

zeroconf.getDhcpInfo(
  function(dhcpInfo){
    console.log('DHCP Info', dhcpInfo);
  },
  function(error){
    console.error('Zeroconf error', error
  }
);

=> "DHCP Info" {
  ipAddr: "192.168.37.151",
  gateway: "192.168.37.1",
  netmask: "255.255.255.0",
  dns1: "10.0.0.2",
  dns2: "0.0.0.0",
  server: "192.168.37.1",
  lease: "3600"
}

Platform references:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.