mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-16 12:53:32 +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:
+17
-26
@@ -22,7 +22,6 @@ const adapter = new JSONFile(file);
|
||||
export const db = new Low(adapter);
|
||||
|
||||
// dependencies
|
||||
import { Client } from 'node-osc';
|
||||
import express from 'express';
|
||||
import http from 'http';
|
||||
import cors from 'cors';
|
||||
@@ -48,8 +47,8 @@ if (db.data == null || !isValid) {
|
||||
|
||||
// get data
|
||||
// there is also the case of the db being corrupt
|
||||
// try to parse the data
|
||||
export const data = await parseJson(db.data);
|
||||
// try to parse the data, make sure that all fields exist (enforce)
|
||||
export const data = await parseJson(db.data, true);
|
||||
db.data = data;
|
||||
await db.write();
|
||||
|
||||
@@ -113,17 +112,17 @@ app.use((err, req, res, next) => {
|
||||
* ----------------
|
||||
*
|
||||
* Configuration of services comes from app general config
|
||||
* It can be overriden here by the settings in the db
|
||||
* It can also be overriden on call
|
||||
* It can be overridden here by the settings in the db
|
||||
* It can also be overridden on call
|
||||
*
|
||||
*/
|
||||
|
||||
const s = data.settings;
|
||||
const oscIP = s.oscOutIP || config.osc.ipOut;
|
||||
const oscOutPort = s.oscOutPort || config.osc.portOut;
|
||||
const oscInPort = s.oscInPort || config.osc.port;
|
||||
const osc = data.osc;
|
||||
const oscIP = osc?.targetIP || config.osc.targetIP;
|
||||
const oscOutPort = osc?.portOut || config.osc.portOut;
|
||||
const oscInPort = osc?.port || config.osc.port;
|
||||
|
||||
const serverPort = s.serverPort || config.server.port;
|
||||
const serverPort = data.settings.serverPort || config.server.port;
|
||||
|
||||
// Start OSC server
|
||||
import { initiateOSC, shutdownOSCServer } from './controllers/OscController.js';
|
||||
@@ -140,17 +139,6 @@ export const startOSCServer = async (overrideConfig = null) => {
|
||||
initiateOSC(oscSettings);
|
||||
};
|
||||
|
||||
// Start OSC Client
|
||||
let oscClient = null;
|
||||
|
||||
export const startOSCClient = async (overrideConfig = null) => {
|
||||
// Setup default port
|
||||
const port = overrideConfig?.port || oscOutPort;
|
||||
console.log('initialise OSC Client on port: ', port);
|
||||
|
||||
oscClient = new Client(oscIP, oscOutPort);
|
||||
};
|
||||
|
||||
// create HTTP server
|
||||
const server = http.createServer(app);
|
||||
|
||||
@@ -168,8 +156,14 @@ export const startServer = async (overrideConfig = null) => {
|
||||
const returnMessage = `HTTP Server is listening on port ${port}`;
|
||||
server.listen(port, '0.0.0.0', () => console.log(returnMessage));
|
||||
|
||||
// OSC Config
|
||||
const oscConfig = {
|
||||
ip: oscIP,
|
||||
port: overrideConfig?.port || oscOutPort
|
||||
}
|
||||
|
||||
// init timer
|
||||
global.timer = new EventTimer(server, oscClient, config);
|
||||
global.timer = new EventTimer(server, config.timer, oscConfig, data.http);
|
||||
global.timer.setupWithEventList(data.events);
|
||||
|
||||
return returnMessage;
|
||||
@@ -178,7 +172,7 @@ export const startServer = async (overrideConfig = null) => {
|
||||
export const shutdown = async () => {
|
||||
console.log('Node service shutdown');
|
||||
|
||||
user.event('NODE', 'shutdown', 'requesting node shutfown').send();
|
||||
user.event('NODE', 'shutdown', 'requesting node shutdown').send();
|
||||
|
||||
// shutdown express server
|
||||
server.close();
|
||||
@@ -186,9 +180,6 @@ export const shutdown = async () => {
|
||||
// shutdown OSC Server
|
||||
shutdownOSCServer();
|
||||
|
||||
// shutdown OSC Client
|
||||
oscClient.close();
|
||||
|
||||
// shutdown timer
|
||||
global.timer.shutdown();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user