From 6350a5b1754b4deae9122c8498930984c1a6a5ec Mon Sep 17 00:00:00 2001 From: Julian Waller Date: Mon, 31 Jul 2023 15:41:14 +0100 Subject: [PATCH] fix: perform deep diff for `MultiViewerSourceUpdateCommand` before updating state #132 --- .../Settings/MultiViewerSourceCommand.ts | 21 +++++++++++++++++-- src/lib/atemUtil.ts | 4 ++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/commands/Settings/MultiViewerSourceCommand.ts b/src/commands/Settings/MultiViewerSourceCommand.ts index a78d0c3ba..678d87963 100644 --- a/src/commands/Settings/MultiViewerSourceCommand.ts +++ b/src/commands/Settings/MultiViewerSourceCommand.ts @@ -1,6 +1,7 @@ import { BasicWritableCommand, DeserializedCommand } from '../CommandBase' import { AtemState, AtemStateUtil, InvalidIdError } from '../../state' import { MultiViewerSourceState } from '../../state/settings' +import { isRunningInTests } from '../../lib/atemUtil' export class MultiViewerSourceCommand extends BasicWritableCommand< Pick @@ -47,14 +48,30 @@ export class MultiViewerSourceUpdateCommand extends DeserializedCommand= state.info.multiviewer.count) { throw new InvalidIdError('MultiViewer', this.multiViewerId) } const multiviewer = AtemStateUtil.getMultiViewer(state, this.multiViewerId) + const currentWindow = multiviewer.windows[this.properties.windowIndex] + + // The Constellation HD range has a bug where it sends this command for every window on every frame + // This hides that from library consumers by doing a deep diff, when we usually do not. + if (currentWindow && !isRunningInTests()) { + let isChanged = false + for (const stringKey of Object.keys(this.properties)) { + const typedKey = stringKey as keyof MultiViewerSourceState + if (this.properties[typedKey] !== currentWindow[typedKey]) { + isChanged = true + break + } + } + if (!isChanged) return [] + } + multiviewer.windows[this.properties.windowIndex] = { - ...multiviewer.windows[this.properties.windowIndex], + ...currentWindow, ...this.properties, } diff --git a/src/lib/atemUtil.ts b/src/lib/atemUtil.ts index 373681637..4b9fee164 100644 --- a/src/lib/atemUtil.ts +++ b/src/lib/atemUtil.ts @@ -292,3 +292,7 @@ export function omit(o: T, ...keys: K[]): Omit { export function assertNever(_val: never): void { // Nothing to do } + +export function isRunningInTests(): boolean { + return process.env.JEST_WORKER_ID !== undefined +}