fix: close stream on beforeDestory Uv4lMjpeg.vue (#796)
This commit is contained in:
1 parent
05069ee43b
commit
35e6a2a5c4
1 file changed
+10
-18
@@ -5,34 +5,23 @@
|
||||
</style>
|
||||
|
||||
<template>
|
||||
<vue-load-image v-observe-visibility="visibilityChanged">
|
||||
<img slot="image" :src="url" alt="Preview" :style="webcamStyle" class="webcamImage" />
|
||||
<div slot="preloader" class="text-center py-5">
|
||||
<v-progress-circular indeterminate color="primary"></v-progress-circular>
|
||||
</div>
|
||||
<div slot="error" class="text-center py-5">
|
||||
<v-icon x-large>{{ mdiWebcamOff }}</v-icon>
|
||||
<div class="subtitle-1 mt-2">{{ $t('Panels.WebcamPanel.UrlNotAvailable') }}</div>
|
||||
</div>
|
||||
</vue-load-image>
|
||||
<img ref="webcamUv4lMjpegImage" :src="url" :alt="camSettings.name" :style="webcamStyle" class="webcamImage" />
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Component, Mixins, Prop } from 'vue-property-decorator'
|
||||
import BaseMixin from '@/components/mixins/base'
|
||||
import { GuiWebcamStateWebcam } from '@/store/gui/webcams/types'
|
||||
import { mdiWebcamOff } from '@mdi/js'
|
||||
|
||||
@Component
|
||||
export default class Uv4lMjpeg extends Mixins(BaseMixin) {
|
||||
mdiWebcamOff = mdiWebcamOff
|
||||
|
||||
private isVisible = true
|
||||
|
||||
@Prop({ required: true }) declare readonly camSettings: GuiWebcamStateWebcam
|
||||
|
||||
@Prop({ default: null }) declare readonly printerUrl: string | null
|
||||
|
||||
declare $refs: {
|
||||
webcamUv4lMjpegImage: HTMLImageElement
|
||||
}
|
||||
|
||||
get url() {
|
||||
const baseUrl = this.camSettings.urlStream
|
||||
const url = new URL(baseUrl, this.printerUrl === null ? this.hostUrl.toString() : this.printerUrl)
|
||||
@@ -49,8 +38,11 @@ export default class Uv4lMjpeg extends Mixins(BaseMixin) {
|
||||
return ''
|
||||
}
|
||||
|
||||
visibilityChanged(isVisible: boolean) {
|
||||
this.isVisible = isVisible
|
||||
beforeDestroy() {
|
||||
if (this.$refs.webcamUv4lMjpegImage) {
|
||||
this.$refs.webcamUv4lMjpegImage.removeAttribute('src')
|
||||
URL.revokeObjectURL(this.url)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in new issue
Block a user