-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
69 lines (64 loc) · 1.72 KB
/
app.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
63
64
65
66
67
68
69
var osc = require('node-osc'),
express = require('express'),
app = express(),
server = require('http').Server(app),
io = require('socket.io')(server);
io.set('log level', 1);
//server
server.listen(3000);
app.use(express.static('public'));
//OSC
var oscAddr = '192.168.1.2';
//var oscAddr = '127.0.0.1';
var oscServer = new osc.Server(10001, oscAddr);
var oscClient = new osc.Client(oscAddr, 10000);
//socket
var mode = 'none';
io.sockets.on('connection', function(socket) {
//mode
socket.on('config', function(data) {
mode = data;
oscClient.send('/config', data);
console.log('[Received] config: ' + data);
});
//graph
socket.on('emit_graph', function(data) {
oscClient.send('/graph', data);
console.log("[Received] graph: " + data);
});
//calc
socket.on('emit_calc', function(data) {
oscClient.send('/calc', data);
console.log("[Received] calc: " + data);
});
//timer
socket.on('emit_timer', function(data) {
oscClient.send('/timer', data);
console.log("[Received] timer: " + data);
});
//visualizer
socket.on('emit_visualizer', function(data) {
oscClient.send('/visualizer', data);
console.log('[Received] visualizer: ' + data);
});
//oscServer
var msg, addr;
var prevMsg = null;
oscServer.on('message', function(obj, rinfo) {
msg = obj[2][1];
addr = obj[2][0];
console.log('[Incoming msg] ' + 'address:' + addr + ' msg:' + msg);
//console.log(rinfo);
if (msg !== prevMsg){
if (addr = '/timer') {
socket.emit('send_time', msg);
console.log('time: ' + msg);
}
if (addr = '/graph') {
socket.emit('send_graph', msg);
console.log('time: ' + msg);
}
}
prevMsg = msg;
});
});