Make more efficient

This commit is contained in:
Nick Mowen 2023-10-20 16:08:22 -06:00
parent d3e849fca4
commit 5deda8a855

View File

@ -1,11 +1,11 @@
import { h } from 'preact'; import { h } from 'preact';
import { baseUrl } from '../api/baseUrl'; import { baseUrl } from '../api/baseUrl';
import { useCallback, useEffect } from 'preact/hooks'; import { useCallback, useEffect } from 'preact/hooks';
import { useMemo } from 'react';
export default function WebRtcPlayer({ camera, width, height }) { export default function WebRtcPlayer({ camera, width, height }) {
const url = `${baseUrl.replace(/^http/, 'ws')}live/webrtc/api/ws?src=${camera}`; const url = `${baseUrl.replace(/^http/, 'ws')}live/webrtc/api/ws?src=${camera}`;
const ws = new WebSocket(url); const ws = useMemo(() => new WebSocket(url), [url])
const PeerConnection = useCallback(async (media) => { const PeerConnection = useCallback(async (media) => {
const pc = new RTCPeerConnection({ const pc = new RTCPeerConnection({
iceServers: [{ urls: 'stun:stun.l.google.com:19302' }], iceServers: [{ urls: 'stun:stun.l.google.com:19302' }],