* feat/173: update dependencies
* feat/173: migrate to playback requests to POST
* feat/173: HTTP startById and startByIndex
* feat/173: HTTP loadById and loadByIndex
* feat/173: add tests
* feat/173: OSC API
* feat/173: Websocket API
This commit is contained in:
Carlos Valente
2022-07-13 15:49:59 +02:00
committed by GitHub
parent 91a0d975b3
commit a20909b882
11 changed files with 415 additions and 122 deletions
+49 -13
View File
@@ -42,36 +42,67 @@ export const initiateOSC = (config) => {
// get second part (command)
switch (path.toLowerCase()) {
case 'onair':
case 'onair': {
global.timer.setonAir(true);
break;
case 'offair':
}
case 'offair': {
global.timer.setonAir(false);
break;
case 'start':
case 'play':
}
case 'play': {
global.timer.trigger('start');
break;
case 'pause':
}
case 'start': {
try {
const eventIndex = Number(args);
if (isNaN(eventIndex)) {
global.timer.error('RX', `OSC IN: event index not recognised ${args}`);
return;
}
const success = global.timer.trigger('startByIndex', eventIndex);
if (!success) {
global.timer.error('RX', `OSC IN: event index not recognised ${args}`);
}
} catch (error) {
console.log('error parsing: ', error);
}
break;
}
case 'startid': {
const success = global.timer.trigger('startById', args);
if (!success) {
global.timer.error('RX', `OSC IN: event ID not recognised ${args}`);
}
break;
}
case 'pause': {
global.timer.trigger('pause');
break;
case 'prev':
}
case 'prev': {
global.timer.trigger('previous');
break;
case 'next':
}
case 'next': {
global.timer.trigger('next');
break;
}
case 'unload':
case 'stop':
case 'stop': {
global.timer.trigger('unload');
break;
case 'reload':
}
case 'reload': {
global.timer.trigger('reload');
break;
case 'roll':
}
case 'roll': {
global.timer.trigger('roll');
break;
case 'delay':
}
case 'delay': {
try {
const t = parseInt(args, 10);
if (isNaN(t)) {
@@ -83,7 +114,9 @@ export const initiateOSC = (config) => {
console.log('error parsing: ', error);
}
break;
}
case 'goto':
case 'load': {
try {
const eventIndex = parseInt(args, 10);
if (isNaN(eventIndex) || eventIndex <= 0) {
@@ -97,8 +130,9 @@ export const initiateOSC = (config) => {
global.timer.error('RX', `OSC IN: error calling goto ${error}`);
}
break;
}
case 'gotoid':
console.log('calling gotoid with', args);
case 'loadid': {
if (args == null) {
global.timer.error('RX', `OSC IN: event id not recognised or out of range ${args}}`);
return;
@@ -109,10 +143,12 @@ export const initiateOSC = (config) => {
global.timer.error('RX', `OSC IN: error calling goto ${error}`);
}
break;
}
default:
default: {
global.timer.warning('RX', `OSC IN: unhandled message ${path}`);
break;
}
}
});
};
@@ -46,6 +46,13 @@ async function _insertAt(entry, index) {
await db.write();
}
/**
* @description Inserts an entry after an element with given Id
* @param entry
* @param id
* @return {Promise<void>}
* @private
*/
async function _insertAfterId(entry, id) {
const index = [...data.events].findIndex((event) => event.id === id);
await _insertAt(entry, index + 1);
+39 -1
View File
@@ -19,7 +19,23 @@ export const offAir = async (req, res) => {
// Create controller for GET request to '/playback/start'
// Starts timer object
export const pbStart = async (req, res) => {
global.timer.trigger('start') ? res.sendStatus(200) : res.sendStatus(400);
const { eventId, eventIndex } = req.query;
if (eventId) {
global.timer.trigger('startById', eventId)
? res.sendStatus(200)
: res.status(400).send('Invalid event ID');
} else if (eventIndex) {
const index = Number(eventIndex);
if (!isNaN(index)) {
global.timer.trigger('startByIndex', index - 1)
? res.sendStatus(200)
: res.status(400).send('Invalid event index');
} else {
res.status(400).send('Invalid event index');
}
} else {
global.timer.trigger('start') ? res.sendStatus(200) : res.sendStatus(400);
}
};
// Create controller for GET request to '/playback/pause'
@@ -52,6 +68,28 @@ export const pbNext = async (req, res) => {
global.timer.trigger('next') ? res.sendStatus(200) : res.sendStatus(400);
};
// Create controller for GET request to '/playback/load'
// Load requested event
export const pbLoad = async (req, res) => {
const { eventId, eventIndex } = req.query;
if (eventId) {
global.timer.trigger('loadById', eventId)
? res.sendStatus(200)
: res.status(400).send('Invalid event ID');
} else if (eventIndex) {
const index = Number(eventIndex);
if (!isNaN(index)) {
global.timer.trigger('loadByIndex', index - 1)
? res.sendStatus(200)
: res.status(400).send('Invalid event index');
} else {
res.status(400).send('Invalid event index');
}
} else {
res.status(400).send('No event given');
}
};
// Create controller for GET request to '/playback/unload'
// Unloads any events
export const pbUnload = async (req, res) => {