Pause error fixed
This commit is contained in:
parent
1353b0ead5
commit
86875dfc39
@ -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,30 @@ 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.loop()
|
||||||
|
}
|
||||||
|
else if(this.playing_count >= 300){
|
||||||
|
this.playing_count = 0
|
||||||
|
}
|
||||||
|
})
|
||||||
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 +179,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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user