From 20524b0a712865eab34744e03a04d0253dd619bf Mon Sep 17 00:00:00 2001 From: dictor93 <33715075+dictor93@users.noreply.github.com> Date: Sat, 16 Dec 2023 11:47:40 +0200 Subject: [PATCH] fix: add port to webcam url if port is not 80 (#1566) Co-authored-by: Stefan Dej --- src/components/mixins/base.ts | 2 +- src/components/mixins/webcam.ts | 4 ++++ .../webcams/streamers/MjpegstreamerAdaptive.vue | 10 +++++----- .../webcams/streamers/WebrtcCameraStreamer.vue | 7 +------ 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/components/mixins/base.ts b/src/components/mixins/base.ts index e8a4f9fd2..1f02143dd 100644 --- a/src/components/mixins/base.ts +++ b/src/components/mixins/base.ts @@ -13,7 +13,7 @@ export default class BaseMixin extends Vue { return this.$store.getters['socket/getHostUrl'] } - get hostPort(): boolean { + get hostPort(): number { return this.$store.state.socket.port ?? 80 } diff --git a/src/components/mixins/webcam.ts b/src/components/mixins/webcam.ts index 784b3dce0..28ade9195 100644 --- a/src/components/mixins/webcam.ts +++ b/src/components/mixins/webcam.ts @@ -23,6 +23,10 @@ export default class WebcamMixin extends Mixins(BaseMixin) { // overwrite url to baseUrl, if it is an absolute URL if (baseUrl.startsWith('http') || baseUrl.startsWith('://')) url = new URL(baseUrl) + if (baseUrl.startsWith('/webcam') && ![80, 7125, 7130].includes(this.hostPort)) { + url.port = this.hostPort.toString() + } + return decodeURIComponent(url.toString()) } diff --git a/src/components/webcams/streamers/MjpegstreamerAdaptive.vue b/src/components/webcams/streamers/MjpegstreamerAdaptive.vue index 41ca032c1..fcd1399a8 100644 --- a/src/components/webcams/streamers/MjpegstreamerAdaptive.vue +++ b/src/components/webcams/streamers/MjpegstreamerAdaptive.vue @@ -84,6 +84,10 @@ export default class MjpegstreamerAdaptive extends Mixins(BaseMixin, WebcamMixin return [90, 270].includes(this.camSettings.rotation ?? 0) } + get url() { + return this.convertUrl(this.camSettings?.snapshot_url, this.printerUrl) + } + refreshFrame() { if (this.isVisible) { this.refresh = new Date().getTime() @@ -92,11 +96,7 @@ export default class MjpegstreamerAdaptive extends Mixins(BaseMixin, WebcamMixin } async setFrame() { - const baseUrl = this.camSettings.snapshot_url - - let url = new URL(baseUrl, this.printerUrl === null ? this.hostUrl.toString() : this.printerUrl) - if (baseUrl.startsWith('http') || baseUrl.startsWith('://')) url = new URL(baseUrl) - + let url = new URL(this.url) url.searchParams.append('bypassCache', this.refresh.toString()) this.request_start_time = performance.now() diff --git a/src/components/webcams/streamers/WebrtcCameraStreamer.vue b/src/components/webcams/streamers/WebrtcCameraStreamer.vue index 16140d76a..334ff82e4 100644 --- a/src/components/webcams/streamers/WebrtcCameraStreamer.vue +++ b/src/components/webcams/streamers/WebrtcCameraStreamer.vue @@ -37,12 +37,7 @@ export default class WebrtcCameraStreamer extends Mixins(BaseMixin, WebcamMixin) @Ref() declare stream: HTMLVideoElement get url() { - const baseUrl = this.camSettings.stream_url - let url = new URL(baseUrl, this.printerUrl === null ? this.hostUrl.toString() : this.printerUrl) - - if (baseUrl.startsWith('http') || baseUrl.startsWith('://')) url = new URL(baseUrl) - - return decodeURIComponent(url.toString()) + return this.convertUrl(this.camSettings?.stream_url, this.printerUrl) } get webcamStyle() {