-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (42 loc) · 1.31 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
40
41
42
43
44
45
46
47
48
49
50
51
var path = require('path');
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var osc = require('node-osc');
var oscServer = new osc.Server(3333, '127.0.0.1');
app.use(express.static(__dirname + '/public'));
/*oscServer.on("message", function (msg, rinfo) {
console.log(msg);
});*/
io.on('connection', function(socket){
/*var x = 0;
setInterval (function () {
x += 0.01;
// console.log(Math.sin(x)+1);
//socket.emit('dial', { 'dial': Math.sin(x)+1 });
}, 1000);*/
console.log('a user connected');
socket.on('disconnect', function(){
console.log('user disconnected');
});
oscServer.on("message", function (msg, rinfo) {
console.log("TouchOSC message:");
console.log(msg);
if (msg[0].startsWith('/1/push')) {
var val = msg[0].substr(-1);
if (msg[1] == 1) {
socket.emit('push', { 'button': val });
} else if (msg[1] == 0 && val == 5) {
socket.emit('stop', { 'button': val });
}
} else if (msg[0].startsWith('/1/slider')) {
socket.emit('slider', { 'slider': msg[1] });
} else if (msg[0].startsWith('/1/dial')) {
socket.emit('dial', { 'dial': msg[1] });
}
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});