From 27422294bc4cca7e1e5f7cb39dbc8fda8e558d21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Wed, 28 Jul 2021 00:07:20 +0200 Subject: [PATCH] screencast singleton. --- src/component/screencast.vue | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/component/screencast.vue b/src/component/screencast.vue index 427f6e69..42947be5 100644 --- a/src/component/screencast.vue +++ b/src/component/screencast.vue @@ -13,7 +13,8 @@ }) export default class extends Vue { @Ref('image') readonly _image!: HTMLImageElement - private active = false + private running = false + private continue = false @Prop() private readonly enabled!: boolean @@ -22,7 +23,10 @@ private readonly api!: RoomApi async loop() { - while (this.active) { + if (this.running) return + this.running = true + + while (this.continue) { const lastLoad = Date.now() const res = await this.api.screenCastImage({ responseType: 'blob' }) @@ -39,6 +43,8 @@ URL.revokeObjectURL(image) } + + this.running = false } mounted() { @@ -52,14 +58,14 @@ } start() { - if (!this.active) { - this.active = true + if (!this.running) { + this.continue = true setTimeout(this.loop, 0) } } stop() { - this.active = false + this.continue = false } @Watch('enabled')