From e0d0332747f7808ce71e0b6851b5553d2b29a365 Mon Sep 17 00:00:00 2001 From: killer069 <65385476+killer069@users.noreply.github.com> Date: Thu, 9 Sep 2021 21:46:23 +0530 Subject: [PATCH] Stream aborted fixes --- play-dl/YouTube/classes/LiveStream.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/play-dl/YouTube/classes/LiveStream.ts b/play-dl/YouTube/classes/LiveStream.ts index 4ffd623..32d264f 100644 --- a/play-dl/YouTube/classes/LiveStream.ts +++ b/play-dl/YouTube/classes/LiveStream.ts @@ -115,6 +115,7 @@ export class Stream { private url : string private bytes_count : number; private per_sec_bytes : number; + private timer : NodeJS.Timeout | null; private content_length : number private request : Request | null constructor(url : string, type : StreamType, duration : number, contentLength : number){ @@ -125,6 +126,7 @@ export class Stream { this.per_sec_bytes = Math.ceil(contentLength / duration) this.content_length = contentLength this.request = null + this.timer = null this.stream.on('close', () => { this.cleanup() }) @@ -132,8 +134,10 @@ export class Stream { } private cleanup(){ + clearTimeout(this.timer as NodeJS.Timeout) this.request?.unpipe(this.stream) this.request?.destroy() + this.timer = null this.request = null this.url = '' this.bytes_count = 0 @@ -162,9 +166,9 @@ export class Stream { this.bytes_count += chunk.length }) - stream.on('end', () => { + setTimeout(() => { if(end < this.content_length) this.loop() else this.cleanup() - }) + }, 280 * 1000) } }