Skip to content

Commit

Permalink
fix: in cgAdd: make cgLayer be optional
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Feb 22, 2024
1 parent 278eb2b commit 3066ee3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
42 changes: 42 additions & 0 deletions src/__tests__/serializers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,46 @@ describe('serializers', () => {

expect(result).toBe(`MIXER 1-10 FILL 0.1 0.2 0.7 0.8 20`)
})
it('should serialize a cgAdd command with minimum params', () => {
const command: CgAddCommand = {
command: Commands.CgAdd,
params: {
channel: 1,
layer: 10,
template: 'myFolder/myTemplate',
playOnLoad: false,
},
}

const serialized = serializers[Commands.CgAdd].map((fn) => fn(command.command, command.params))

expect(serialized).toHaveLength(serializers[Commands.CgAdd].length)

const result = serialized.filter((l) => l !== '').join(' ')

expect(result).toBe(`CG 1-10 ADD 1 "myFolder/myTemplate" 0`)
})
it('should serialize a cgAdd command with all params defined', () => {
const command: CgAddCommand = {
command: Commands.CgAdd,
params: {
channel: 1,
layer: 10,
template: 'myFolder/myTemplate',
playOnLoad: true,
cgLayer: 2,
data: {
hello: 'world',
},
},
}

const serialized = serializers[Commands.CgAdd].map((fn) => fn(command.command, command.params))

expect(serialized).toHaveLength(serializers[Commands.CgAdd].length)

const result = serialized.filter((l) => l !== '').join(' ')

expect(result).toBe(`CG 1-10 ADD 2 "myFolder/myTemplate" 1 "{\\"hello\\":\\"world\\"}"`)
})
})
4 changes: 3 additions & 1 deletion src/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,13 @@ export interface DataRemoveParameters {
}

export interface CGLayer {
cgLayer: number
/** cgLayer (defaults to 1) */
cgLayer?: number
}

export interface CgAddParameters extends ChannelLayer, CGLayer {
template: string
/** If true, CasparCG will call play() in the template after load. */
playOnLoad: boolean
data?: Record<string, any> | string
}
Expand Down
2 changes: 1 addition & 1 deletion src/serializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const callAttributeSerializer = (_: Commands, { param, value }: CallParameters)
const consumerSerializer = (_: Commands, { consumer, parameters }: AddParameters) => consumer + ' ' + parameters
const removeSerializer = (_: Commands, { consumer }: RemoveParameters) => consumer + ''

const cgLayerSerializer = (_: Commands, { cgLayer }: CGLayer) => cgLayer + ''
const cgLayerSerializer = (_: Commands, { cgLayer }: CGLayer) => (cgLayer === undefined ? '1' : `${cgLayer}`)
const cgDataSerializer = (_: Commands, { data }: CgUpdateParameters | CgAddParameters) => {
if (!data) {
return ''
Expand Down

0 comments on commit 3066ee3

Please sign in to comment.