summaryrefslogtreecommitdiffstats
path: root/src/mixins
diff options
context:
space:
mode:
authormarco <marcoambrosini@pm.me>2021-09-30 15:26:45 +0200
committermarco <marcoambrosini@pm.me>2021-10-05 18:19:58 +0200
commitb3f0878032069b5f1dca0ade6475f3af53317d4d (patch)
treebb2869bb637b00ffe72762a45e0848d48ff8d907 /src/mixins
parentf27c7d735986365eb4cceb95e5d120564a50cb5e (diff)
Handle device events conditionally
The devices mixin logic is initialized when loading the app but the devices shouldn't be initialised until the DeviceChecker's modal has been opened. Signed-off-by: marco <marcoambrosini@pm.me>
Diffstat (limited to 'src/mixins')
-rw-r--r--src/mixins/devices.js68
1 files changed, 49 insertions, 19 deletions
diff --git a/src/mixins/devices.js b/src/mixins/devices.js
index 15b7a6973..21527cde9 100644
--- a/src/mixins/devices.js
+++ b/src/mixins/devices.js
@@ -36,10 +36,48 @@ export const devices = {
videoStream: null,
videoStreamError: null,
hark: null,
+ initialized: false,
}
},
+ props: {
+ initializeOnMounted: {
+ type: Boolean,
+ default: true,
+ },
+ },
+
methods: {
+ initializeDevicesMixin() {
+ this.initialized = true
+
+ if (!this.mediaDevicesManager.isSupported()) {
+ // DOMException constructor is not supported in Internet Explorer,
+ // so a plain object is used instead.
+ this.audioStreamError = {
+ message: 'MediaDevicesManager is not supported',
+ name: 'NotSupportedError',
+ }
+ this.videoStreamError = {
+ message: 'MediaDevicesManager is not supported',
+ name: 'NotSupportedError',
+ }
+ }
+
+ this.mediaDevicesManager.enableDeviceEvents()
+ this.updateAudioStream()
+ this.updateVideoStream()
+ },
+
+ stopDevicesMixin() {
+ this.initialized = false
+
+ this.stopAudioStream()
+ this.stopVideoStream()
+ this.mediaDevicesManager.disableDeviceEvents()
+
+ },
+
updateAudioStream() {
if (!this.mediaDevicesManager.isSupported()) {
return
@@ -216,37 +254,29 @@ export const devices = {
},
mounted() {
- if (!this.mediaDevicesManager.isSupported()) {
- // DOMException constructor is not supported in Internet Explorer,
- // so a plain object is used instead.
- this.audioStreamError = {
- message: 'MediaDevicesManager is not supported',
- name: 'NotSupportedError',
- }
- this.videoStreamError = {
- message: 'MediaDevicesManager is not supported',
- name: 'NotSupportedError',
- }
+ if (this.initializeOnMounted) {
+ this.initializeDevicesMixin()
}
-
- this.mediaDevicesManager.enableDeviceEvents()
- this.updateAudioStream()
- this.updateVideoStream()
},
destroyed() {
- this.stopAudioStream()
- this.stopVideoStream()
-
- this.mediaDevicesManager.disableDeviceEvents()
+ this.stopDevicesMixin()
},
watch: {
audioInputId(audioInputId) {
+ if (!this.initialized) {
+ return
+ }
+
this.updateAudioStream()
},
videoInputId(videoInputId) {
+ if (!this.initialized) {
+ return
+ }
+
this.updateVideoStream()
},
},