Skip to content

Commit

Permalink
fix: in cgAdd: make cgLayer and playOnLoad be optional
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed May 1, 2023
1 parent 23d3de2 commit f1fa99e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
20 changes: 19 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,22 @@ 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 1`)
})
})
6 changes: 4 additions & 2 deletions src/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,14 @@ export interface DataRemoveParameters {
}

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

export interface CgAddParameters extends ChannelLayer, CGLayer {
template: string
playOnLoad: boolean
/** If true CasparCG will call play() in the template after load. (defaults to true) */
playOnLoad?: boolean
data?: Record<string, any> | string
}
export interface CgPlayParameters extends ChannelLayer, CGLayer {}
Expand Down
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -231,7 +231,7 @@ export const serializers: Readonly<Serializers<AMCPCommand>> = {
channelLayerSerializer,
splitCommandKeywordSerializer,
cgLayerSerializer,
(_, { template, playOnLoad }) => `${template} ${playOnLoad ? '1' : '0'}`,
(_, { template, playOnLoad }) => `${template} ${playOnLoad === false ? '0' : '1'}`,
cgDataSerializer,
],
[Commands.CgPlay]: [
Expand Down

0 comments on commit f1fa99e

Please sign in to comment.