add necessary endpoint for http subscription

This commit is contained in:
arc-alex
2023-11-04 20:34:08 +01:00
parent 2b87f72acb
commit 4c38207a15
3 changed files with 49 additions and 2 deletions
@@ -54,6 +54,10 @@ export class DataProvider {
return data.osc;
}
static getHttp() {
return data.http;
}
static getAliases() {
return data.aliases;
}
@@ -86,6 +90,11 @@ export class DataProvider {
await this.persist();
}
static async setHttp(newData) {
data.http = { ...newData };
await this.persist();
}
static getRundown() {
return [...data.rundown];
}
@@ -12,6 +12,7 @@ import { PlaybackService } from '../services/PlaybackService.js';
import { eventStore } from '../stores/EventStore.js';
import { isDocker, resolveDbPath } from '../setup.js';
import { oscIntegration } from '../services/integration-service/OscIntegration.js';
import { httpIntegration } from '../services/integration-service/HttpIntegration.js';
import { logger } from '../classes/Logger.js';
import { deleteAllEvents, forceReset } from '../services/rundown-service/RundownService.js';
@@ -282,15 +283,23 @@ export const getOSC = async (req, res) => {
res.status(200).send(osc);
};
// Create controller for GET request to '/ontime/http'
// Returns -
export const getHTTP = async (req, res) => {
const http = DataProvider.getHttp();
console.log('get http', http)
res.status(200).send(http);
};
export const postOscSubscriptions = async (req, res) => {
if (failEmptyObjects(req.body, res)) {
return;
}
try {
const oscSubscriptions = req.body;
const subscriptions = req.body;
const oscSettings = DataProvider.getOsc();
oscSettings.subscriptions = oscSubscriptions;
oscSettings.subscriptions = subscriptions;
await DataProvider.setOsc(oscSettings);
// TODO: this update could be more granular, checking that relevant data was changed
@@ -303,6 +312,27 @@ export const postOscSubscriptions = async (req, res) => {
}
};
export const postHttpSubscriptions = async (req, res) => {
console.log('http post sub')
if (failEmptyObjects(req.body, res)) {
return;
}
try {
const subscriptions = req.body;
const httpSettings = DataProvider.getHttp();
httpSettings.subscriptions = subscriptions;
await DataProvider.setHttp(httpSettings);
const { message } = httpIntegration.init(httpSettings);
logger.info(LogOrigin.Tx, message);
res.send(httpSettings).status(200);
} catch (error) {
res.status(400).send(error);
}
};
// Create controller for POST request to '/ontime/osc'
// Returns ACK message
export const postOSC = async (req, res) => {
+8
View File
@@ -6,6 +6,7 @@ import {
getAliases,
getInfo,
getOSC,
getHTTP,
getSettings,
getUserFields,
getViewSettings,
@@ -14,6 +15,7 @@ import {
postNew,
postOSC,
postOscSubscriptions,
postHttpSubscriptions,
postSettings,
postUserFields,
postViewSettings,
@@ -76,5 +78,11 @@ router.post('/osc', validateOSC, postOSC);
// create route between controller and '/ontime/osc-subscriptions' endpoint
router.post('/osc-subscriptions', validateSubscription, postOscSubscriptions);
// create route between controller and '/ontime/http' endpoint
router.get('/http', getHTTP);
// create route between controller and '/ontime/osc-subscriptions' endpoint
router.post('/http-subscriptions', validateSubscription, postHttpSubscriptions);
// create route between controller and '/ontime/new' endpoint
router.post('/new', projectSanitiser, postNew);