forked from marsvaardig/osc-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
76 lines (61 loc) · 1.79 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
70
71
72
73
74
75
76
var osc = require("osc"),
cmd = require("node-cmd"),
Omx = require("node-omxplayer"),
omxplayer = Omx();
/****************
* OSC Over UDP *
****************/
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;
};
var udpPort = new osc.UDPPort({
localAddress: "0.0.0.0",
localPort: 57121, // sets the port number used for osc/qlab.
});
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);
});
// Make the screen blank
cmd.run("/opt/vc/bin/tvservice -p");
});
udpPort.on("message", function (oscMessage) {
if (oscMessage.address == "/play") {
if (oscMessage.args[1].length >= 1) {
omxplayer.newSource(oscMessage.args[1], oscMessage.args[0], false, 100);
}
else {
omxplayer.newSource(oscMessage.args[0], 'hdmi', false, 100);
}
}
if (oscMessage.address == "/loop") {
omxplayer.newSource(oscMessage.args[1], oscMessage.args[0], true, 100);
}
if (oscMessage.address == "/pause" && omxplayer.running) {
omxplayer.pause();
}
if (oscMessage.address == "/stop" && omxplayer.running) {
omxplayer.quit();
}
if (oscMessage.address == "/cmd") {
cmd.run(oscMessage.args[0]);
}
});
udpPort.on("error", function (err) {
console.log(err);
});
udpPort.open();