diff --git a/lib/agent/triggers/control-zones/index.js b/lib/agent/triggers/control-zones/index.js index 257659ac6..a246c4e5a 100644 --- a/lib/agent/triggers/control-zones/index.js +++ b/lib/agent/triggers/control-zones/index.js @@ -43,6 +43,8 @@ var emitter, retryTimeOut, checking = false; +let timerActionStart; + var push_event = function(type, zone_id, coords) { coords.id = zone_id.id; var data = { @@ -90,9 +92,11 @@ var check_zones = function() { // distance comes in KM, so we transform to M to compare if (distance * 1000 > zone.radius) { // outside - storage.do('update', { type: 'geofences', id: zone.id, columns: 'state', values: 'outside' }, (err) => { - if (err) logger.error(err); + if (err) { + logger.error(err); + return; + } if (zone.state == 'inside' && zone.direction !== 'in') { logger.info('Device left the geofence ' + zone.name + '! Notifying') hooks.trigger('geofencing_out', zone.id) @@ -101,11 +105,12 @@ var check_zones = function() { checking = false; zone.state = 'outside'; }); - } else { // inside - storage.do('update', { type: 'geofences', id: zone.id, columns: 'state', values: 'inside' }, (err) => { - if (err) logger.error(err); + if (err) { + logger.error(err); + return; + } if ((zone.state == 'outside' && zone.direction !== 'out') || zone.state == null) { logger.info('Device got inside the geofence ' + zone.name + '! Notifying') hooks.trigger('geofencing_in', zone.id) @@ -114,7 +119,6 @@ var check_zones = function() { checking = false; zone.state = 'inside'; }); - } }); } @@ -160,12 +164,15 @@ exports.start = function(opts, cb) { hooks.on('connected', function() { clearTimeout(retryTimeOut) attempts = 0; - - action.start(); + if (timerActionStart) clearTimeout(timerActionStart); + timerActionStart = setTimeout(() => { + action.start(); + }, 1000 * 15); }) // No need to keep checking the location until it's connected again hooks.on('disconnected', function() { + if (timerActionStart) clearTimeout(timerActionStart); clearTimeout(retryTimeOut) attempts = 0; }) diff --git a/test/lib/agent/providers/geo/geonative_strategy.js b/test/lib/agent/providers/geo/geonative_strategy.js index 90cfa464e..d954fa917 100644 --- a/test/lib/agent/providers/geo/geonative_strategy.js +++ b/test/lib/agent/providers/geo/geonative_strategy.js @@ -9,6 +9,7 @@ var helpers = require('./../../../../helpers'), geo = { darwin: require(join(geo_path, 'darwin')), linux: require(join(geo_path, 'linux')), + win32: require(join(geo_path, 'win32')), win: require(join(geo_path, 'win32')), }, geonative_strat = helpers.load('providers/geo/strategies').native; @@ -26,6 +27,11 @@ describe('native geoloc', function () { } var successful_location = { + win32: { + lat: 38.707163, + lng: -9.135517, + accuracy: 140000.0 + }, win: { lat: 38.707163, lng: -9.135517,