mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-14 11:53:49 +00:00
V2 ws store (#310)
* Update TimerService.ts * refactor: message service publishes to store * refactor: several type improvements * V2 ws store wss (#309) * refactor: shared logging types * refactor: simplify message service consumption * refactor: create discrete logging system * refactor: move socket.io > websocket
This commit is contained in:
+33
-29
@@ -6,8 +6,7 @@ import cors from 'cors';
|
||||
// import utils
|
||||
import { join, resolve } from 'path';
|
||||
|
||||
import { initiateOSC, shutdownOSCServer } from './controllers/OscController.js';
|
||||
import { initSentry } from './modules/sentry.js';
|
||||
import { initSentry, reportSentryException } from './modules/sentry.js';
|
||||
import { currentDirectory, environment, isProduction, resolvedPath } from './setup.js';
|
||||
import { ONTIME_VERSION } from './ONTIME_VERSION.js';
|
||||
import { OSCSettings } from 'ontime-types';
|
||||
@@ -18,13 +17,18 @@ import { router as eventDataRouter } from './routes/eventDataRouter.js';
|
||||
import { router as ontimeRouter } from './routes/ontimeRouter.js';
|
||||
import { router as playbackRouter } from './routes/playbackRouter.js';
|
||||
|
||||
// Services
|
||||
// Import adapters
|
||||
import { OscServer } from './adapters/OscAdapter.js';
|
||||
import { socket } from './adapters/WebsocketAdapter.js';
|
||||
import { DataProvider } from './classes/data-provider/DataProvider.js';
|
||||
import { socketProvider } from './classes/socket/SocketController.js';
|
||||
import { eventTimer } from './services/TimerService.js';
|
||||
import { dbLoadingProcess } from './modules/loadDb.js';
|
||||
|
||||
// Services
|
||||
import { eventTimer } from './services/TimerService.js';
|
||||
import { integrationService } from './services/integration-service/IntegrationService.js';
|
||||
import { OscIntegration } from './services/integration-service/OscIntegration.js';
|
||||
import { logger } from './classes/Logger.js';
|
||||
import { eventLoader } from './classes/event-loader/EventLoader.js';
|
||||
|
||||
console.log(`Starting Ontime version ${ONTIME_VERSION}`);
|
||||
|
||||
@@ -33,10 +37,7 @@ if (!isProduction) {
|
||||
console.log(`Ontime directory at ${currentDirectory} `);
|
||||
}
|
||||
|
||||
initSentry(environment);
|
||||
|
||||
// import socket provider
|
||||
const socketServer = socketProvider;
|
||||
initSentry(isProduction);
|
||||
|
||||
// Create express APP
|
||||
const app = express();
|
||||
@@ -100,6 +101,9 @@ enum OntimeStartOrder {
|
||||
}
|
||||
|
||||
let step = OntimeStartOrder.InitDB;
|
||||
let expressServer = null;
|
||||
let oscServer = null;
|
||||
|
||||
const checkStart = (currentState: OntimeStartOrder) => {
|
||||
if (step !== currentState) {
|
||||
step = OntimeStartOrder.Error;
|
||||
@@ -116,9 +120,6 @@ export const startDb = async () => {
|
||||
await dbLoadingProcess;
|
||||
};
|
||||
|
||||
// create HTTP server
|
||||
const expressServer = http.createServer(app);
|
||||
|
||||
/**
|
||||
* Starts servers
|
||||
* @return {Promise<string>}
|
||||
@@ -128,11 +129,13 @@ export const startServer = async () => {
|
||||
|
||||
const serverPort = 4001; // hardcoded for now
|
||||
const returnMessage = `Ontime is listening on port ${serverPort}`;
|
||||
expressServer.listen(serverPort, '0.0.0.0');
|
||||
|
||||
socketServer.initServer(expressServer);
|
||||
socketServer.info('SERVER', returnMessage);
|
||||
socketServer.startListener();
|
||||
expressServer = http.createServer(app);
|
||||
|
||||
socket.init(expressServer);
|
||||
eventLoader.init();
|
||||
|
||||
expressServer.listen(serverPort, '0.0.0.0');
|
||||
|
||||
return returnMessage;
|
||||
};
|
||||
@@ -149,7 +152,7 @@ export const startOSCServer = async (overrideConfig = null) => {
|
||||
const { osc } = DataProvider.getData();
|
||||
|
||||
if (!osc.enabledIn) {
|
||||
socketServer.info('RX', 'OSC Input Disabled');
|
||||
logger.info('RX', 'OSC Input Disabled');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -160,8 +163,8 @@ export const startOSCServer = async (overrideConfig = null) => {
|
||||
};
|
||||
|
||||
// Start OSC Server
|
||||
socketServer.info('RX', `Starting OSC Server on port: ${oscSettings.portIn}`);
|
||||
initiateOSC(oscSettings);
|
||||
logger.info('RX', `Starting OSC Server on port: ${oscSettings.portIn}`);
|
||||
oscServer = new OscServer(oscSettings);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -178,7 +181,7 @@ export const startIntegrations = async (config?: { osc: OSCSettings }) => {
|
||||
|
||||
const oscIntegration = new OscIntegration();
|
||||
const { success, message } = oscIntegration.init(osc);
|
||||
socketServer.info('RX', message);
|
||||
logger.info('RX', message);
|
||||
|
||||
if (success) {
|
||||
integrationService.register(oscIntegration);
|
||||
@@ -193,25 +196,26 @@ export const startIntegrations = async (config?: { osc: OSCSettings }) => {
|
||||
export const shutdown = async (exitCode = 0) => {
|
||||
console.log(`Ontime shutting down with code ${exitCode}`);
|
||||
|
||||
expressServer.close();
|
||||
shutdownOSCServer();
|
||||
expressServer?.close();
|
||||
oscServer?.shutdown();
|
||||
eventTimer.shutdown();
|
||||
socketServer.shutdown();
|
||||
integrationService.shutdown();
|
||||
logger.shutdown();
|
||||
socket.shutdown();
|
||||
process.exit(exitCode);
|
||||
};
|
||||
|
||||
process.on('exit', (code) => console.log(`Ontime exited with code: ${code}`));
|
||||
|
||||
process.on('unhandledRejection', async (error, promise) => {
|
||||
console.error(error, 'Error: unhandled rejection', promise);
|
||||
socketServer.error('SERVER', 'Error: unhandled rejection');
|
||||
process.on('unhandledRejection', async (error) => {
|
||||
reportSentryException(error);
|
||||
logger.error('SERVER', 'Error: unhandled rejection');
|
||||
await shutdown(1);
|
||||
});
|
||||
|
||||
process.on('uncaughtException', async (error, promise) => {
|
||||
console.error(error, 'Error: uncaught exception', promise);
|
||||
socketServer.error('SERVER', 'Error: uncaught exception');
|
||||
process.on('uncaughtException', async (error) => {
|
||||
reportSentryException(error);
|
||||
logger.error('SERVER', 'Error: uncaught exception');
|
||||
await shutdown(1);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user