From ae79449ad08f952c0f834261bd3ef5a643ec2cd4 Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Thu, 14 May 2020 17:31:23 +0100 Subject: [PATCH] Separated previewRequest from safePreviewRequest --- .../settingsComponents/streamSettings.vue | 2 +- .../viewComponents/streamDisplay.vue | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/components/viewComponents/settingsComponents/streamSettings.vue b/src/components/viewComponents/settingsComponents/streamSettings.vue index 91669d2a..5e5ae94e 100644 --- a/src/components/viewComponents/settingsComponents/streamSettings.vue +++ b/src/components/viewComponents/settingsComponents/streamSettings.vue @@ -59,7 +59,7 @@ export default { }, set(value) { this.$store.commit("changeSetting", ["autoGpuPreview", value]); - this.$root.$emit("globalTogglePreview", value); + this.$root.$emit("globalSafeTogglePreview", value); } }, diff --git a/src/components/viewComponents/streamDisplay.vue b/src/components/viewComponents/streamDisplay.vue index 350f751a..16ba9dcd 100644 --- a/src/components/viewComponents/streamDisplay.vue +++ b/src/components/viewComponents/streamDisplay.vue @@ -80,6 +80,9 @@ export default { this.$root.$on("globalTogglePreview", state => { this.previewRequest(state); }); + this.$root.$on("globalSafeTogglePreview", state => { + this.safePreviewRequest(state); + }); // A global signal listener to flash the stream element this.$root.$on("globalFlashStream", () => { this.flashStream(); @@ -98,7 +101,7 @@ export default { created: function() { console.log(`${this._uid} created`); // Send a request to start/stop GPU preview based on global setting - this.previewRequest(this.$store.state.globalSettings.autoGpuPreview); + this.safePreviewRequest(this.$store.state.globalSettings.autoGpuPreview); // Get FOV from settings this.updateFov(); }, @@ -168,7 +171,7 @@ export default { var a = Object.values(this.$store.state.activeStreams); let allClosed = a.every(v => v === false); if (allClosed) { - this.previewRequest(false); + this.safePreviewRequest(false); } } // If resized to anything other than zero @@ -177,7 +180,7 @@ export default { this.$store.commit("addStream", this._uid); if (this.$store.state.globalSettings.autoGpuPreview == true) { // Start the preview immediately - this.previewRequest(true); + this.safePreviewRequest(true); // Send another start preview request after 1 second /* The internal logic of this component means that a stop GPU preview @@ -197,7 +200,7 @@ export default { 2. The requests leapfrog eachother, stopping the preview, in which case the follow-up request restarts the preview in the correct location. */ - setTimeout(() => this.previewRequest(true), 250); + setTimeout(() => this.safePreviewRequest(true), 250); } } }, @@ -226,7 +229,9 @@ export default { this.displayPosition = elementPositionOnDisplay; }, - previewRequest: function(state) { + safePreviewRequest: function(state) { + // previewRequest, but only stopping preview if all streams are invisible + // and only starting preview if any stream is visible var a = Object.values(this.$store.state.activeStreams); let allClosed = a.every(v => v === false); // If all streams are closed, don't start GPU preview @@ -237,6 +242,10 @@ export default { if (state === false && !allClosed) { return false; } + return this.previewRequest(state); + }, + + previewRequest: function(state) { // If requesting starting the stream, but this component is inactive, skip if (this.$store.getters.ready == true) { var requestUri = null;