Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: in cgAdd: make cgLayer be optional #182

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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