-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (31 loc) · 1.49 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
var express = require('express');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server);
app.use(express.static('js'));
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});
// var data = [];
// function addData(new_data) {
// data.push(new_data);
// }
function pushUpdate(new_data) {
//console.log("sent" + JSON.stringify(new_data));
io.emit('dataUpdate', new_data);
}
// setTimeout(function() {addData({ "date":(new Date()).getTime()+1000, "data":(Math.floor(Math.random() * 6) + 1) });}, 1000);
// setTimeout(function() {addData({ "date":(new Date()).getTime()+2000, "data":(Math.floor(Math.random() * 6) + 1) });}, 1000);
// setTimeout(function() {addData({ "date":(new Date()).getTime()+3000, "data":(Math.floor(Math.random() * 6) + 1) });}, 1000);
// setTimeout(function() {addData({ "date":(new Date()).getTime()+4000, "data":(Math.floor(Math.random() * 6) + 1) });}, 1000);
// setInterval(function() {pushUpdate({ "date":(new Date()).getTime(), "data":(Math.floor(Math.random() * 6) + 1) });}, 1000);
setInterval(function() {pushUpdate({ "date":(new Date()).getTime(), "data":(Math.floor(Math.random() * 100) + 1) });}, 1000);
io.on('connection', function(socket){
console.log('a user connected');
// io.emit('completeData', data);
});
server.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Dashboard listening at http://%s:%s', host, port);
});