This repository has been archived on 2024-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
tracman-server/config/demo.js
2017-06-27 13:45:50 -04:00

32 lines
650 B
JavaScript

'use strict';
// Imports
const fs = require('fs'),
debug = require('debug')('tracman-demo');
module.exports = (io)=>{
fs.readFile(__dirname+'/demo.txt', (err,data)=>{
if (err){ console.error(`${err.stack}`); }
const lines = data.toString().split('\n');
(function sendLoc(ln) {
if (ln>20754){ sendLoc(0) }
else {
let loc = lines[ln].split(' ');
debug(`Sending demo location: ${loc[1]}, ${loc[2]}`);
io.to('demo').emit('get', {
tim: new Date(),
lat: loc[1],
lon: loc[2],
dir: loc[3],
spd: loc[4]
});
setTimeout(()=>{
sendLoc(ln+1);
}, loc[0]);
}
})(5667);
});
};