diff --git a/apps/server/src/adapters/WebsocketAdapter.ts b/apps/server/src/adapters/WebsocketAdapter.ts index dfc337cf7..036e7cd44 100644 --- a/apps/server/src/adapters/WebsocketAdapter.ts +++ b/apps/server/src/adapters/WebsocketAdapter.ts @@ -102,7 +102,7 @@ class SocketServer implements IAdapter { this.sendClientList(); }); - ws.on('message', (data) => { + ws.on('message', async (data) => { try { const message = JSON.parse(data.toString()) as WsPacketToServer; const { tag, payload } = message; @@ -142,7 +142,7 @@ class SocketServer implements IAdapter { tag satisfies never; // Protocol specific stuff handled above try { - const reply = dispatchFromAdapter(tag, payload, 'ws'); + const reply = await dispatchFromAdapter(tag, payload, 'ws'); if (reply) { ws.send( JSON.stringify({ diff --git a/apps/server/src/api-integration/integration.controller.ts b/apps/server/src/api-integration/integration.controller.ts index 52290fade..08ca3a044 100644 --- a/apps/server/src/api-integration/integration.controller.ts +++ b/apps/server/src/api-integration/integration.controller.ts @@ -20,13 +20,11 @@ import { eventStore } from '../stores/EventStore.js'; import * as assert from '../utils/assert.js'; import { parseProperty, isValidChangeProperty } from './integration.utils.js'; import { socket } from '../adapters/WebsocketAdapter.js'; -import { throttle } from '../utils/throttle.js'; import { coerceEnum } from '../utils/coerceType.js'; import { editEntry } from '../api-data/rundown/rundown.service.js'; import { willCauseRegeneration } from '../api-data/rundown/rundown.utils.js'; import { getCurrentRundown } from '../api-data/rundown/rundown.dao.js'; -const throttledEditEvent = throttle(editEntry, 20); let lastRequest: Date | null = null; export function dispatchFromAdapter(tag: string, payload: unknown, _source?: 'osc' | 'ws' | 'http') { @@ -45,7 +43,9 @@ export function getLastRequest() { return lastRequest; } -type ActionHandler = (payload: unknown) => { payload: unknown }; +type ActionHandler = + | ((payload: unknown) => { payload: unknown }) + | ((payload: unknown) => Promise<{ payload: unknown }>); const actionHandlers: Record = { /* General */ @@ -53,7 +53,7 @@ const actionHandlers: Record = { poll: () => ({ payload: eventStore.poll(), }), - change: (payload) => { + change: async (payload) => { assert.isObject(payload); if (Object.keys(payload).length === 0) { throw new Error('Payload is empty'); @@ -89,16 +89,8 @@ const actionHandlers: Record = { Object.assign(patchEntry, newObjectProperty); } }); - - if (shouldThrottle) { - if (throttledEditEvent(patchEntry)) { - return { payload: 'throttled' }; - } - } else { - editEntry(patchEntry).catch((_error) => { - /** No error handling */ - }); - } + //TODO: windowed edit function + await editEntry(patchEntry); return { payload: 'success' }; }, /* Message Service */ diff --git a/apps/server/src/api-integration/integration.router.ts b/apps/server/src/api-integration/integration.router.ts index db491247a..49c51bf16 100644 --- a/apps/server/src/api-integration/integration.router.ts +++ b/apps/server/src/api-integration/integration.router.ts @@ -27,7 +27,7 @@ integrationRouter.get('/', (_req: Request, res: Response<{ message: string }>) = /** * All calls are sent to the dispatcher */ -integrationRouter.get('/*splat', (req: Request, res: Response) => { +integrationRouter.get('/*splat', async (req: Request, res: Response) => { let action = req.path.substring(1); if (!action) { res.status(400).json({ message: 'No action found' }); @@ -45,7 +45,7 @@ integrationRouter.get('/*splat', (req: Request, res: Response