-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·43 lines (33 loc) · 1.06 KB
/
index.js
File metadata and controls
executable file
·43 lines (33 loc) · 1.06 KB
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
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var dbManager = require('./database_manager.js');
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
// views is directory for all template files
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.get('/', function(request, response) {
response.render('pages/index');
});
io.on('connection', function(socket){
var callback = (params) => {
params.forEach(function(element) {
socket.emit('update', element);
}, this);
};
dbManager.getAll(callback);
socket.on('update', function (params) {
var data = JSON.stringify(params);
data = data.replace(">", ">");
params = JSON.parse(data);
console.log(params);
//db update
dbManager.update({key: params.uuid}, params);
socket.broadcast.emit('update', params);
});
});
http.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});