From 3066ee355e1bfa628602e3707ec980ad616b2502 Mon Sep 17 00:00:00 2001 From: Johan Nyman Date: Thu, 22 Feb 2024 07:58:59 +0100 Subject: [PATCH] fix: in cgAdd: make cgLayer be optional --- src/__tests__/serializers.spec.ts | 42 +++++++++++++++++++++++++++++++ src/parameters.ts | 4 ++- src/serializers.ts | 2 +- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/__tests__/serializers.spec.ts b/src/__tests__/serializers.spec.ts index 15d576c6..f7913129 100644 --- a/src/__tests__/serializers.spec.ts +++ b/src/__tests__/serializers.spec.ts @@ -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\\"}"`) + }) }) diff --git a/src/parameters.ts b/src/parameters.ts index 3d8a215b..582ef0d5 100644 --- a/src/parameters.ts +++ b/src/parameters.ts @@ -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 } diff --git a/src/serializers.ts b/src/serializers.ts index ce842d92..fed913b9 100755 --- a/src/serializers.ts +++ b/src/serializers.ts @@ -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 ''