diff --git a/apps/client/src/common/utils/socket.ts b/apps/client/src/common/utils/socket.ts index cf23e9812..b4389d492 100644 --- a/apps/client/src/common/utils/socket.ts +++ b/apps/client/src/common/utils/socket.ts @@ -1,6 +1,7 @@ import { Log, RundownCached, RuntimeStore } from 'ontime-types'; import { CLIENT_LIST, CUSTOM_FIELDS, isProduction, RUNDOWN, RUNTIME, websocketUrl } from '../api/constants'; +import { invalidateAllCaches } from '../api/utils'; import { ontimeQueryClient } from '../queryClient'; import { getClientId, @@ -178,10 +179,12 @@ export const connectSocket = () => { } case 'ontime-refetch': { // the refetch message signals that the rundown has changed in the server side - const { revision } = payload; + const { revision, reload } = payload; const currentRevision = ontimeQueryClient.getQueryData(RUNDOWN)?.revision ?? -1; - if (revision > currentRevision) { + if (reload) { + invalidateAllCaches(); + } else if (revision > currentRevision) { ontimeQueryClient.invalidateQueries({ queryKey: RUNDOWN }); ontimeQueryClient.invalidateQueries({ queryKey: CUSTOM_FIELDS }); } diff --git a/apps/server/src/services/rundown-service/RundownService.ts b/apps/server/src/services/rundown-service/RundownService.ts index 000b37468..bd008d7a8 100644 --- a/apps/server/src/services/rundown-service/RundownService.ts +++ b/apps/server/src/services/rundown-service/RundownService.ts @@ -228,10 +228,16 @@ function updateRuntimeOnChange() { ); } +type NotifyChangesOptions = { + timer?: boolean | string[]; // whether to notify the timer, could be a yes / no or an array of affected IDs + external?: boolean; // whether to notify external services + reload?: boolean; // major change, clients should consider refetching everything +}; + /** * Notify services of changes in the rundown */ -function notifyChanges(options: { timer?: boolean | string[]; external?: boolean }) { +function notifyChanges(options: NotifyChangesOptions) { if (options.timer) { const playableEvents = getPlayableEvents(); @@ -249,6 +255,7 @@ function notifyChanges(options: { timer?: boolean | string[]; external?: boolean // advice socket subscribers of change const payload = { changes: Array.isArray(options.timer) ? options.timer : undefined, + reload: options.reload, revision: cache.getMetadata().revision, }; sendRefetch(payload); @@ -266,7 +273,7 @@ export async function initRundown(rundown: Readonly, customFields updateRuntimeOnChange(); // notify timer of change - notifyChanges({ timer: true }); + notifyChanges({ timer: true, external: true, reload: true }); } export async function setFrozenState(state: boolean) {