scottdermott / cordova-plugin-discovery

Cordova Service Discovery Plugin for Android & iOS
MIT License
31 stars 30 forks source link

Takes a very long time to find the right device #19

Open renat2985 opened 5 years ago

renat2985 commented 5 years ago

Can You please tell me if there is anyway to speed up search for a required devices My script search for device with name arduino and opens it in iframe. Thanks.

var app = {
 initialize: function() {
  document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
 },

 onDeviceReady: function() {
  this.receivedEvent('deviceready');

  var serviceType = "upnp:rootdevice";
  var success = function(devices) {

   for (var key in devices) {
    if (devices[key].Server.slice(0, 7) == 'Arduino') {
     if (key == '1') {
      document.getElementById("loadweb").src = 'http://'+devices[key].LOCATION.split('/')[2].split(':')[0];
     }
    }
   }
  }
  var failure = function() {
   alert("Error calling Service Discovery Plugin");
  }
  serviceDiscovery.getNetworkServices(serviceType, success, failure);
 },
 receivedEvent: function(id) {
  var parentElement = document.getElementById(id);
  var listeningElement = parentElement.querySelector('.listening');
  var receivedElement = parentElement.querySelector('.received');
  listeningElement.setAttribute('style', 'display:none;');
  receivedElement.setAttribute('style', 'display:block;');
  console.log('Received Event: ' + id);
 }
};
app.initialize();