-
Notifications
You must be signed in to change notification settings - Fork 0
/
bridge.js
60 lines (52 loc) · 1.49 KB
/
bridge.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
let osc = require('node-osc');
let io = require('socket.io')(8081);
//for OBS
let oscServer1, oscClient1;
let isConnected1 = false;
//for TouchDesigner
let oscServer2, oscClient2;
let isConnected2 = false;
io.sockets.on('connection', function (socket) {
console.log('connection');
//---OBS---
socket.on("config1", function (obj) {
isConnected1 = true;
oscServer1 = new osc.Server(obj.server.port, obj.server.host);
oscClient1 = new osc.Client(obj.client.host, obj.client.port);
oscClient1.send('/status', socket.sessionId + ' connected');
oscServer1.on('message', function (msg, rinfo) {
socket.emit("message1", msg);
});
socket.emit("connected", 1);
});
socket.on("message1", function (obj) {
oscClient1.send.apply(oscClient1, obj);
});
//---TouchDesigner---
socket.on("config2", function (obj) {
isConnected2 = true;
oscServer2 = new osc.Server(obj.server.port, obj.server.host);
oscClient2 = new osc.Client(obj.client.host, obj.client.port);
oscClient2.send('/status', socket.sessionId + ' connected');
oscServer2.on('message', function (msg, rinfo) {
socket.emit("message2", msg);
});
socket.emit("connected", 1);
});
socket.on("message2", function (obj) {
oscClient2.send.apply(oscClient2, obj);
});
socket.on('disconnect', function () {
if (isConnected1) {
oscServer1.kill();
oscClient1.kill();
isConnected1 = false;
}
if (isConnected2) {
oscServer2.kill();
oscClient2.kill();
isConnected2 = false;
}
console.log('disconnected');
});
});