-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
57 lines (47 loc) · 1.45 KB
/
server.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
const _ = require('lodash');
const express = require('express');
const http = require('http');
const app = express();
const server = http.createServer(app);
const io = require('socket.io').listen(server);
const now = require('performance-now');
const path = require('path');
const webpack = require('webpack');
const config = require('./webpack.config');
const compiler = webpack(config);
const Device = require('./device')
const Multiplexer = require('./multiplexer')
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: "/"
}));
app.use(require('webpack-hot-middleware')(compiler));
app.get('*', function (req, res, next) {
var filename = path.join(compiler.outputPath,'index.html');
compiler.outputFileSystem.readFile(filename, function(err, result){
if (err) {
return next(err);
}
res.set('content-type','text/html');
res.send(result);
res.end();
});
})
let djActionRunning = false;
io.on('connection', (socket) => {
socket.on('message', (data) => {
if (data.action === 'leds') {
if (multiplexer && !djActionRunning) {
multiplexer.setState(data.payload)
}
} else if (data.action === "dj-action"){
console.log(`DJ ACTION ${data.payload}`)
djActionRunning = true;
setTimeout(() => djActionRunning = false, 1000);
if (multiplexer) {
multiplexer.setState(_.range(0,600).map(i => '#990066'))
}
}
})
});
server.listen(3001, '0.0.0.0')