/**
Copyright 2024 Google LLC
... (لایسنس) ...
*/
import cn from "classnames";
import React, { memo, ReactNode, RefObject, useEffect, useState } from "react";
import { useLiveAPIContext } from "../../contexts/LiveAPIContext";
import { AudioRecorder } from "../../lib/audio-recorder";
// آیکون توقف (Pause)
const SvgPauseIcon = () => ;
const SvgCameraIcon = () => ;
const SvgStopCamIcon = () => ;
const SvgSwitchCameraIcon = () => ;
export type ControlTrayProps = { /* ... (مثل قبل) ... */
videoRef: RefObject;
supportsVideo: boolean;
onVideoStreamChange: (stream: MediaStream | null) => void;
isAppMicActive: boolean;
onAppMicToggle: (active: boolean) => void;
isAppCamActive: boolean;
onAppCamToggle: (active: boolean) => void;
createLogoFunction: (isMini: boolean, isActive: boolean, type?: 'human' | 'ai', forFooter?: boolean) => ReactNode;
ReferenceMicrophoneIcon: () => JSX.Element;
};
const ControlTray: React.FC = ({
videoRef,
onVideoStreamChange,
supportsVideo,
isAppMicActive,
onAppMicToggle,
isAppCamActive,
onAppCamToggle,
createLogoFunction,
ReferenceMicrophoneIcon,
}) => {
// ... (state ها و useEffect ها و توابع هندلر مثل قبل) ...
const { client, connected, connect } = useLiveAPIContext();
const [audioRecorder] = useState(() => new AudioRecorder());
const [activeLocalVideoStream, setActiveLocalVideoStream] = useState(null);
const [currentFacingMode, setCurrentFacingMode] = useState<'user' | 'environment'>('user');
const [isSwitchingCamera, setIsSwitchingCamera] = useState(false);
const renderCanvasRef = React.useRef(null);
useEffect(() => { /* ... */ }, [isAppCamActive, activeLocalVideoStream, isSwitchingCamera]);
useEffect(() => { /* ... */ }, [connected, client, isAppMicActive, audioRecorder]);
useEffect(() => { /* ... */ }, [connected, activeLocalVideoStream, client, videoRef, renderCanvasRef]);
useEffect(() => { /* ... */ }, [activeLocalVideoStream, videoRef]);
const ensureConnectedAndReady = async (): Promise => { /* ... */ return true;};
const handleMicToggle = async () => { /* ... */ onAppMicToggle(!isAppMicActive);};
const startWebcam = async (facingModeToTry: 'user' | 'environment' = currentFacingMode) => { /* ... */ };
const stopWebcam = () => { /* ... */ };
const handleCamToggle = async () => { /* ... */
const newCamState = !isAppCamActive;
if (newCamState) {
if (!(await ensureConnectedAndReady())) { onAppCamToggle(false); return; }
if (!isAppMicActive) onAppMicToggle(true);
onAppCamToggle(true);
} else {
onAppCamToggle(false);
}
};
const handleSwitchCamera = async () => { /* ... */ };
return (
);
};
export default memo(ControlTray);