mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-14 20:03:52 +00:00
event cucle (#76)
* install sass * refact: integration settings - OSC in its own HTTP endpoint - OSC settings have own object in db * refact: simplify event cycle * refact: restructure external triggers http * refact: restructure external triggers osc+socket * refact: restructure data updates * feat: osc integration class * IO improvements - timer uses osc integration - create trigger handler to manage external triggers * refact: refract state machine update * Integration: simple HTTP Client * Integration: http options in datamodel * Integration: call http send on life cycle * feat/62-logging: fix issue #71
This commit is contained in:
@@ -47,32 +47,32 @@ export const initiateOSC = (config) => {
|
||||
case 'start':
|
||||
case 'play':
|
||||
console.log('calling play');
|
||||
global.timer.start();
|
||||
global.timer.trigger('start');
|
||||
break;
|
||||
case 'pause':
|
||||
console.log('calling pause');
|
||||
global.timer.pause();
|
||||
global.timer.trigger('pause');
|
||||
break;
|
||||
case 'prev':
|
||||
console.log('calling prev');
|
||||
global.timer.previous();
|
||||
global.timer.trigger('previous');
|
||||
break;
|
||||
case 'next':
|
||||
console.log('calling next');
|
||||
global.timer.next();
|
||||
global.timer.trigger('next');
|
||||
break;
|
||||
case 'unload':
|
||||
case 'stop':
|
||||
console.log('calling unload');
|
||||
global.timer.unload();
|
||||
global.timer.trigger('unload');
|
||||
break;
|
||||
case 'reload':
|
||||
console.log('calling reload');
|
||||
global.timer.reload();
|
||||
global.timer.trigger('reload');
|
||||
break;
|
||||
case 'roll':
|
||||
console.log('calling roll');
|
||||
global.timer.roll();
|
||||
global.timer.trigger('roll');
|
||||
break;
|
||||
case 'delay':
|
||||
console.log('calling delay with', args);
|
||||
|
||||
@@ -9,14 +9,6 @@ import {
|
||||
block as blockDef,
|
||||
} from '../models/eventsDefinition.js';
|
||||
|
||||
function _getEventsCount() {
|
||||
return Array.from(data.events).length;
|
||||
}
|
||||
|
||||
function _pushNew(entry) {
|
||||
return data.events.push(entry).write();
|
||||
}
|
||||
|
||||
async function _insertAt(entry, index) {
|
||||
// get events
|
||||
let events = data.events;
|
||||
@@ -26,7 +18,7 @@ async function _insertAt(entry, index) {
|
||||
// Remove order field from object
|
||||
delete entry.order;
|
||||
|
||||
// Insert at beggining
|
||||
// Insert at beginning
|
||||
if (order === 0) {
|
||||
events.unshift(entry);
|
||||
}
|
||||
@@ -47,7 +39,7 @@ async function _insertAt(entry, index) {
|
||||
}
|
||||
|
||||
async function _removeById(eventId) {
|
||||
data.events = Array.from(data.events).filter((e) => e.id != eventId);
|
||||
data.events = Array.from(data.events).filter((e) => e.id !== eventId);
|
||||
await db.write();
|
||||
}
|
||||
|
||||
@@ -122,7 +114,7 @@ export const eventsPost = async (req, res) => {
|
||||
const index = newEvent.order || 0;
|
||||
|
||||
// add new event in place
|
||||
_insertAt(newEvent, index);
|
||||
await _insertAt(newEvent, index);
|
||||
|
||||
// update timers
|
||||
_updateTimers();
|
||||
@@ -160,7 +152,7 @@ export const eventsPut = async (req, res) => {
|
||||
const e = data.events[eventIndex];
|
||||
data.events[eventIndex] = { ...e, ...req.body };
|
||||
data.events[eventIndex].revision++;
|
||||
db.write();
|
||||
await db.write();
|
||||
|
||||
// update timer
|
||||
_updateTimersSingle(eventId, req.body);
|
||||
@@ -176,7 +168,7 @@ export const eventsPut = async (req, res) => {
|
||||
// Returns -
|
||||
export const eventsPatch = async (req, res) => {
|
||||
// Code is the same as put, call that
|
||||
eventsPut(req, res);
|
||||
await eventsPut(req, res);
|
||||
};
|
||||
|
||||
export const eventsReorder = async (req, res) => {
|
||||
@@ -207,7 +199,7 @@ export const eventsReorder = async (req, res) => {
|
||||
|
||||
// save events
|
||||
data.events = events;
|
||||
db.write();
|
||||
await db.write();
|
||||
|
||||
// TODO: would it be more efficient to reorder at timer?
|
||||
// update timer
|
||||
@@ -273,7 +265,7 @@ export const eventsApplyDelay = async (req, res) => {
|
||||
|
||||
// update events
|
||||
data.events = events;
|
||||
db.write();
|
||||
await db.write();
|
||||
|
||||
// update timer
|
||||
_updateTimers();
|
||||
@@ -297,7 +289,7 @@ export const eventsDelete = async (req, res) => {
|
||||
|
||||
try {
|
||||
// remove new event
|
||||
_removeById(req.params.eventId);
|
||||
await _removeById(req.params.eventId);
|
||||
|
||||
// update timer
|
||||
_deleteTimerId(req.params.eventId);
|
||||
@@ -316,7 +308,7 @@ export const eventsDeleteAll = async (req, res) => {
|
||||
try {
|
||||
// set with nothing
|
||||
data.events = [];
|
||||
db.write();
|
||||
await db.write();
|
||||
|
||||
// update timer object
|
||||
global.timer.clearEventList();
|
||||
|
||||
@@ -95,9 +95,13 @@ const getNetworkInterfaces = () => {
|
||||
export const getInfo = async (req, res) => {
|
||||
const version = data.settings.version;
|
||||
const serverPort = data.settings.serverPort;
|
||||
const oscInPort = data.settings.oscInPort;
|
||||
const oscOutPort = data.settings.oscOutPort;
|
||||
const oscOutIP = data.settings.oscOutIP;
|
||||
|
||||
const osc = {
|
||||
port: data.osc.port,
|
||||
portOut: data.osc.portOut,
|
||||
targetIP: data.osc.targetIP,
|
||||
enabled: data.osc.enabled,
|
||||
};
|
||||
|
||||
// get nif and inject localhost
|
||||
const ni = getNetworkInterfaces();
|
||||
@@ -108,9 +112,7 @@ export const getInfo = async (req, res) => {
|
||||
networkInterfaces: ni,
|
||||
version,
|
||||
serverPort,
|
||||
oscInPort,
|
||||
oscOutPort,
|
||||
oscOutIP,
|
||||
osc,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -132,6 +134,31 @@ export const postInfo = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Create controller for POST request to '/ontime/osc'
|
||||
// Returns -
|
||||
export const getOSC = async (req, res) => {
|
||||
// send object with network information
|
||||
res.status(200).send(data.osc);
|
||||
};
|
||||
|
||||
// Create controller for POST request to '/ontime/osc'
|
||||
// Returns ACK message
|
||||
export const postOSC = async (req, res) => {
|
||||
if (!req.body) {
|
||||
res.status(400).send('No object found in request');
|
||||
return;
|
||||
}
|
||||
// TODO: validate data
|
||||
try {
|
||||
data.osc = { ...data.osc, ...req.body };
|
||||
await db.write();
|
||||
res.sendStatus(200);
|
||||
} catch (error) {
|
||||
res.status(400).send(error);
|
||||
console.log(error);
|
||||
}
|
||||
};
|
||||
|
||||
// Create controller for POST request to '/ontime/db'
|
||||
// Returns -
|
||||
export const dbUpload = async (req, res) => {
|
||||
|
||||
@@ -8,79 +8,68 @@ export const pbGet = async (req, res) => {
|
||||
// Turns onAir flag to true
|
||||
export const onAir = async (req, res) => {
|
||||
console.log('Setting onAir to true');
|
||||
global.timer.setonAir(true);
|
||||
res.sendStatus(200);
|
||||
global.timer.trigger('onAir') ? res.sendStatus(200) : res.sendStatus(400);
|
||||
};
|
||||
|
||||
// Create controller for GET request to '/playback/onAir'
|
||||
// Turns onAir flag to true
|
||||
export const offAir = async (req, res) => {
|
||||
console.log('Setting onAir to false');
|
||||
global.timer.setonAir(false);
|
||||
res.sendStatus(200);
|
||||
global.timer.trigger('offAir') ? res.sendStatus(200) : res.sendStatus(400);
|
||||
};
|
||||
|
||||
// Create controller for GET request to '/playback/start'
|
||||
// Starts timer object
|
||||
export const pbStart = async (req, res) => {
|
||||
console.log('Calling start');
|
||||
global.timer.start();
|
||||
res.sendStatus(200);
|
||||
global.timer.trigger('start') ? res.sendStatus(200) : res.sendStatus(400);
|
||||
};
|
||||
|
||||
// Create controller for GET request to '/playback/pause'
|
||||
// Pauses timer object
|
||||
export const pbPause = async (req, res) => {
|
||||
console.log('Calling pause');
|
||||
global.timer.pause();
|
||||
res.sendStatus(200);
|
||||
global.timer.trigger('pause') ? res.sendStatus(200) : res.sendStatus(400);
|
||||
};
|
||||
|
||||
// Create controller for GET request to '/playback/stop'
|
||||
// Stops timer object
|
||||
export const pbStop = async (req, res) => {
|
||||
console.log('Calling stop');
|
||||
global.timer.stop();
|
||||
res.sendStatus(200);
|
||||
global.timer.trigger('stop') ? res.sendStatus(200) : res.sendStatus(400);
|
||||
};
|
||||
|
||||
// Create controller for GET request to '/playback/roll'
|
||||
// Sets timer object to roll mode
|
||||
export const pbRoll = async (req, res) => {
|
||||
console.log('Calling roll');
|
||||
global.timer.roll();
|
||||
res.sendStatus(501);
|
||||
global.timer.trigger('roll') ? res.sendStatus(200) : res.sendStatus(400);
|
||||
};
|
||||
|
||||
// Create controller for GET request to '/playback/previous'
|
||||
// Sets timer object to roll mode
|
||||
export const pbPrevious = async (req, res) => {
|
||||
console.log('Calling previous');
|
||||
global.timer.previous();
|
||||
res.sendStatus(200);
|
||||
global.timer.trigger('previous') ? res.sendStatus(200) : res.sendStatus(400);
|
||||
};
|
||||
|
||||
// Create controller for GET request to '/playback/next'
|
||||
// Sets timer object to roll mode
|
||||
export const pbNext = async (req, res) => {
|
||||
console.log('Calling next');
|
||||
global.timer.next();
|
||||
res.sendStatus(200);
|
||||
global.timer.trigger('next') ? res.sendStatus(200) : res.sendStatus(400);
|
||||
};
|
||||
|
||||
// Create controller for GET request to '/playback/unload'
|
||||
// Unloads any events
|
||||
export const pbUnload = async (req, res) => {
|
||||
console.log('Calling unload');
|
||||
global.timer.unload();
|
||||
|
||||
res.sendStatus(200);
|
||||
global.timer.trigger('unload') ? res.sendStatus(200) : res.sendStatus(400);
|
||||
};
|
||||
|
||||
// Create controller for GET request to '/playback/reload'
|
||||
// Reloads current event
|
||||
export const pbReload = async (req, res) => {
|
||||
console.log('Calling reload');
|
||||
global.timer.reload();
|
||||
res.sendStatus(200);
|
||||
global.timer.trigger('reload') ? res.sendStatus(200) : res.sendStatus(400);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user