mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-08 08:53:51 +00:00
feat: OSC
This commit is contained in:
+5
-1
@@ -72,4 +72,8 @@ global.timer = new EventTimer(server, config);
|
||||
timer.setupWithEventList(eventlist);
|
||||
|
||||
// Start server
|
||||
server.listen(port, () => console.log(`Listening on port ${port}`));
|
||||
server.listen(port, () => console.log(`HTTP Server is listening on port ${port}`));
|
||||
|
||||
// Start OSC server
|
||||
const initiateOSC = require('./controllers/OscController.js').initiateOSC;
|
||||
initiateOSC(config.osc);
|
||||
|
||||
@@ -437,6 +437,7 @@ class EventTimer extends Timer {
|
||||
if (end < start) end += this.DAYMS;
|
||||
|
||||
// time stuff changes on wheter we keep the running clock
|
||||
|
||||
if (type === 'load') {
|
||||
this._resetTimers();
|
||||
|
||||
@@ -586,14 +587,14 @@ class EventTimer extends Timer {
|
||||
current = ${this.current}
|
||||
duration = ${this.duration}
|
||||
|
||||
Options
|
||||
------------------------------
|
||||
showNegative = ${this.showNegative}
|
||||
|
||||
Events
|
||||
------------------------------
|
||||
numEvents = ${this.numEvents}
|
||||
selectedEvent = ${this.selectedEvent}
|
||||
numEvents = ${this.numEvents}
|
||||
selectedEvent = ${this.selectedEvent}
|
||||
selectedEventId = ${this.selectedEventId}
|
||||
nextEventId = ${this.nextEventId}
|
||||
selectedPublicEventId = ${this.selectedPublicEventId}
|
||||
nextPublicEventId = ${this.nextPublicEventId}
|
||||
|
||||
Private Titles
|
||||
------------------------------
|
||||
@@ -617,7 +618,6 @@ class EventTimer extends Timer {
|
||||
Subtitle Next = ${this.titlesPublic.subtitleNext}
|
||||
Presenter Next = ${this.titlesPublic.presenterNext}
|
||||
|
||||
|
||||
Messages
|
||||
------------------------------
|
||||
presenter text = ${this.presenter.text}
|
||||
@@ -630,10 +630,15 @@ class EventTimer extends Timer {
|
||||
Private
|
||||
------------------------------
|
||||
finishAt = ${this._finishAt}
|
||||
finished = ${this._finishedAt}
|
||||
startedAt = ${this._startedAt}
|
||||
pausedAt = ${this._pausedAt}
|
||||
pausedInterval = ${this._pausedInterval}
|
||||
pausedTotal = ${this._pausedTotal}
|
||||
|
||||
Socket
|
||||
------------------------------
|
||||
numClients = ${this._numClients}
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
+14
-3
@@ -54,12 +54,20 @@ class Timer {
|
||||
this.current =
|
||||
this._startedAt + this.duration + this._pausedTotal - now;
|
||||
|
||||
if (this.current <= 0 && this._finishedAt == null)
|
||||
this._finishedAt = now;
|
||||
break;
|
||||
case 'pause':
|
||||
// update paused time
|
||||
this._pausedInterval = now - this._pausedAt;
|
||||
|
||||
if (this._startedAt != null) {
|
||||
// update current timer
|
||||
this.current =
|
||||
this._startedAt +
|
||||
this.duration +
|
||||
this._pausedTotal +
|
||||
this._pausedInterval -
|
||||
now;
|
||||
}
|
||||
break;
|
||||
case 'stop':
|
||||
// nothing here yet
|
||||
@@ -68,6 +76,9 @@ class Timer {
|
||||
console.error('Timer: no playstate on update call', this.state);
|
||||
break;
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
if (this.current <= 0 && this._finishedAt == null) this._finishedAt = now;
|
||||
}
|
||||
|
||||
// helpers
|
||||
@@ -193,7 +204,7 @@ class Timer {
|
||||
|
||||
if (amount < 0 && Math.abs(amount) > this.current) {
|
||||
// if we will make the clock negative
|
||||
this._finishedAt = this._getCurrentTime();
|
||||
if (this._finishedAt == null) this._finishedAt = this._getCurrentTime();
|
||||
} else if (this.current < 0 && this.current + amount > 0) {
|
||||
// clock will go from negative to positive
|
||||
this._finishedAt = null;
|
||||
|
||||
@@ -8,5 +8,8 @@
|
||||
"database": {
|
||||
"filename": "db.json",
|
||||
"tablename": "events"
|
||||
},
|
||||
"osc": {
|
||||
"port": 8888
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
const osc = require('node-osc');
|
||||
|
||||
const initiateOSC = (config) => {
|
||||
const oscServer = new osc.Server(config.port, '0.0.0.0', () => {
|
||||
console.log(`OSC Server is listening on port ${config.port}`);
|
||||
});
|
||||
|
||||
oscServer.on('message', function (msg) {
|
||||
// message should look like /ontime/{path}/{args} where
|
||||
// ontime: fixed message for app
|
||||
// path: command to be called
|
||||
// args: extra data, only used on some of the API entries (delay, goto)
|
||||
console.log('OSC received', msg);
|
||||
|
||||
// split message
|
||||
const [, address, path] = msg[0].split('/');
|
||||
const args = msg[1];
|
||||
|
||||
// get first part before (ontime)
|
||||
if (address !== 'ontime') return;
|
||||
|
||||
// get second part (command)
|
||||
switch (path) {
|
||||
case 'start':
|
||||
case 'play':
|
||||
console.log('calling play');
|
||||
global.timer.start();
|
||||
break;
|
||||
case 'pause':
|
||||
console.log('calling pause');
|
||||
global.timer.pause();
|
||||
break;
|
||||
case 'prev':
|
||||
console.log('calling prev');
|
||||
global.timer.previous();
|
||||
break;
|
||||
case 'next':
|
||||
console.log('calling next');
|
||||
global.timer.next();
|
||||
break;
|
||||
case 'unload':
|
||||
console.log('calling unload');
|
||||
global.timer.unload();
|
||||
break;
|
||||
case 'reload':
|
||||
console.log('calling reload');
|
||||
global.timer.reload();
|
||||
break;
|
||||
case 'roll':
|
||||
console.log('calling roll');
|
||||
break;
|
||||
case 'delay':
|
||||
console.log('calling delay with', args);
|
||||
let t = parseInt(args);
|
||||
if (!isNaN(t)) global.timer.increment(t * 1000 * 60);
|
||||
break;
|
||||
case 'goto':
|
||||
console.log('calling goto with', args);
|
||||
break;
|
||||
|
||||
default:
|
||||
console.log('Error: not recognised');
|
||||
break;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = { initiateOSC };
|
||||
@@ -8,6 +8,7 @@
|
||||
"express-session": "~1.17.1",
|
||||
"lowdb": "^1.0.0",
|
||||
"nanoid": "^3.1.22",
|
||||
"node-osc": "^6.0.1",
|
||||
"passport": "~0.4.1",
|
||||
"passport-local": "~1.0.0",
|
||||
"socket.io": "^4.0.0"
|
||||
|
||||
@@ -45,6 +45,11 @@ base64id@2.0.0, base64id@~2.0.0:
|
||||
resolved "https://registry.yarnpkg.com/base64id/-/base64id-2.0.0.tgz#2770ac6bc47d312af97a8bf9a634342e0cd25cb6"
|
||||
integrity sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==
|
||||
|
||||
binpack@~0:
|
||||
version "0.1.0"
|
||||
resolved "https://registry.yarnpkg.com/binpack/-/binpack-0.1.0.tgz#bd3d0974c3f2a0446e17df4f60b55a72a205a97e"
|
||||
integrity sha1-vT0JdMPyoERuF99PYLVacqIFqX4=
|
||||
|
||||
body-parser@1.19.0, body-parser@~1.19.0:
|
||||
version "1.19.0"
|
||||
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.19.0.tgz#96b2709e57c9c4e09a6fd66a8fd979844f69f08a"
|
||||
@@ -375,6 +380,13 @@ negotiator@0.6.2:
|
||||
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.2.tgz#feacf7ccf525a77ae9634436a64883ffeca346fb"
|
||||
integrity sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==
|
||||
|
||||
node-osc@^6.0.1:
|
||||
version "6.0.1"
|
||||
resolved "https://registry.yarnpkg.com/node-osc/-/node-osc-6.0.1.tgz#6f2c39996c64460435b678dc91c128d3a9711031"
|
||||
integrity sha512-UZBQGH4vVTw3Ub5/xcnhlrhL6bpaYz3hhNjO4eup4tknyP5qOi2GVVnEmEn/qaTgTvs7SVyytj3OHg9JWRD4Aw==
|
||||
dependencies:
|
||||
osc-min "^1.1.1"
|
||||
|
||||
object-assign@^4:
|
||||
version "4.1.1"
|
||||
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
|
||||
@@ -392,6 +404,13 @@ on-headers@~1.0.2:
|
||||
resolved "https://registry.yarnpkg.com/on-headers/-/on-headers-1.0.2.tgz#772b0ae6aaa525c399e489adfad90c403eb3c28f"
|
||||
integrity sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==
|
||||
|
||||
osc-min@^1.1.1:
|
||||
version "1.1.2"
|
||||
resolved "https://registry.yarnpkg.com/osc-min/-/osc-min-1.1.2.tgz#3dcaff10f804c39b7080cf4c10fd7a4103cd9037"
|
||||
integrity sha512-8DbiO8ME85R75stgNVCZtHxB9MNBBNcyy+isNBXrsFeinXGjwNAauvKVmGlfRas5VJWC/mhzIx7spR2gFvWxvg==
|
||||
dependencies:
|
||||
binpack "~0"
|
||||
|
||||
parseurl@~1.3.3:
|
||||
version "1.3.3"
|
||||
resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.3.tgz#9da19e7bee8d12dff0513ed5b76957793bc2e8d4"
|
||||
|
||||
Reference in New Issue
Block a user