-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
62 lines (48 loc) · 1.27 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
58
59
60
61
62
const express = require('express')
const http = require('http')
const WebSocket = require('ws')
const port = 6676
const include_files = [
'/anim.js',
'/control.js',
'/node_modules/three/build/three.min.js',
'/node_modules/nouislider/distribute/nouislider.min.js',
'/node_modules/nouislider/distribute/nouislider.min.css',
];
const app = express();
const server = http.Server(app);
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html');
});
app.get('/ctl', function(req, res) {
res.sendFile(__dirname + '/control.html');
});
let settings = {};
app.get('/settings', function(req, res) {
res.send(settings);
});
include_files.map(function(file) {
app.get(file, function(req, res){
res.sendFile(__dirname + file);
});
});
server.listen(port, () => console.log('listening on *:' + port))
// Websocket init
const wss = new WebSocket.Server({ server })
wss.on('connection', function (ws) {
console.log('kontekt')
ws.on('message', (msg) => {
//console.log('got msg', msg)
const parts = msg.split(":")
const cmd = parts[0]
// Broadcast adjust msg
switch (cmd) {
case 'adjust':
wss.clients.forEach( client => {
if (client != ws) {
client.send(msg)
}
})
}
})
})