From 117b9794f7197a06582684ada188c03ffce1606b Mon Sep 17 00:00:00 2001 From: ianshade Date: Wed, 20 May 2020 16:53:32 +0200 Subject: [PATCH 1/2] fix: Handle Remove command rejection This command fails in newer versions when there is no consumer present on the layer --- src/imageProvider.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/imageProvider.ts b/src/imageProvider.ts index 44e93b5..11691ae 100644 --- a/src/imageProvider.ts +++ b/src/imageProvider.ts @@ -223,15 +223,18 @@ export class ImageProvider { const qmax = config.stream && config.stream.qmax || 5 const streamProducerId = 998 - - await this.casparcg.do( - new AMCP.CustomCommand({ - channel: myStream.channel, - command: ( - `REMOVE ${myStream.channel}-${streamProducerId}` - ) - }) - ) + try { + await this.casparcg.do( + new AMCP.CustomCommand({ + channel: myStream.channel, + command: ( + `REMOVE ${myStream.channel}-${streamProducerId}` + ) + }) + ) + } catch (e) { + console.log(`Cannot remove consumer ${myStream.channel}-${streamProducerId}.`) + } await this.casparcg.do( new AMCP.CustomCommand({ From 03922d3da1ef98269ae1a01c4175e44d5f47c884 Mon Sep 17 00:00:00 2001 From: ianshade Date: Wed, 20 May 2020 17:12:42 +0200 Subject: [PATCH 2/2] fix: Send Add command depending on version --- src/imageProvider.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/imageProvider.ts b/src/imageProvider.ts index 11691ae..b8c919d 100644 --- a/src/imageProvider.ts +++ b/src/imageProvider.ts @@ -53,6 +53,7 @@ export class ImageProvider { private frameCounter = 0 private wasDisconnected: boolean = false + private versionBelow220: boolean = false constructor () { console.log(`Connecting to CasparCG at ${config.casparHost}, port ${config.casparPort}...`) @@ -71,6 +72,7 @@ export class ImageProvider { } async init () { + await this.checkVersion() const casparConfig = await this.casparcg.infoConfig() @@ -236,11 +238,15 @@ export class ImageProvider { console.log(`Cannot remove consumer ${myStream.channel}-${streamProducerId}.`) } + const params = this.versionBelow220 ? + `-f mpjpeg -multiple_requests 1 -qmin ${qmin} -qmax ${qmax}` : + `-format mpjpeg -multiple_requests 1 -qmin:v ${qmin} -qmax:v ${qmax}` + await this.casparcg.do( new AMCP.CustomCommand({ channel: myStream.channel, command: ( - `ADD ${myStream.channel}-${streamProducerId} STREAM http://127.0.0.1:${config.port}/feed/${myStream.id} -f mpjpeg -multiple_requests 1 -qmin ${qmin} -qmax ${qmax}` + `ADD ${myStream.channel}-${streamProducerId} STREAM http://127.0.0.1:${config.port}/feed/${myStream.id} ${params}` ) }) ) @@ -508,6 +514,13 @@ export class ImageProvider { }) ) } + private async checkVersion () { + const versionCommand = await this.casparcg.version() + const versionParts = versionCommand.response.data.toString().split('.') + if (parseInt(versionParts[0], 10) === 2 && parseInt(versionParts[1], 10) < 2) { + this.versionBelow220 = true + } + } } interface Region { id: string