wavey-wind/server.js

55 lines
1.2 KiB
JavaScript
Raw Normal View History

const app = require('express')();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const port = 6676;
const include_files = [
'/three.min.js',
'/anim.js',
'/control.js',
'/nouislider.min.js',
'/nouislider.min.css',
'/lodash.min.js',
];
app.get('/', function(req, res) {
2017-10-06 23:20:52 +02:00
res.sendFile(__dirname + '/index.html');
});
app.get('/ctl', function(req, res) {
2017-10-06 23:20:52 +02:00
res.sendFile(__dirname + '/control.html');
});
let settings = {};
app.get('/settings', function(req, res) {
res.send(settings);
2017-10-06 23:20:52 +02:00
});
include_files.map(function(file) {
app.get(file, function(req, res){
res.sendFile(__dirname + file);
});
2017-10-06 23:20:52 +02:00
});
app.get('/socket.io.js', function(req, res){
res.sendFile(__dirname + '/node_modules/socket.io-client/dist/socket.io.js');
});
io.on('connection', function(socket){
console.log('konekt');
socket.on('disconnect', function(){
console.log('diskonekt');
});
socket.on('adjust', function(name, val) {
settings[name] = val;
io.emit('adjust', name, val, socket.id);
2017-10-06 23:20:52 +02:00
});
});
http.listen(port, function(){
console.log('listening on *:' + port);
2017-10-06 23:20:52 +02:00
});