-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (49 loc) · 1.62 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
52
53
54
55
56
57
58
var osc = require("osc"),
express = require("express"),
WebSocket = require("ws");
var getIPAddresses = function () {
var os = require("os"),
interfaces = os.networkInterfaces(),
ipAddresses = [];
for (var deviceName in interfaces) {
var addresses = interfaces[deviceName];
for (var i = 0; i < addresses.length; i++) {
var addressInfo = addresses[i];
if (addressInfo.family === "IPv4" && !addressInfo.internal) {
ipAddresses.push(addressInfo.address);
}
}
}
return ipAddresses;
};
// Bind to a UDP socket to listen for incoming OSC events.
var udpPort = new osc.UDPPort({
localAddress: "0.0.0.0",
localPort: 57121
});
udpPort.on("ready", function () {
var ipAddresses = getIPAddresses();
console.log("Listening for OSC over UDP.");
ipAddresses.forEach(function (address) {
console.log(" Host:", address + ", Port:", udpPort.options.localPort);
});
console.log("To start the demo, go to http://localhost:8081 in your web browser.");
});
udpPort.open();
// Create an Express-based Web Socket server to which messages will be relayed.
var appResources = __dirname + "/web",
app = express(),
server = app.listen(8081),
wss = new WebSocket.Server({
server: server
});
app.use("/", express.static(appResources));
wss.on("connection", function (socket) {
console.log("A Web Socket connection has been established!");
var socketPort = new osc.WebSocketPort({
socket: socket
});
var relay = new osc.Relay(udpPort, socketPort, {
raw: true
});
});