-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverMap.js
62 lines (51 loc) · 1.72 KB
/
serverMap.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
/**
* Created by NachoGeotec on 02/10/2015.
*/
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var mongoose = require("mongoose");
var dbConfig = require("./controller/db.js");
var users = [];
app.use(express.static(__dirname + '/public'));
mongoose.connect(dbConfig.url, function(err, res){
if(err) console.log ('ERROR connecting to: ' + dbConfig.url + '. ' + err);
console.log('Connected to: ' + dbConfig.url);
});
app.get('/', function(req, res){
res.sendFile(__dirname + '/public/indexMap.html');
});
io.on('connection', function(socket){
var data = socket.handshake.query.data.split(";");
console.log("DATA: " + data);
var username = data[0];
var lat = data[1];
var lon = data[2];
users[username] = [lat, lon];
io.emit('user connected', username, lat, lon);
socket.on('disconnect', function(){
delete users[username];
io.emit('user disconnected', username);
});
socket.on('position changed', function(latitiude, longitude){
lat = latitiude;
lon = longitude;
users[username] = [lat, lon];
console.log("POS CHANGED: " + username + " LAT: " + lat + " LON: " + lon);
io.emit('update position', username, lat, lon);
});
});
var port = 8899;
http.listen(port, function(){
console.log('listening on port: ' + port);
});
function actualTime(){
var date = new Date();
var dia = date.toDateString();
if(date.getMinutes().toString().length<2) var minutes = "0" + date.getMinutes();
else var minutes = date.getMinutes();
var hour = date.getHours() + ':' + minutes;
var dateReturned = dia + " " + hour;
return dateReturned;
}