mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-08 12:15:25 +03:00
Fix webrtc timing out
This commit is contained in:
parent
9df5927ac5
commit
6866edef76
@ -1,11 +1,8 @@
|
|||||||
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 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' }],
|
||||||
@ -59,7 +56,7 @@ export default function WebRtcPlayer({ camera, width, height }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const connect = useCallback(async () => {
|
const connect = useCallback(async (ws) => {
|
||||||
const pc = await PeerConnection('video+audio');
|
const pc = await PeerConnection('video+audio');
|
||||||
|
|
||||||
ws.addEventListener('open', () => {
|
ws.addEventListener('open', () => {
|
||||||
@ -89,15 +86,17 @@ export default function WebRtcPlayer({ camera, width, height }) {
|
|||||||
ws.addEventListener('close', () => {
|
ws.addEventListener('close', () => {
|
||||||
pc.close();
|
pc.close();
|
||||||
})
|
})
|
||||||
}, [PeerConnection, ws]);
|
}, [PeerConnection]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
connect();
|
const url = `${baseUrl.replace(/^http/, 'ws')}live/webrtc/api/ws?src=${camera}`;
|
||||||
|
const ws = new WebSocket(url);
|
||||||
|
connect(ws);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
ws.close();
|
ws.close();
|
||||||
}
|
}
|
||||||
}, [connect, ws]);
|
}, [camera, connect]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user