From 8e2d8e016d4e35f8f3b5954b6e6e1314b93e9885 Mon Sep 17 00:00:00 2001 From: manhere <580122+manhere@users.noreply.github.com> Date: Fri, 12 May 2023 16:12:30 +0800 Subject: [PATCH 1/2] duplicate `if` --- src/components/app-video.vue | 40 +++++++++++++++++------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/components/app-video.vue b/src/components/app-video.vue index 4ae6714..9d09d01 100644 --- a/src/components/app-video.vue +++ b/src/components/app-video.vue @@ -78,29 +78,27 @@ export default { }, async doConnectStream(stream) { log('doConnectStream', this.title, stream) - if (stream) { - try { - await this.$nextTick() - - const video = this.$refs.video - log('connectStreamToVideoElement', stream, video) - if (stream) { - if ('srcObject' in video) - video.srcObject = stream - else - video.src = window.URL.createObjectURL(stream) // for older browsers - - // Keep in mind https://developers.google.com/web/updates/2017/09/autoplay-policy-changes - // But if the user allows to access camera it should be fine - // https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide - video.onloadedmetadata = () => this.playVideo(video) - video.onloadeddata = () => this.playVideo(video) - } - } - catch (err) { - trackSilentException(err) + try { + await this.$nextTick() + + const video = this.$refs.video + log('connectStreamToVideoElement', stream, video) + if (stream) { + if ('srcObject' in video) + video.srcObject = stream + else + video.src = window.URL.createObjectURL(stream) // for older browsers + + // Keep in mind https://developers.google.com/web/updates/2017/09/autoplay-policy-changes + // But if the user allows to access camera it should be fine + // https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide + video.onloadedmetadata = () => this.playVideo(video) + video.onloadeddata = () => this.playVideo(video) } } + catch (err) { + trackSilentException(err) + } }, handleClick() { if (this.showPlayButton) From 4aa01917d6dff0b3095d38eb30dc3a374b35a2e4 Mon Sep 17 00:00:00 2001 From: manhere <580122+manhere@users.noreply.github.com> Date: Sat, 13 May 2023 09:51:59 +0800 Subject: [PATCH 2/2] duplicate `if(stream)` --- src/components/app-video.vue | 38 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/components/app-video.vue b/src/components/app-video.vue index 9d09d01..ed1996c 100644 --- a/src/components/app-video.vue +++ b/src/components/app-video.vue @@ -78,26 +78,26 @@ export default { }, async doConnectStream(stream) { log('doConnectStream', this.title, stream) - try { - await this.$nextTick() - - const video = this.$refs.video - log('connectStreamToVideoElement', stream, video) - if (stream) { - if ('srcObject' in video) - video.srcObject = stream - else - video.src = window.URL.createObjectURL(stream) // for older browsers - - // Keep in mind https://developers.google.com/web/updates/2017/09/autoplay-policy-changes - // But if the user allows to access camera it should be fine - // https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide - video.onloadedmetadata = () => this.playVideo(video) - video.onloadeddata = () => this.playVideo(video) + if (stream) { + try { + await this.$nextTick() + + const video = this.$refs.video + log('connectStreamToVideoElement', stream, video) + if ('srcObject' in video) + video.srcObject = stream + else + video.src = window.URL.createObjectURL(stream) // for older browsers + + // Keep in mind https://developers.google.com/web/updates/2017/09/autoplay-policy-changes + // But if the user allows to access camera it should be fine + // https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide + video.onloadedmetadata = () => this.playVideo(video) + video.onloadeddata = () => this.playVideo(video) + } + catch (err) { + trackSilentException(err) } - } - catch (err) { - trackSilentException(err) } }, handleClick() {