diff --git a/CHANGELOG.md b/CHANGELOG.md index e9fd89c..fa68d3a 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Tracman Server Changelog ###### v0.8.0 +* Added check to ensure only the newest location is sent * Removed buggy login/-out redirects * [#111](https://github.com/Tracman-org/Server/issues/111) Implemented service worker * [#116](https://github.com/Tracman-org/Server/issues/116) Switched promises for async/await diff --git a/README.md b/README.md index babad1d..9a3130b 100755 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ Tracman will be updated according to [this branching model](http://nvie.com/post [view full changelog](CHANGELOG.md) #### v0.8.0 +* Added check to ensure only the newest location is sent * Removed buggy login/-out redirects * [#111](https://github.com/Tracman-org/Server/issues/111) Implemented service worker * [#116](https://github.com/Tracman-org/Server/issues/116) Switched promises for async/await diff --git a/config/sockets.js b/config/sockets.js index b12f77a..406287d 100755 --- a/config/sockets.js +++ b/config/sockets.js @@ -63,7 +63,7 @@ module.exports = { debug(`Location was set to: ${JSON.stringify(loc)}`) // Get android timestamp or use server timestamp - if (loc.ts) loc.tim = Date(loc.ts) + if (loc.ts) loc.tim = +loc.ts else loc.tim = Date.now() // Check for user and sk32 token @@ -93,19 +93,27 @@ module.exports = { ).message ) } else { - // Broadcast location - io.to(loc.usr).emit('get', loc) - debug(`Broadcasting ${loc.lat}, ${loc.lon} to ${loc.usr}`) - // Save in db as last seen - user.last = { - lat: parseFloat(loc.lat), - lon: parseFloat(loc.lon), - dir: parseFloat(loc.dir || 0), - spd: parseFloat(loc.spd || 0), - time: loc.tim + // Check that loc is newer than lastLoc + debug(`Checking that loc of ${loc.tim} is newer than last of ${user.last.time.getTime()}...`) + if (!user.last.time || loc.tim > user.last.time.getTime()) { + + // Broadcast location + io.to(loc.usr).emit('get', loc) + debug(`Broadcasting ${loc.lat}, ${loc.lon} to ${loc.usr}`) + + // Save in db as last seen + user.last = { + lat: parseFloat(loc.lat), + lon: parseFloat(loc.lon), + dir: parseFloat(loc.dir || 0), + spd: parseFloat(loc.spd || 0), + time: loc.tim + } + user.save() + } - user.save() + } } catch (err) { console.error(err.stack) } }