From 0e91b787802bf955f7696ec5da0bbfd9a6b92e1a Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Fri, 21 Oct 2022 09:31:16 -0600 Subject: [PATCH] Set url outside onEffect --- web/src/components/WebRtcPlayer.jsx | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/web/src/components/WebRtcPlayer.jsx b/web/src/components/WebRtcPlayer.jsx index b40ec83b2..680915ff3 100644 --- a/web/src/components/WebRtcPlayer.jsx +++ b/web/src/components/WebRtcPlayer.jsx @@ -1,17 +1,12 @@ import { h } from 'preact'; +import { baseUrl } from '../api/baseUrl'; import { useEffect } from 'preact/hooks'; export default function WebRtcPlayer({ camera, width, height }) { + const url = `${baseUrl.replace(/^http/, 'ws')}go2rtc/api/ws?src=${camera}`; useEffect(() => { - let ws; - - if (location.protocol == 'https:') { - ws = new WebSocket(`wss://${window.location.host}/go2rtc/api/ws?src=${camera}`); - } else { - ws = new WebSocket(`ws://${window.location.host}/go2rtc/api/ws?src=${camera}`); - } - + const ws = new WebSocket(url); ws.onopen = () => { pc.createOffer().then(offer => { pc.setLocalDescription(offer).then(() => {