mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
screencast switch to image src.
This commit is contained in:
parent
82f45bfedd
commit
8f8094e7bd
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<img ref="image" @load="onImageLoad" />
|
<img :src="imageSrc" @load="onImageLoad" @error="onImageError" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
@ -13,7 +13,7 @@
|
|||||||
name: 'neko-screencast',
|
name: 'neko-screencast',
|
||||||
})
|
})
|
||||||
export default class extends Vue {
|
export default class extends Vue {
|
||||||
@Ref('image') readonly _image!: HTMLImageElement
|
private imageSrc = ''
|
||||||
private running = false
|
private running = false
|
||||||
private continue = false
|
private continue = false
|
||||||
|
|
||||||
@ -32,29 +32,19 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await this.api.screenCastImage({ responseType: 'blob' })
|
const res = await this.api.screenCastImage({ responseType: 'blob' })
|
||||||
const image = URL.createObjectURL(res.data)
|
this.imageSrc = URL.createObjectURL(res.data)
|
||||||
|
|
||||||
if (this._image) {
|
|
||||||
this._image.src = image
|
|
||||||
}
|
|
||||||
|
|
||||||
const delay = lastLoad - Date.now() + REFRESH_RATE
|
const delay = lastLoad - Date.now() + REFRESH_RATE
|
||||||
if (delay > 0) {
|
if (delay > 0) {
|
||||||
await new Promise((res) => setTimeout(res, delay))
|
await new Promise((res) => setTimeout(res, delay))
|
||||||
}
|
}
|
||||||
|
|
||||||
URL.revokeObjectURL(image)
|
|
||||||
} catch {
|
} catch {
|
||||||
await new Promise((res) => setTimeout(res, ERROR_DELAY_MS))
|
await new Promise((res) => setTimeout(res, ERROR_DELAY_MS))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.running = false
|
this.running = false
|
||||||
this.$emit('imageReady', false)
|
this.imageSrc = ''
|
||||||
|
|
||||||
if (this._image) {
|
|
||||||
this._image.src = ''
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
@ -88,7 +78,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
onImageLoad() {
|
onImageLoad() {
|
||||||
|
URL.revokeObjectURL(this.imageSrc)
|
||||||
this.$emit('imageReady', this.running)
|
this.$emit('imageReady', this.running)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onImageError() {
|
||||||
|
if (this.imageSrc) URL.revokeObjectURL(this.imageSrc)
|
||||||
|
this.$emit('imageReady', false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user