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 23d3de2 commit 0385790
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
62 changes: 61 additions & 1 deletion src/__tests__/serializers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { serializers, serializersV21 } from '../serializers'
import { Commands, LoadbgDecklinkCommand, PlayCommand, PlayHtmlCommand } from '../commands'
import { CgAddCommand, Commands, LoadbgDecklinkCommand, PlayCommand, PlayHtmlCommand } from '../commands'
import { TransitionType } from '../enums'

describe('serializers', () => {
Expand Down Expand Up @@ -113,4 +113,64 @@ describe('serializers', () => {

expect(result).toBe('PLAY 1-10 [html] http://example.com')
})
it('should serialize a cgAdd command with minimum params', () => {
const command: CgAddCommand = {
command: Commands.CgAdd,
params: {
channel: 1,
layer: 10,
template: 'myFolder/myTemplate',
},
}

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',
cgLayer: 2,
data: {
hello: 'world',
},
playOnLoad: true,
},
}

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"}`)
})
it('should serialize a cgAdd command with data', () => {
const command: CgAddCommand = {
command: Commands.CgAdd,
params: {
channel: 1,
layer: 10,
template: 'myFolder/myTemplate',
data: 'I am a string',
},
}

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 I am a string`)
})
})
4 changes: 3 additions & 1 deletion src/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,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 @@ -99,7 +99,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 0385790

Please sign in to comment.