Pause Error Fixes
This commit is contained in:
Killer069 2021-09-10 10:36:12 +05:30 committed by GitHub
commit 90af501ec9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -115,8 +115,9 @@ export class Stream {
private url : string private url : string
private bytes_count : number; private bytes_count : number;
private per_sec_bytes : number; private per_sec_bytes : number;
private timer : NodeJS.Timeout | null; private content_length : number;
private content_length : number private data_ended : boolean;
private playing_count : number;
private request : Request | null private request : Request | null
constructor(url : string, type : StreamType, duration : number, contentLength : number){ constructor(url : string, type : StreamType, duration : number, contentLength : number){
this.url = url this.url = url
@ -126,18 +127,28 @@ export class Stream {
this.per_sec_bytes = Math.ceil(contentLength / duration) this.per_sec_bytes = Math.ceil(contentLength / duration)
this.content_length = contentLength this.content_length = contentLength
this.request = null this.request = null
this.timer = null this.data_ended = false
this.playing_count = 0
this.stream.on('close', () => { this.stream.on('close', () => {
this.cleanup() this.cleanup()
}) })
this.stream.on('pause', () => {
this.playing_count++;
if(this.data_ended){
this.cleanup()
this.stream.removeAllListeners('pause')
}
else if(this.playing_count === 280){
this.playing_count = 0
this.loop()
}
})
this.loop() this.loop()
} }
private cleanup(){ private cleanup(){
clearTimeout(this.timer as NodeJS.Timeout)
this.request?.unpipe(this.stream) this.request?.unpipe(this.stream)
this.request?.destroy() this.request?.destroy()
this.timer = null
this.request = null this.request = null
this.url = '' this.url = ''
this.bytes_count = 0 this.bytes_count = 0
@ -166,9 +177,8 @@ export class Stream {
this.bytes_count += chunk.length this.bytes_count += chunk.length
}) })
setTimeout(() => { stream.on('end', () => {
if(end < this.content_length) this.loop() if(end >= this.content_length) this.data_ended = true
else this.cleanup() })
}, 280 * 1000)
} }
} }