trik / capacitor-zeroconf

Cordova ZeroConf Plugin
6 stars 7 forks source link

The plugin is causing delay #4

Open Aymkdn opened 3 months ago

Aymkdn commented 3 months ago

The plugin causes a 20-30 seconds delay to my app.

Here is what I'm doing:

let watchRequest = {
  type: "_fbx-api._tcp.",  // par exemple "_http._tcp"
  domain: "local."         // par exemple "local."
};

let callback = (event) => {
  if (event) {
    this.zeroConf.event = event;
    if (event.action === "resolved") {
      if (this.zeroConf.callbackId) {
        ZeroConf.unwatch(this.zeroConf.callbackId);
      }
      ZeroConf.close();
      this.modal.debug.zeroconf = "RESOLVED";
      let ip = event.service.ipv4Addresses[0];
      if (ip) {
        this.modal.debug.zeroconf = "OK ("+ip+")";
        this.freeboxIP = ip;
      }
    } else {
      this.modal.debug.zeroconf = event.action;
    }
  }
};

ZeroConf.watch({
  type: "_fbx-api._tcp.",
  domain: "local."
}, callback)
.then(callbackId => {
  this.zeroConf.callbackId = callbackId;
})
.catch((error) => {
  console.error('Erreur lors du démarrage du watch:', error);
});

And here is the logcat:

2024-08-01 17:44:42.581 22547-23102 ZeroConf Added 2024-08-01 17:44:42.583 22547-23102 ZeroConf Resolved 2024-08-01 17:44:42.587 22547-22547 ZeroConf Unwatch nullnull 2024-08-01 17:44:42.588 22547-22547 ZeroConf Close 2024-08-01 17:45:04.631 22547-22547 Choreographer Skipped 528 frames! The application may be doing too much work on its main thread.

If I remove the code, my app works just fine. Am I doing something incorrect?

Aymkdn commented 3 months ago

FYI, I tried another plugin that works much faster:

npm install @ionic-native/zeroconf cordova-plugin-zeroconf

And in my app:

import { Zeroconf } from "@ionic-native/zeroconf"

[…]
Zeroconf.registerAddressFamily = 'ipv4';
Zeroconf.watchAddressFamily = 'ipv4';
Zeroconf.watch("_fbx-api._tcp.", "local.").subscribe(result => {
  if (result.action === "resolved") {
    Zeroconf.unwatch('_fbx-api._tcp.', 'local.');
    Zeroconf.close();
    this.modal.debug.zeroconf = "RESOLVED";
    let ip = result.service.ipv4Addresses[0];
    if (ip) {
      this.modal.debug.zeroconf = "OK";
      this.freeboxIP = ip;
    }
  } else {
    this.modal.debug.zeroconf = result.action;
  }
});

Logcat:

2024-08-02 16:37:27.980 10951-11122 ZeroConf D Added 2024-08-02 16:37:27.981 10951-11122 ZeroConf D Sending result: {"action":"added","service":{"domain":"local.","type":"_fbx-api._tcp.","name":"Freebox Server","port":0,"hostname":"Freebox Server._fbx-api._tcp.local.","ipv4Addresses":[],"ipv6Addresses":[],"txtRecord":{"Freebox Server._fbx-api._tcp.local.":"true"}}} 2024-08-02 16:37:27.983 10951-11122 ZeroConf D Resolved 2024-08-02 16:37:27.984 10951-11122 ZeroConf D Sending result: {"action":"resolved","service":{"domain":"local.","type":"_fbx-api._tcp.","name":"Freebox Server","port":80,"hostname":"","ipv4Addresses":["192.168.0.254"],"ipv6Addresses":[],"txtRecord":{"https_port":"23121","uid":"5c8d5a13cf46a227ee6ad7d0fd192b9a","https_available":"1","box_model_name":"Freebox v7 (r1)","device_type":"FreeboxServer7,1","api_domain":"gqtfxpb7.fbxos.fr","box_model":"fbxgw7-r1\/full","api_base_url":"\/api\/","api_version":"12.0"}}} 2024-08-02 16:37:28.299 10951-11040 ZeroConf D Unwatch _fbx-api._tcp.local. 2024-08-02 16:37:28.300 10951-11040 ZeroConf D Close 2024-08-02 16:37:31.834 10951-11130 ProfileInstaller D Installing profile for info.kodono.pop_files