Skip to content

Commit

Permalink
fix: cancel open connection before close fetch (mainsail-crew#450)
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Dej <[email protected]>
  • Loading branch information
meteyou authored and dw-0 committed Dec 25, 2021
1 parent ba7ef6c commit 0540798
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/webcams/Mjpegstreamer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default class Mjpegstreamer extends Mixins(BaseMixin) {
private timerFPS: number | null = null
private timerRestart: number | null = null
private stream: ReadableStream | null = null
private controller: AbortController | null = null
@Prop({ required: true })
camSettings: any
Expand Down Expand Up @@ -84,8 +85,11 @@ export default class Mjpegstreamer extends Mixins(BaseMixin) {
return contentLength
}
this.controller = new AbortController()
const { signal } = this.controller
//readable stream credit to from https://github.com/aruntj/mjpeg-readable-stream
fetch(this.url)
fetch(this.url, { signal })
.then(response => response.body)
.then(rb => {
const reader = rb?.getReader()
Expand Down Expand Up @@ -177,6 +181,7 @@ export default class Mjpegstreamer extends Mixins(BaseMixin) {
stopStream() {
if (this.timerFPS) clearTimeout(this.timerFPS)
if (this.timerRestart) clearTimeout(this.timerRestart)
this.controller?.abort()
this.stream?.cancel()
}
Expand Down

0 comments on commit 0540798

Please sign in to comment.