Skip to content

Commit

Permalink
feat: update atem-connection and atem-state SOFIE-2504 (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian authored Nov 16, 2023
1 parent 7641cfa commit 10d1509
Show file tree
Hide file tree
Showing 15 changed files with 459 additions and 205 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"symlink-dir": "^5.1.1",
"ts-jest": "^29.1.0",
"ts-node": "^8.10.2",
"type-fest": "^3.10.0",
"typedoc": "^0.23.28",
"typescript": "~4.9.5"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/timeline-state-resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
],
"dependencies": {
"@tv2media/v-connection": "^7.3.0",
"atem-connection": "2.5.0",
"atem-state": "0.13.0",
"atem-connection": "3.3.2",
"atem-state": "1.1.0",
"cacheable-lookup": "^5.0.3",
"casparcg-connection": "^6.0.6",
"casparcg-state": "^3.0.2",
Expand All @@ -113,8 +113,8 @@
"timeline-state-resolver-types": "9.1.0-release51",
"tslib": "^2.5.1",
"tv-automation-quantel-gateway-client": "^3.1.7",
"type-fest": "^3.10.0",
"underscore": "^1.13.6",
"underscore-deep-extend": "^1.1.5",
"utf-8-validate": "^5.0.10",
"ws": "^7.5.9",
"xml-js": "^1.6.11"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as atemState from './atem-state'
import * as atemConnection from './atem-connection'
import * as casparcgConnection from './casparcg-connection'
import * as emberplusConnection from './emberplus-connection'
import * as emberplus from './emberplus'
Expand All @@ -14,7 +14,7 @@ import * as ws from './ws'
// does not work properly and need to be set up like this..

export function setupAllMocks() {
jest.mock('atem-state', () => atemState)
jest.mock('atem-connection', () => atemConnection)
jest.mock('casparcg-connection', () => casparcgConnection)
jest.mock('emberplus-connection', () => emberplusConnection)
jest.mock('emberplus', () => emberplus)
Expand Down
45 changes: 45 additions & 0 deletions packages/timeline-state-resolver/src/__mocks__/atem-connection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export * from 'atem-connection'
import * as OrigAtemConnection from 'atem-connection'
import { EventEmitter } from 'events'

const setTimeoutOrg = setTimeout

// @ts-ignore separate declarations
export class BasicAtem extends EventEmitter implements OrigAtemConnection.BasicAtem {
constructor(_options?: OrigAtemConnection.AtemOptions) {
super()
}
get state(): OrigAtemConnection.AtemState {
return OrigAtemConnection.AtemStateUtil.Create()
}
async connect(): Promise<void> {
setTimeoutOrg(() => {
this.emit('connected')
}, 10)

return new Promise<void>((resolve) => {
setTimeoutOrg(() => {
resolve()
}, 5)
})
}
async disconnect(): Promise<void> {
return new Promise<void>((resolve) => {
setTimeoutOrg(() => {
resolve()
}, 10)
})
}

async destroy(): Promise<void> {
return new Promise<void>((resolve) => {
setTimeoutOrg(() => {
resolve()
}, 10)
})
}

async sendCommand(): Promise<void> {
return Promise.resolve()
}
}
49 changes: 0 additions & 49 deletions packages/timeline-state-resolver/src/__mocks__/atem-state.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Diff States Simple diff against empty state 1`] = `
{
"audio": {
"classic": undefined,
"fairlight": {
"audioRouting": {
"outputs": {
"default": undefined,
},
"sources": undefined,
},
"crossfade": undefined,
"inputs": undefined,
"masterOutput": undefined,
"monitorOutput": undefined,
},
},
"colorGenerators": undefined,
"macros": {
"player": {
"player": true,
},
},
"media": {
"players": {
"source": true,
"status": true,
},
},
"settings": {
"multiviewer": undefined,
},
"video": {
"auxiliaries": [],
"downstreamKeyers": {
"mask": true,
"onAir": true,
"properties": true,
"sources": true,
},
"mixEffects": {
"programPreview": true,
"transitionProperties": true,
"transitionSettings": {
"DVE": false,
"dip": false,
"mix": true,
"stinger": false,
"wipe": true,
},
"transitionStatus": true,
"upstreamKeyers": {
"advancedChromaSettings": false,
"chromaSettings": false,
"dveSettings": true,
"flyKeyframes": undefined,
"lumaSettings": true,
"mask": true,
"onAir": true,
"patternSettings": true,
"sources": true,
"type": true,
},
},
"superSources": {
"border": true,
"boxes": "all",
"properties": true,
},
},
}
`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as AtemConnection from 'atem-connection'
import { compareAtemCommands, createDevice } from './util'
import { compareAtemCommands, createDevice, expectIncludesAtemCommandName } from './util'
import {
AtemTransitionStyle,
DeviceType,
Expand All @@ -8,16 +8,38 @@ import {
MappingAtemType,
Mappings,
} from 'timeline-state-resolver-types'
import { AtemState } from 'atem-state'
import { createDiffOptions } from '../diffState'

const diffStatesSpy = jest.spyOn(AtemState, 'diffStates')

describe('Diff States', () => {
beforeEach(() => {
diffStatesSpy.mockClear()
})

test('Simple diff against empty state', async () => {
const device = await createDevice()

const state1 = AtemConnection.AtemStateUtil.Create()
AtemConnection.AtemStateUtil.getMixEffect(state1, 0).programInput = 2

const diffOptions = createDiffOptions({})
expect(diffOptions).toMatchSnapshot()

expect(diffStatesSpy).toHaveBeenCalledTimes(0)

const commands = device.diffStates(undefined, state1, {})

expect(diffStatesSpy).toHaveBeenCalledTimes(1)
expect(diffStatesSpy).toHaveBeenNthCalledWith(
1,
expect.anything(),
AtemConnection.AtemStateUtil.Create(),
state1,
diffOptions
)

expect(commands).toHaveLength(1)
compareAtemCommands(commands[0].command, new AtemConnection.Commands.ProgramInputCommand(0, 2))
})
Expand All @@ -30,8 +52,15 @@ describe('Diff States', () => {
const state2 = AtemConnection.AtemStateUtil.Create()
AtemConnection.AtemStateUtil.getMixEffect(state2, 0).programInput = 3

const diffOptions = createDiffOptions({})

expect(diffStatesSpy).toHaveBeenCalledTimes(0)

const commands = device.diffStates(state1, state2, {})

expect(diffStatesSpy).toHaveBeenCalledTimes(1)
expect(diffStatesSpy).toHaveBeenNthCalledWith(1, expect.anything(), state1, state2, diffOptions)

expect(commands).toHaveLength(1)
compareAtemCommands(commands[0].command, new AtemConnection.Commands.ProgramInputCommand(0, 3))
})
Expand All @@ -42,8 +71,22 @@ describe('Diff States', () => {
const state1 = AtemConnection.AtemStateUtil.Create()
state1.video.auxilliaries[5] = 10

const diffOptions = createDiffOptions({})
expect(diffOptions.video?.auxiliaries).toStrictEqual([])

expect(diffStatesSpy).toHaveBeenCalledTimes(0)

const commands = device.diffStates(undefined, state1, {})

expect(diffStatesSpy).toHaveBeenCalledTimes(1)
expect(diffStatesSpy).toHaveBeenNthCalledWith(
1,
expect.anything(),
AtemConnection.AtemStateUtil.Create(),
state1,
diffOptions
)

expect(commands).toHaveLength(0)
})

Expand All @@ -64,8 +107,22 @@ describe('Diff States', () => {
},
}

const diffOptions = createDiffOptions(mappings)
expect(diffOptions.video?.auxiliaries).toStrictEqual([5])

expect(diffStatesSpy).toHaveBeenCalledTimes(0)

const commands = device.diffStates(undefined, state1, mappings)

expect(diffStatesSpy).toHaveBeenCalledTimes(1)
expect(diffStatesSpy).toHaveBeenNthCalledWith(
1,
expect.anything(),
AtemConnection.AtemStateUtil.Create(),
state1,
diffOptions
)

expect(commands).toHaveLength(1)
compareAtemCommands(commands[0].command, new AtemConnection.Commands.AuxSourceCommand(5, 10))
})
Expand Down Expand Up @@ -94,8 +151,7 @@ describe('Diff States', () => {
const commands = device.diffStates(undefined, deviceState1, mappings)

expect(commands).toHaveLength(2)
compareAtemCommands(commands[0].command, new AtemConnection.Commands.PreviewInputCommand(0, 2))
compareAtemCommands(commands[1].command, new AtemConnection.Commands.CutCommand(0))
expectIncludesAtemCommandName(commands, AtemConnection.Commands.CutCommand.name)
}

const deviceState2 = AtemConnection.AtemStateUtil.Create()
Expand All @@ -108,13 +164,8 @@ describe('Diff States', () => {
const commands = device.diffStates(deviceState1, deviceState2, mappings)

expect(commands).toHaveLength(4)
const transitionPropertiesCommand = new AtemConnection.Commands.TransitionPropertiesCommand(0)
transitionPropertiesCommand.updateProps({ nextStyle: 1 })

compareAtemCommands(commands[0].command, new AtemConnection.Commands.PreviewInputCommand(0, 3))
compareAtemCommands(commands[1].command, transitionPropertiesCommand)
compareAtemCommands(commands[2].command, new AtemConnection.Commands.TransitionPositionCommand(0, 0))
compareAtemCommands(commands[3].command, new AtemConnection.Commands.AutoTransitionCommand(0))
expectIncludesAtemCommandName(commands, AtemConnection.Commands.AutoTransitionCommand.name)
}
})

Expand Down Expand Up @@ -153,12 +204,8 @@ describe('Diff States', () => {
const commands = device.diffStates(deviceState1, deviceState2, mappings)

expect(commands).toHaveLength(3)
const transitionPropertiesCommand = new AtemConnection.Commands.TransitionPropertiesCommand(0)
transitionPropertiesCommand.updateProps({ nextStyle: 1 })

compareAtemCommands(commands[0].command, new AtemConnection.Commands.PreviewInputCommand(0, 4))
compareAtemCommands(commands[1].command, new AtemConnection.Commands.TransitionPositionCommand(0, 0))
compareAtemCommands(commands[2].command, new AtemConnection.Commands.AutoTransitionCommand(0))
expectIncludesAtemCommandName(commands, AtemConnection.Commands.AutoTransitionCommand.name)
}
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ describe('AtemStateBuilder', () => {
expect(expectedState.audio?.channels).toBeFalsy()
expectedState.audio = { channels: {} }

expectedState.audio.channels[1] = Object.assign(cloneDeep(Defaults.Audio.Channel), {
expectedState.audio.channels[1] = Object.assign(cloneDeep(Defaults.ClassicAudio.Channel), {
gain: 123,
balance: 456,
mixOption: 2,
Expand Down
Loading

0 comments on commit 10d1509

Please sign in to comment.