-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
80 lines (71 loc) · 2.74 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/livelocation');
Routes = require('./models/routes');
var _globals = require('./_globals.js');
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.get('/', function (req, res) {
res.render('index.ejs');
});
app.get('/view', function (req, res) {
Route = Routes;
Route.getRouteDetails(111, function(done){
if(done.status)
{
if(done.begining!=null)
res.render('viewer', {gMapsKey : _globals.gMapsKey, destination:{lat : done.destination[0], long: done.destination[1]}, begining:{lat : done.begining[0], long: done.begining[1]}});
else
res.render('viewer', {gMapsKey : _globals.gMapsKey, destination:{lat : done.destination[0], long: done.destination[1]}, begining:{lat : null, long: null}});
}
else
res.render('viewer', {gMapsKey : _globals.gMapsKey, destination:{lat : done.destination[0], long: done.destination[1]}, begining:{lat : null, long: null}});
})
});
app.get('/path', function (req, res) {
Route = Routes;
Route.getRouteDetails(111, function(done){
if(done.status)
{
if(done.begining!=null)
res.render('viewer', {gMapsKey : _globals.gMapsKey, destination:{lat : done.destination[0], long: done.destination[1]}, begining:{lat : done.begining[0], long: done.begining[1]}});
else
res.render('viewer', {gMapsKey : _globals.gMapsKey, destination:{lat : null, long: null}, begining:{lat : null, long: null}});
}
else
res.render('viewer', {gMapsKey : _globals.gMapsKey, destination:{lat : null, long: null}, begining:{lat : null, long: null}});
})
});
app.get('/start', function (req, res) {
Route = Routes;
Route.newRoute(111, [26.84701, 80.94482], function(done){
if(done.status)
{
console.log(done);
res.render('router');
}
else
console.log(done.message);
})
});
io.on('connection', function (socket) {
console.log('a user connected');
socket.on('disconnect', function () {
console.log('user disconnected');
});
socket.on('latlong', function (msg) {
//console.log('latlong: ' + msg);
Route = Routes;
//console.log(msg);
//var msgarr = toString(msg).split(",")
Route.updateLatlong(111, msg , function(done){
console.log(done);
})
io.sockets.emit('latlong registered', { latlong: msg });
});
});
http.listen(3000, function () {
console.log('listening on *:3000');
});