mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-12 19:03:47 +00:00
Merge branch 'chore/cleanup' of https://github.com/cpvalente/ontime into chore/cleanup
This commit is contained in:
+53
-6
@@ -4,6 +4,7 @@ import { sessionId, user } from './utils/analytics.js';
|
||||
user.screenview('Node service', 'ontime').send();
|
||||
user.event('NODE', 'started', 'starting node service').send();
|
||||
|
||||
// import config
|
||||
import { config } from './config/config.js';
|
||||
|
||||
// init database
|
||||
@@ -95,20 +96,66 @@ app.use((err, req, res, next) => {
|
||||
res.status(500).send(err.stack);
|
||||
});
|
||||
|
||||
/*************** START SERVICES ***************/
|
||||
/* Override config
|
||||
* ----------------
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
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 serverPort = s.serverPort || config.server.port;
|
||||
|
||||
// Start OSC server
|
||||
import { initiateOSC, shutdownOSCServer } from './controllers/OscController.js';
|
||||
|
||||
export const startOSCServer = async (overrideConfig = null) => {
|
||||
// Setup default port
|
||||
const oscSettings = {
|
||||
port: overrideConfig?.port || oscInPort,
|
||||
ipOut: oscIP,
|
||||
portOut: oscOutPort,
|
||||
};
|
||||
|
||||
// Start OSC Server
|
||||
initiateOSC(oscSettings);
|
||||
};
|
||||
|
||||
// Start OSC Client
|
||||
// TODO: Move this to function
|
||||
const oscClient = new Client('127.0.0.1', 9999);
|
||||
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);
|
||||
|
||||
export const startServer = (overrideConfig = null) => {
|
||||
export const startServer = async (overrideConfig = null) => {
|
||||
// Setup default port
|
||||
const serverPort = overrideConfig?.port || config.server.port;
|
||||
// const port = overrideConfig?.port || serverPort;
|
||||
|
||||
/* Note: Port is hardcoded
|
||||
* need to find a good solution for sharing
|
||||
* the dynamic info with the frontend
|
||||
*/
|
||||
const port = 4001;
|
||||
|
||||
// Start server
|
||||
const returnMessage = `HTTP Server is listening on port ${serverPort}`;
|
||||
server.listen(serverPort, '0.0.0.0', () => console.log(returnMessage));
|
||||
const returnMessage = `HTTP Server is listening on port ${port}`;
|
||||
server.listen(port, '0.0.0.0', () => console.log(returnMessage));
|
||||
|
||||
// init timer
|
||||
global.timer = new EventTimer(server, oscClient, config);
|
||||
|
||||
@@ -158,19 +158,52 @@ const getNetworkInterfaces = () => {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
};
|
||||
|
||||
// Create controller for POST request to '/ontime/info'
|
||||
// Returns -
|
||||
// TODO: Add version
|
||||
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;
|
||||
|
||||
// get nif and inject localhost
|
||||
const ni = getNetworkInterfaces();
|
||||
ni.unshift({ name: 'localhost', address: '127.0.0.1' });
|
||||
|
||||
// send object with network information
|
||||
res.status(200).send({
|
||||
networkInterfaces: ni,
|
||||
version,
|
||||
serverPort,
|
||||
oscInPort,
|
||||
oscOutPort,
|
||||
oscOutIP,
|
||||
});
|
||||
};
|
||||
|
||||
// Create controller for POST request to '/ontime/info'
|
||||
// Returns ACK message
|
||||
export const postInfo = async (req, res) => {
|
||||
if (!req.body) {
|
||||
res.status(400).send('No object found in request');
|
||||
return;
|
||||
}
|
||||
// TODO: validate data
|
||||
try {
|
||||
data.settings = { ...data.settings, ...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) => {
|
||||
|
||||
@@ -5,12 +5,16 @@ export const dbModel = {
|
||||
url: '',
|
||||
publicInfo: '',
|
||||
backstageInfo: '',
|
||||
endMessage: '',
|
||||
},
|
||||
settings: {
|
||||
app: 'ontime',
|
||||
version: 1,
|
||||
osc_enabled: false,
|
||||
osc_port: 8888,
|
||||
serverPort: 4001,
|
||||
oscInPort: 8888,
|
||||
oscOutPort: 9999,
|
||||
oscOutIP: '127.0.0.1',
|
||||
oscEnabled: false,
|
||||
lock: false,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
dbDownload,
|
||||
dbUpload,
|
||||
getInfo,
|
||||
postInfo,
|
||||
dbPathToUpload,
|
||||
} from '../controllers/ontimeController.js';
|
||||
|
||||
@@ -18,5 +19,8 @@ router.post('/db', uploadJson, dbUpload);
|
||||
// create route between controller and '/ontime/info' endpoint
|
||||
router.get('/info', uploadJson, getInfo);
|
||||
|
||||
// create route between controller and '/ontime/info' endpoint
|
||||
router.post('/info', postInfo);
|
||||
|
||||
// create route between controller and '/ontime/dbpath' endpoint
|
||||
router.post('/dbpath', dbPathToUpload);
|
||||
|
||||
Reference in New Issue
Block a user