From f1fa99ed467146fd0df7622674f30e433b52f902 Mon Sep 17 00:00:00 2001 From: Johan Nyman Date: Mon, 1 May 2023 06:30:40 +0200 Subject: [PATCH] fix: in cgAdd: make cgLayer and playOnLoad be optional --- src/__tests__/serializers.spec.ts | 20 +++++++++++++++++++- src/parameters.ts | 6 ++++-- src/serializers.ts | 4 ++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/__tests__/serializers.spec.ts b/src/__tests__/serializers.spec.ts index a5a5d475..337ffc39 100644 --- a/src/__tests__/serializers.spec.ts +++ b/src/__tests__/serializers.spec.ts @@ -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', () => { @@ -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`) + }) }) diff --git a/src/parameters.ts b/src/parameters.ts index f8b99dfe..b6844004 100755 --- a/src/parameters.ts +++ b/src/parameters.ts @@ -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 } export interface CgPlayParameters extends ChannelLayer, CGLayer {} diff --git a/src/serializers.ts b/src/serializers.ts index d5e02370..2cfd87cc 100755 --- a/src/serializers.ts +++ b/src/serializers.ts @@ -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 '' @@ -231,7 +231,7 @@ export const serializers: Readonly> = { channelLayerSerializer, splitCommandKeywordSerializer, cgLayerSerializer, - (_, { template, playOnLoad }) => `${template} ${playOnLoad ? '1' : '0'}`, + (_, { template, playOnLoad }) => `${template} ${playOnLoad === false ? '0' : '1'}`, cgDataSerializer, ], [Commands.CgPlay]: [