Skip to content

Commit

Permalink
rebroadcast: fix unhandled rejection on stream startup failure
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Dec 12, 2023
1 parent 4b715e5 commit 3f1b45c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions common/src/read-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Buffer> {
if (readable.readableEnded || readable.destroyed)
throw new Error("stream ended");
throw new StreamEndError();

if (!length) {
return Buffer.alloc(0);
Expand Down
4 changes: 2 additions & 2 deletions plugins/prebuffer-mixin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/prebuffer-mixin/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 5 additions & 5 deletions plugins/prebuffer-mixin/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3f1b45c

Please sign in to comment.