Use onEffect

This commit is contained in:
Nick Mowen 2022-10-21 09:28:11 -06:00
parent ae89e817a2
commit 89adc958cd

View File

@ -1,8 +1,11 @@
import { h } from 'preact';
import { useEffect } from 'preact/hooks';
let ws;
export default function WebRtcPlayer({ camera, width, height }) {
useEffect(() => {
let ws;
function initStream(camera) {
if (location.protocol == 'https:') {
ws = new WebSocket(`wss://${window.location.host}/go2rtc/api/ws?src=${camera}`);
} else {
@ -59,10 +62,8 @@ function initStream(camera) {
// so need to create transeivers manually
pc.addTransceiver('video', {direction: 'recvonly'});
pc.addTransceiver('audio', {direction: 'recvonly'});
}
}, [camera]);
export default function WebRtcPlayer({ camera, width, height }) {
initStream(camera);
return (
<div>
<video id='video' autoplay playsinline controls muted width={width} height={height} />