From f84b15b2d0b3ddb750b3d0e24341d4ecd23ddd70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=BE=D0=B2=20=D0=90=D1=80=D1=82?= =?UTF-8?q?=D0=B5=D0=BC?= Date: Sun, 5 Jul 2026 17:41:34 +0300 Subject: [PATCH] =?UTF-8?q?BUR-58=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BE=D0=BF=D1=82=D0=B8=D0=BC=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=B0=D1=8F=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3?= =?UTF-8?q?=D1=83=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=82=D0=BE=D0=BA=D0=B0=20=D0=B2=D0=B8=D0=B4=D0=B5?= =?UTF-8?q?=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/CameraView.tsx | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/components/CameraView.tsx b/src/components/CameraView.tsx index f33b98d..b39f544 100644 --- a/src/components/CameraView.tsx +++ b/src/components/CameraView.tsx @@ -6,6 +6,21 @@ type CameraViewProps = { wsUrl: string; }; +const CAMERA_PLAYER_CONFIG = { + enableWorker: true, + enableStashBuffer: true, + stashInitialSize: 512, + autoCleanupSourceBuffer: true, + autoCleanupMaxBackwardDuration: 10, + autoCleanupMinBackwardDuration: 5, + liveBufferLatencyChasing: true, + liveBufferLatencyMaxLatency: 5.0, + liveBufferLatencyMinRemain: 2.0, + liveSync: false, + lazyLoad: false, + deferLoadAfterSourceOpen: false, +}; + export function CameraView({ title = 'Камера', wsUrl }: CameraViewProps) { const videoRef = useRef(null); const [error, setError] = useState(null); @@ -13,6 +28,7 @@ export function CameraView({ title = 'Камера', wsUrl }: CameraViewProps) { useEffect(() => { const video = videoRef.current; let player: ReturnType | null = null; + const handlePlayerError = () => setError('Ошибка видеопотока'); if (!video) { return; @@ -30,20 +46,22 @@ export function CameraView({ title = 'Камера', wsUrl }: CameraViewProps) { } player = mpegts.createPlayer( - { type: 'mpegts', isLive: true, url: wsUrl }, - { liveBufferLatencyChasing: true, liveBufferLatencyMaxLatency: 1.5 }, + { type: 'mpegts', isLive: true, url: wsUrl, hasAudio: false }, + CAMERA_PLAYER_CONFIG, ); + player.on(mpegts.Events.ERROR, handlePlayerError); player.attachMediaElement(video); player.load(); const playResult = player.play(); if (playResult instanceof Promise) { - void playResult.then(() => setError(null)).catch(() => setError('Не удалось запустить воспроизведение')); + void playResult.then(() => setError(null)).catch(() => undefined); } return () => { video.removeEventListener('playing', clearError); + player?.off(mpegts.Events.ERROR, handlePlayerError); player?.pause(); player?.unload(); player?.detachMediaElement(); -- 2.49.1