From 3f1b45c435367b7486aaeb5002ef0f4bd63a4f10 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Tue, 12 Dec 2023 09:44:59 -0800 Subject: [PATCH] rebroadcast: fix unhandled rejection on stream startup failure --- common/src/read-stream.ts | 4 ++-- plugins/prebuffer-mixin/package-lock.json | 4 ++-- plugins/prebuffer-mixin/package.json | 2 +- plugins/prebuffer-mixin/src/main.ts | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/common/src/read-stream.ts b/common/src/read-stream.ts index 7a6124b7e3..190b6b345a 100644 --- a/common/src/read-stream.ts +++ b/common/src/read-stream.ts @@ -59,13 +59,13 @@ export async function read16BELengthLoop(readable: Readable, options: { export class StreamEndError extends Error { constructor() { - super() + super('stream ended'); } } export async function readLength(readable: Readable, length: number): Promise { if (readable.readableEnded || readable.destroyed) - throw new Error("stream ended"); + throw new StreamEndError(); if (!length) { return Buffer.alloc(0); diff --git a/plugins/prebuffer-mixin/package-lock.json b/plugins/prebuffer-mixin/package-lock.json index 955c533de5..d2c12d5c70 100644 --- a/plugins/prebuffer-mixin/package-lock.json +++ b/plugins/prebuffer-mixin/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/prebuffer-mixin", - "version": "0.10.2", + "version": "0.10.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/prebuffer-mixin", - "version": "0.10.2", + "version": "0.10.3", "license": "Apache-2.0", "dependencies": { "@scrypted/common": "file:../../common", diff --git a/plugins/prebuffer-mixin/package.json b/plugins/prebuffer-mixin/package.json index c9970177d1..60624d3405 100644 --- a/plugins/prebuffer-mixin/package.json +++ b/plugins/prebuffer-mixin/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/prebuffer-mixin", - "version": "0.10.2", + "version": "0.10.3", "description": "Video Stream Rebroadcast, Prebuffer, and Management Plugin for Scrypted.", "author": "Scrypted", "license": "Apache-2.0", diff --git a/plugins/prebuffer-mixin/src/main.ts b/plugins/prebuffer-mixin/src/main.ts index 900d770935..5a83bcfbc4 100644 --- a/plugins/prebuffer-mixin/src/main.ts +++ b/plugins/prebuffer-mixin/src/main.ts @@ -203,14 +203,14 @@ class PrebufferSession { return; this.console.log(this.streamName, 'prebuffer session started'); this.parserSessionPromise = this.startPrebufferSession(); - this.parserSessionPromise.catch(e => { - this.console.error(this.streamName, 'prebuffer session ended with error', e); - this.parserSessionPromise = undefined; - }); this.parserSessionPromise.then(pso => pso.killed.finally(() => { this.console.error(this.streamName, 'prebuffer session ended'); this.parserSessionPromise = undefined; - })); + })) + .catch(e => { + this.console.error(this.streamName, 'prebuffer session ended with error', e); + this.parserSessionPromise = undefined; + }); } canUseRtspParser(mediaStreamOptions: MediaStreamOptions) {