Ezmary commited on
Commit
35ee466
·
verified ·
1 Parent(s): 094fd2d

Update src/components/control-tray/ControlTray.tsx

Browse files
src/components/control-tray/ControlTray.tsx CHANGED
@@ -1,370 +1,368 @@
 
 
 
 
1
  import cn from "classnames";
2
  import React, { memo, ReactNode, RefObject, useEffect, useRef, useState } from "react";
3
  import { useLiveAPIContext } from "../../contexts/LiveAPIContext";
4
- // Hooks for webcam/screen capture if still used with new UI
5
- import { useScreenCapture } from "../../hooks/use-screen-capture";
6
- import { useWebcam } from "../../hooks/use-webcam";
7
  import { AudioRecorder } from "../../lib/audio-recorder";
8
  import { isIOS } from "../../lib/platform";
9
- // import AudioPulse from "../audio-pulse/AudioPulse"; // Original pulse, new design has different aesthetic
10
- // import "./control-tray.scss"; // Comment out or remove if styles conflict
11
 
12
- // --- SVG Icon Definitions (inline for simplicity) ---
13
  const SvgPauseIcon = () => <svg width="37" height="37" viewBox="0 0 37 37" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M15.9872 29.6198V8.28342C15.9872 6.25781 15.132 5.44757 12.9713 5.44757H7.52469C5.36404 5.44757 4.50879 6.25781 4.50879 8.28342V29.6198C4.50879 31.6454 5.36404 32.4556 7.52469 32.4556H12.9713C15.132 32.4556 15.9872 31.6454 15.9872 29.6198Z" fill="#BE123C"/><path opacity="0.4" d="M31.5175 29.6198V8.28342C31.5175 6.25781 30.6622 5.44757 28.5016 5.44757H23.055C20.9093 5.44757 20.0391 6.25781 20.0391 8.28342V29.6198C20.0391 31.6454 20.8943 32.4556 23.055 32.4556H28.5016C30.6622 32.4556 31.5175 31.6454 31.5175 29.6198Z" fill="#BE123C"/></svg>;
14
- const SvgMicrophoneIcon = () => <svg width="69" height="68" viewBox="0 0 69 68" fill="none" xmlns="http://www.w3.org/2000/svg"><path opacity="0.4" d="M49.9479 27.1824C49.0803 27.1824 48.3907 27.872 48.3907 28.7396V32.2544C48.3907 40.1293 41.984 46.5361 34.109 46.5361C26.234 46.5361 19.8273 40.1293 19.8273 32.2544V28.7173C19.8273 27.8497 19.1377 27.1601 18.2701 27.1601C17.4025 27.1601 16.7129 27.8497 16.7129 28.7173V32.2321C16.7129 41.2861 23.6758 48.7384 32.5518 49.5393V54.2776C32.5518 55.1452 33.2414 55.8348 34.109 55.8348C34.9766 55.8348 35.6662 55.1452 35.6662 54.2776V49.5393C44.52 48.7607 51.5051 41.2861 51.5051 32.2321V28.7173C51.4829 27.872 50.7933 27.1824 49.9479 27.1824Z" fill="#BE123C"/><path d="M34.1099 11.3434C28.682 11.3434 24.2773 15.7481 24.2773 21.176V32.5658C24.2773 37.9938 28.682 42.3984 34.1099 42.3984C39.5379 42.3984 43.9425 37.9938 43.9425 32.5658V21.176C43.9425 15.7481 39.5379 11.3434 34.1099 11.3434ZM37.0241 26.8042C36.8684 27.3826 36.3567 27.7608 35.7784 27.7608C35.6671 27.7608 35.5559 27.7385 35.4447 27.7163C34.5771 27.4716 33.665 27.4716 32.7974 27.7163C32.0856 27.9165 31.396 27.4938 31.218 26.8042C31.0178 26.1146 31.4404 25.4027 32.1301 25.2247C33.4426 24.8688 34.8218 24.8688 36.1343 25.2247C36.8017 25.4027 37.2021 26.1146 37.0241 26.8042ZM38.2031 22.4885C38.0029 23.0224 37.5135 23.3339 36.9796 23.3339C36.8239 23.3339 36.6904 23.3116 36.5347 23.2671C34.9775 22.6887 33.2423 22.6887 31.6852 23.2671C31.0178 23.5118 30.2614 23.1559 30.0167 22.4885C29.772 21.8212 30.128 21.0648 30.7953 20.8423C32.9309 20.0637 35.289 20.0637 37.4245 20.8423C38.0919 21.087 38.4478 21.8212 38.2031 22.4885Z" fill="#BE123C"/></svg>;
15
  const SvgCameraIcon = () => <svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path opacity="0.4" d="M21.8118 5.52235H11.9265C6.29183 5.52235 4.10059 7.7136 4.10059 13.3482V26.5286C4.10059 30.318 6.16002 34.3545 11.9265 34.3545H21.8118C27.4464 34.3545 29.6376 32.1633 29.6376 26.5286V13.3482C29.6376 7.7136 27.4464 5.52235 21.8118 5.52235Z" fill="#2252A0"/><path d="M19.3406 18.9169C21.0512 18.9169 22.438 17.5302 22.438 15.8195C22.438 14.1089 21.0512 12.7222 19.3406 12.7222C17.6299 12.7222 16.2432 14.1089 16.2432 15.8195C16.2432 17.5302 17.6299 18.9169 19.3406 18.9169Z" fill="#2252A0"/><path d="M36.0629 10.3332C35.3874 9.98721 33.9705 9.5918 32.0429 10.9428L29.6045 12.6562C29.621 12.8869 29.6374 13.1011 29.6374 13.3482V26.5286C29.6374 26.7758 29.6045 26.9899 29.6045 27.2206L32.0429 28.934C33.0643 29.659 33.954 29.8896 34.6625 29.8896C35.2721 29.8896 35.7499 29.7249 36.0629 29.5601C36.7384 29.2141 37.8752 28.275 37.8752 25.919V13.9743C37.8752 11.6183 36.7384 10.6792 36.0629 10.3332Z" fill="#2252A0"/></svg>;
16
  const SvgStopCamIcon = () => <svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path opacity="0.4" d="M29.0785 10.8076L6.91966 32.9665C4.61316 31.5002 3.70703 28.8807 3.70703 26.36V13.18C3.70703 7.54555 5.89821 5.35437 11.5327 5.35437H21.4177C26.1789 5.35437 28.4854 6.9195 29.0785 10.8076Z" fill="#2252A0"/><path opacity="0.4" d="M29.2427 15.2394V26.36C29.2427 26.4918 29.2262 26.5907 29.2262 26.706C29.2262 26.8213 29.2097 26.9366 29.2097 27.052H29.2262C29.045 32.1757 26.8208 34.1856 21.417 34.1856H11.532C11.1202 34.1856 10.7412 34.1692 10.3623 34.1197L29.2427 15.2394Z" fill="#2252A0"/><path opacity="0.4" d="M29.21 27.052C29.21 26.9366 29.2264 26.8213 29.2264 26.706C29.2429 26.8213 29.2429 26.9366 29.2264 27.052H29.21Z" fill="#2252A0"/><path opacity="0.4" d="M29.2264 12.4716C29.2429 12.5869 29.2429 12.7187 29.2264 12.834C29.2264 12.7187 29.21 12.6034 29.21 12.488L29.2264 12.4716Z" fill="#2252A0"/><path d="M37.4804 13.8061V25.734C37.4804 28.0899 36.3436 29.029 35.6682 29.3749C35.3551 29.5397 34.8774 29.7209 34.2678 29.7209C33.5594 29.7209 32.6697 29.4903 31.6483 28.7654L29.2264 27.052H29.21C29.21 26.9366 29.2264 26.8213 29.2264 26.706C29.2264 26.5907 29.2429 26.4918 29.2429 26.36V15.2394L34.6302 9.85205C35.0751 9.885 35.421 10.0168 35.6682 10.1651C36.3436 10.5111 37.4804 11.4501 37.4804 13.8061Z" fill="#2252A0"/><path d="M35.8666 3.67393C35.3723 3.17968 34.565 3.17968 34.0708 3.67393L3.6744 34.0868C3.18015 34.581 3.18015 35.3883 3.6744 35.8826C3.92152 36.1132 4.23455 36.245 4.56405 36.245C4.89355 36.245 5.20657 36.1132 5.4537 35.8661L35.8666 5.45323C36.3773 4.95898 36.3773 4.16818 35.8666 3.67393Z" fill="#2252A0"/></svg>;
17
- const SvgSwitchCameraIcon = () => <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="w-[22px] h-[22px] group-hover:rotate-[360deg] transition-transform duration-300 ease-in-out"><path d="M11 19H4a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h5"/><path d="M13 5h7a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-5"/><path d="m17 12-3-3 3-3"/><path d="m7 12 3 3-3 3"/></svg>;
18
- const SvgHumanIcon = () => <svg width="70" height="70" viewBox="0 0 88 89" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M75.1481 81.6361H12.9259C9.66667 81.6361 7 78.9721 7 75.7161V58.5112C7 57.5862 7 57.1052 7.44444 56.2172C8.85185 52.9612 13 50.2232 19.4815 47.8922C24.1111 56.6982 33.3704 62.6921 44 62.6921C54.6296 62.6921 63.9259 56.6982 68.5185 47.8922C75 50.1862 79.1852 52.9982 80.5556 56.2172C81 56.6612 81 57.6232 81 58.5112V75.7161C81 78.9721 78.3333 81.6361 75.0741 81.6361H75.1481Z" stroke="#FCFCFC" strokeWidth="6.42146" strokeLinecap="round" strokeLinejoin="round"/><path d="M44.0371 50.1862C33.8519 50.1862 25.5186 41.8612 25.5186 31.6863V26.1363C25.5186 15.9613 33.8519 7.63635 44.0371 7.63635C54.2223 7.63635 62.5556 15.9613 62.5556 26.1363V31.6863C62.5556 41.8612 54.2223 50.1862 44.0371 50.1862Z" stroke="#FCFCFC" strokeWidth="6.42146" strokeLinecap="round" strokeLinejoin="round"/></svg>;
19
- // --- End SVG Icon Definitions ---
20
-
21
-
22
- // Styles for ControlTray specifically (Tailwind will handle most, this is for custom parts)
23
- const controlTrayStyles = `
24
- .footer-controls {
25
- width: 100%; display: flex; gap: 1rem; position: absolute;
26
- bottom: 0; padding: 2rem 3rem; align-items: center;
27
- z-index: 20; /* Ensure it's above video but below modals */
28
- }
29
- .footer-controls.layout-default { justify-content: space-between; }
30
- .footer-controls.layout-with-small-logo { justify-content: space-around; }
31
-
32
- .control-button {
33
- height: 80px; width: 80px; border-radius: 9999px; /* rounded-full */
34
- padding: 0; display: flex; align-items: center; justify-content: center;
35
- border-width: 1px; /* border */
36
- /* border-color will come from var(--border) via Tailwind's border-border */
37
- box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06); /* shadow-md */
38
- cursor: pointer;
39
- transition: transform 0.2s ease-out, box-shadow 0.2s ease-out;
40
- }
41
- .control-button:hover {
42
- transform: scale(1.05);
43
- box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05); /* shadow-lg */
44
- }
45
- .cam-button-color { background-color: #E0ECFF; } /* Light blue */
46
- .mic-button-color { background-color: #fecdd3; } /* Light red */
47
- .dark .cam-button-color { background-color: #223355; } /* Darker blue */
48
- .dark .mic-button-color { background-color: #5C2129; } /* Darker red */
49
-
50
- .switch-camera-button-container {
51
- position: absolute; bottom: calc(100% + 0.65rem); left: 50%;
52
- z-index: 5; opacity: 0;
53
- transform: translateY(15px) scale(0.7) translateX(-50%);
54
- pointer-events: none;
55
- transition: opacity 0.35s cubic-bezier(0.68, -0.55, 0.27, 1.55), transform 0.35s cubic-bezier(0.68, -0.55, 0.27, 1.55);
56
- transform-origin: center bottom;
57
- }
58
- .switch-camera-button-container.visible {
59
- opacity: 1; transform: translateY(0) scale(1) translateX(-50%); pointer-events: auto;
60
- }
61
- .switch-camera-button-content {
62
- width: 48px; height: 48px;
63
- background-color: var(--background); /* Uses themed background */
64
- border: 1px solid var(--border); /* Uses themed border */
65
- border-radius: 9999px; /* rounded-full */
66
- display: flex; align-items: center; justify-content: center;
67
- box-shadow: 0 5px 10px rgba(0,0,0,0.12), 0 2px 4px rgba(0,0,0,0.08);
68
- cursor: pointer; transform-origin: center;
69
- transition: transform 0.2s ease-out, box-shadow 0.2s ease-out;
70
- }
71
- .switch-camera-button-content:hover {
72
- transform: scale(1.12) rotate(-6deg);
73
- box-shadow: 0 7px 15px rgba(0,0,0,0.18), 0 3px 6px rgba(0,0,0,0.12);
74
- }
75
- .switch-camera-button-content:active { transform: scale(1.03) rotate(0deg); }
76
- .switch-camera-button-content svg {
77
- /* stroke is set by var(--foreground) or Tailwind text color */
78
- /* width/height set on SvgSwitchCameraIcon component */
79
- }
80
- #small-logo-container.flex { display: flex; align-items: center; justify-content: center; }
81
-
82
- /* Ping animation for logos */
83
- @keyframes ping { 75%, 100% { transform: scale(2); opacity: 0; } }
84
- .animate-ping { animation: ping 1s cubic-bezier(0, 0, 0.2, 1) infinite; }
85
- `;
86
 
87
 
88
  export type ControlTrayProps = {
89
  videoRef: RefObject<HTMLVideoElement>;
90
- children?: ReactNode; // Kept for extensibility, not used by new HTML structure
91
  supportsVideo: boolean;
92
- onVideoStreamChange?: (stream: MediaStream | null) => void;
 
 
 
 
 
 
93
  };
94
 
95
- // React component for the logo (replaces createLogoHTML)
96
- const LogoDisplay = ({ isMini, isHumanActive, isAiActive = false /* Not used in HTML */ }) => {
97
- if (!isHumanActive && !isAiActive) return null; // Don't render if no one is active
98
-
99
- const size = isMini ? 80 : 200;
100
- const iconSize = isMini ? 35 : 70;
101
- const insetBase = isMini
102
- ? { ping: 10, outer: 0, mid: 5, inner: 12, icon: 22 }
103
- : { ping: 40, outer: 0, mid: 20, inner: 50, icon: 65 }; // Values from HTML's JS
104
-
105
- const bgColorBase = isHumanActive ? 'blue' : (isAiActive ? 'green' : 'gray');
106
- // Tailwind classes for dynamic background colors
107
- const pingColor = `bg-${bgColorBase}-200`;
108
- const outerRingColor = `bg-${bgColorBase}-200`;
109
- const midRingColor = `bg-${bgColorBase}-300`;
110
- const innerRingColor = `bg-${bgColorBase}-400`;
111
-
112
- return (
113
- <div className="relative" style={{ width: `${size}px`, height: `${size}px` }}>
114
- <div className={`absolute rounded-full opacity-50 animate-ping ${pingColor}`} style={{ inset: `${insetBase.ping}px` }}></div>
115
- <div className={`absolute inset-0 rounded-full opacity-50 ${outerRingColor}`} style={{inset: `${insetBase.outer}px`}}></div>
116
- <div className={`absolute rounded-full opacity-50 ${midRingColor}`} style={{ inset: `${insetBase.mid}px` }}></div>
117
- <div className={`absolute rounded-full opacity-50 ${innerRingColor}`} style={{ inset: `${insetBase.inner}px` }}></div>
118
- <div className="z-10 absolute" style={{ inset: `${insetBase.icon}px`, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
119
- {isHumanActive && <SvgHumanIcon />}
120
- {/* Add AI icon if isAiActive is true and you have one */}
121
- </div>
122
- </div>
123
- );
124
- };
125
-
126
-
127
  function ControlTray({
128
  videoRef,
129
- onVideoStreamChange = () => {},
130
  supportsVideo,
 
 
 
 
 
131
  }: ControlTrayProps) {
132
- const webcam = useWebcam();
133
- const screenCapture = useScreenCapture(); // Kept if screen share button is re-added
134
 
135
- const [isCamActive, setIsCamActive] = useState(false); // New state for camera (visual)
136
- const [isMicActive, setIsMicActive] = useState(false); // New state for mic (visual)
 
137
 
 
138
  const [currentFacingMode, setCurrentFacingMode] = useState<'user' | 'environment'>('user');
139
  const [isSwitchingCamera, setIsSwitchingCamera] = useState(false);
140
-
141
- const [audioRecorder] = useState(() => new AudioRecorder());
142
- // const [inVolume, setInVolume] = useState(0); // For original AudioPulse
143
-
144
- const { client, connected, connect, disconnect, volume, setConfig } = useLiveAPIContext();
145
 
146
- // Connect to API when component mounts or when mic/cam are first activated
 
 
 
 
147
  useEffect(() => {
148
- // This is a placeholder for connection logic.
149
- // The original app had an explicit connect button.
150
- // You might want to connect automatically, or when mic/cam is first toggled.
151
- if (!connected && (isMicActive || isCamActive)) {
152
- // connect(); // Example: connect when mic/cam active
153
  }
154
- }, [isMicActive, isCamActive, connected, connect]);
 
155
 
156
 
157
- // Audio recording based on isMicActive AND connected
158
  useEffect(() => {
159
  const onData = (base64: string) => {
160
- if (client && connected && isMicActive) { // Check isMicActive
161
  client.sendRealtimeInput([{ mimeType: "audio/pcm;rate=16000", data: base64 }]);
162
  }
163
  };
164
- // const onVolume = setInVolume; // For original AudioPulse
165
-
166
- if (connected && isMicActive && audioRecorder) {
167
- audioRecorder.on("data", onData)/*.on("volume", onVolume)*/.start();
168
  } else if (audioRecorder) {
169
  audioRecorder.stop();
170
  }
171
  return () => {
172
  if (audioRecorder) {
173
- audioRecorder.off("data", onData)/*.off("volume", onVolume)*/.stop();
174
  }
175
  };
176
- }, [connected, client, isMicActive, audioRecorder]);
177
 
178
- // Video stream management
 
179
  useEffect(() => {
180
- const videoElement = videoRef.current;
181
- if (videoElement) {
182
- if (isCamActive && webcam.stream) {
183
- videoElement.srcObject = webcam.stream;
184
- videoElement.play().catch(e => console.warn("Video play failed:", e));
185
- onVideoStreamChange(webcam.stream);
186
- } else {
187
- videoElement.srcObject = null;
188
- onVideoStreamChange(null);
189
  }
190
- }
191
- }, [isCamActive, webcam.stream, videoRef, onVideoStreamChange]);
192
-
193
 
194
- // Video frame sending (simplified, adapt frame rate as needed)
195
- useEffect(() => {
196
- let frameSenderId: number;
197
- const sendFrame = () => {
198
- if (connected && isCamActive && webcam.stream && videoRef.current && client) {
199
- const video = videoRef.current;
200
- const canvas = document.createElement('canvas'); // Temporary canvas
201
- const scale = 0.25;
202
  canvas.width = video.videoWidth * scale;
203
  canvas.height = video.videoHeight * scale;
204
  if (canvas.width > 0 && canvas.height > 0) {
205
- const ctx = canvas.getContext("2d");
206
- if (ctx) {
207
- ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
208
- const base64 = canvas.toDataURL("image/jpeg", 0.8);
209
- const data = base64.slice(base64.indexOf(",") + 1);
210
- client.sendRealtimeInput([{ mimeType: "image/jpeg", data }]);
211
- }
212
  }
 
 
213
  }
214
- frameSenderId = window.setTimeout(sendFrame, 1000 / 2); // ~2 FPS, adjust as needed
215
- };
216
-
217
- if (isCamActive && connected) {
218
- frameSenderId = window.setTimeout(sendFrame, 200); // Initial delay
219
  }
220
- return () => clearTimeout(frameSenderId);
221
- }, [connected, isCamActive, webcam.stream, client, videoRef]);
222
 
 
 
 
 
 
223
 
224
- const handleToggleMic = async () => {
225
- if (!connected) { // Auto-connect if not connected
226
- try {
227
- await connect();
228
- } catch (err) {
229
- console.error("Failed to connect on mic toggle:", err);
230
- return; // Don't toggle mic if connection fails
231
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
232
  }
233
- // After ensuring connection (or if already connected)
234
- setIsMicActive(prev => !prev);
235
- // The audioRecorder useEffect will handle starting/stopping based on isMicActive & connected
236
  };
237
 
238
- const handleToggleCam = async () => {
239
  if (isSwitchingCamera) return;
240
- const newCamState = !isCamActive;
 
 
 
 
 
 
 
 
 
 
 
 
241
 
242
- if (newCamState) { // Turning camera ON
243
- if (!connected) { // Auto-connect if not connected
244
- try {
245
- await connect();
246
- } catch (err) {
247
- console.error("Failed to connect on cam toggle:", err);
248
- return;
249
- }
250
- }
251
- try {
252
- await webcam.start({ video: { facingMode: currentFacingMode }, audio: false });
253
- setIsCamActive(true);
254
- } catch (error) {
255
- console.error("Error starting webcam:", error);
256
- setIsCamActive(false); // Ensure it's off if start failed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
257
  }
258
- } else { // Turning camera OFF
259
- webcam.stop();
260
- setIsCamActive(false);
261
- // Optional: Disconnect if both mic and cam are off
262
- // if (!isMicActive && !newCamState && connected) {
263
- // disconnect();
264
- // }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
  }
266
  };
267
 
268
  const handleSwitchCamera = async () => {
269
- if (!isCamActive || isSwitchingCamera) return;
 
270
  setIsSwitchingCamera(true);
271
- const newFacingMode = currentFacingMode === 'user' ? 'environment' : 'user';
 
 
 
 
 
 
272
  try {
273
- await webcam.stop(); // Stop current stream
274
- await webcam.start({ video: { facingMode: { exact: newFacingMode } }, audio: false });
275
- setCurrentFacingMode(newFacingMode);
276
- // onVideoStreamChange already handled by webcam.stream effect
 
 
 
 
 
 
 
 
 
277
  } catch (error) {
278
- console.error("Error switching camera:", error);
279
- // Try to restore previous mode or stop
 
280
  try {
281
- await webcam.start({ video: { facingMode: currentFacingMode }, audio: false });
 
 
 
 
 
 
 
 
 
 
282
  } catch (restoreError) {
283
- console.error("Error restoring camera:", restoreError);
284
- setIsCamActive(false); // Turn off cam if all fails
285
- webcam.stop();
 
286
  }
287
  } finally {
288
  setIsSwitchingCamera(false);
289
  }
290
  };
291
 
292
- // Determine layout for footer controls
293
- const footerLayoutClass = isCamActive ? 'layout-with-small-logo' : 'layout-default';
294
-
295
- // Update large logo visibility in App.tsx (this is tricky, App.tsx owns that element)
296
- // For simplicity, we'll just log. A better way is via context or Zustand.
297
- useEffect(() => {
298
- const largeLogoEl = document.getElementById('large-logo-container');
299
- if (largeLogoEl) {
300
- if (!isCamActive && isMicActive) {
301
- largeLogoEl.innerHTML = ''; // Clear previous
302
- const logoDiv = document.createElement('div');
303
- // This is a hacky way to render the LogoDisplay component's HTML.
304
- // ReactDOM.render(<LogoDisplay isMini={false} isHumanActive={true} />, logoDiv); // This won't work directly here.
305
- // For now, just show/hide. Proper rendering needs state lift or context.
306
- // You might need to pass isMicActive up to App.tsx to render the large logo there.
307
- largeLogoEl.classList.remove('hidden');
308
- largeLogoEl.classList.add('flex');
309
- // Ideally, render <LogoDisplay isMini={false} isHumanActive={true} /> inside it from App.tsx
310
- } else {
311
- largeLogoEl.classList.add('hidden');
312
- largeLogoEl.classList.remove('flex');
313
- largeLogoEl.innerHTML = '';
314
- }
315
  }
316
- }, [isCamActive, isMicActive]);
 
317
 
318
 
319
  return (
320
- <>
321
- <style>{controlTrayStyles}</style>
322
- <div id="footer-controls" className={`footer-controls ${footerLayoutClass}`}>
323
- {/* Cam Button Wrapper (Left) */}
324
- <div id="cam-button-wrapper" className="relative flex justify-center">
 
 
 
 
 
 
 
 
 
 
 
 
325
  <button
326
- id="cam-button"
327
- className="control-button cam-button-color"
328
- onClick={handleToggleCam}
329
- disabled={isSwitchingCamera || !supportsVideo}
 
330
  >
331
- {isCamActive ? <SvgStopCamIcon /> : <SvgCameraIcon />}
332
  </button>
333
- <div
334
- id="switch-camera-button-container"
335
- className={cn("switch-camera-button-container", { visible: isCamActive && !isSwitchingCamera })}
336
- >
337
- <button
338
- id="switch-camera-button"
339
- aria-label="Switch Camera"
340
- className="switch-camera-button-content group" // Added group for icon hover
341
- onClick={handleSwitchCamera}
342
- disabled={!isCamActive || isSwitchingCamera}
343
- >
344
- <SvgSwitchCameraIcon />
345
- </button>
346
- </div>
347
  </div>
 
348
 
349
- {/* Small Logo Container (Center, if cam active) */}
350
- {isCamActive && (
351
- <div id="small-logo-container" className="flex">
352
- <LogoDisplay isMini={true} isHumanActive={true} />
353
- </div>
354
- )}
355
-
356
-
357
- {/* Mic Button (Right) */}
358
- <button
359
- id="mic-button"
360
- className="control-button mic-button-color"
361
- onClick={handleToggleMic}
362
- disabled={isSwitchingCamera} // Mic can be used even if video not supported
 
 
 
 
 
 
 
 
 
 
 
 
 
363
  >
364
- {isMicActive ? <SvgPauseIcon /> : <SvgMicrophoneIcon />}
365
- </button>
366
- </div>
367
- </>
368
  );
369
  }
370
 
 
1
+ /**
2
+ Copyright 2024 Google LLC
3
+ ... (لایسنس و توضیحات دیگر مثل قبل) ...
4
+ */
5
  import cn from "classnames";
6
  import React, { memo, ReactNode, RefObject, useEffect, useRef, useState } from "react";
7
  import { useLiveAPIContext } from "../../contexts/LiveAPIContext";
8
+ // import { UseMediaStreamResult } from "../../hooks/use-media-stream-mux"; // دیگر استفاده نمی‌شود؟
9
+ // import { useScreenCapture } from "../../hooks/use-screen-capture"; // اگر نیاز به اشتراک صفحه نیست، حذف شود
10
+ // import { useWebcam } from "../../hooks/use-webcam"; // منطق وب‌کم در همین فایل ادغام شده
11
  import { AudioRecorder } from "../../lib/audio-recorder";
12
  import { isIOS } from "../../lib/platform";
13
+ // import AudioPulse from "../audio-pulse/AudioPulse"; // دیگر استفاده نمی‌شود
14
+ import "./control-tray.scss"; // ممکن است خالی یا حاوی استایل‌های بسیار کمی باشد
15
 
16
+ // SVG Icons for Controls
17
  const SvgPauseIcon = () => <svg width="37" height="37" viewBox="0 0 37 37" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M15.9872 29.6198V8.28342C15.9872 6.25781 15.132 5.44757 12.9713 5.44757H7.52469C5.36404 5.44757 4.50879 6.25781 4.50879 8.28342V29.6198C4.50879 31.6454 5.36404 32.4556 7.52469 32.4556H12.9713C15.132 32.4556 15.9872 31.6454 15.9872 29.6198Z" fill="#BE123C"/><path opacity="0.4" d="M31.5175 29.6198V8.28342C31.5175 6.25781 30.6622 5.44757 28.5016 5.44757H23.055C20.9093 5.44757 20.0391 6.25781 20.0391 8.28342V29.6198C20.0391 31.6454 20.8943 32.4556 23.055 32.4556H28.5016C30.6622 32.4556 31.5175 31.6454 31.5175 29.6198Z" fill="#BE123C"/></svg>;
18
+ const SvgMicrophoneIcon = () => <svg width="38" height="38" viewBox="0 0 69 68" fill="none" xmlns="http://www.w3.org/2000/svg" transform="scale(0.55)"><path opacity="0.4" d="M49.9479 27.1824C49.0803 27.1824 48.3907 27.872 48.3907 28.7396V32.2544C48.3907 40.1293 41.984 46.5361 34.109 46.5361C26.234 46.5361 19.8273 40.1293 19.8273 32.2544V28.7173C19.8273 27.8497 19.1377 27.1601 18.2701 27.1601C17.4025 27.1601 16.7129 27.8497 16.7129 28.7173V32.2321C16.7129 41.2861 23.6758 48.7384 32.5518 49.5393V54.2776C32.5518 55.1452 33.2414 55.8348 34.109 55.8348C34.9766 55.8348 35.6662 55.1452 35.6662 54.2776V49.5393C44.52 48.7607 51.5051 41.2861 51.5051 32.2321V28.7173C51.4829 27.872 50.7933 27.1824 49.9479 27.1824Z" fill="#BE123C"/><path d="M34.1099 11.3434C28.682 11.3434 24.2773 15.7481 24.2773 21.176V32.5658C24.2773 37.9938 28.682 42.3984 34.1099 42.3984C39.5379 42.3984 43.9425 37.9938 43.9425 32.5658V21.176C43.9425 15.7481 39.5379 11.3434 34.1099 11.3434ZM37.0241 26.8042C36.8684 27.3826 36.3567 27.7608 35.7784 27.7608C35.6671 27.7608 35.5559 27.7385 35.4447 27.7163C34.5771 27.4716 33.665 27.4716 32.7974 27.7163C32.0856 27.9165 31.396 27.4938 31.218 26.8042C31.0178 26.1146 31.4404 25.4027 32.1301 25.2247C33.4426 24.8688 34.8218 24.8688 36.1343 25.2247C36.8017 25.4027 37.2021 26.1146 37.0241 26.8042ZM38.2031 22.4885C38.0029 23.0224 37.5135 23.3339 36.9796 23.3339C36.8239 23.3339 36.6904 23.3116 36.5347 23.2671C34.9775 22.6887 33.2423 22.6887 31.6852 23.2671C31.0178 23.5118 30.2614 23.1559 30.0167 22.4885C29.772 21.8212 30.128 21.0648 30.7953 20.8423C32.9309 20.0637 35.289 20.0637 37.4245 20.8423C38.0919 21.087 38.4478 21.8212 38.2031 22.4885Z" fill="#BE123C"/></svg>;
19
  const SvgCameraIcon = () => <svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path opacity="0.4" d="M21.8118 5.52235H11.9265C6.29183 5.52235 4.10059 7.7136 4.10059 13.3482V26.5286C4.10059 30.318 6.16002 34.3545 11.9265 34.3545H21.8118C27.4464 34.3545 29.6376 32.1633 29.6376 26.5286V13.3482C29.6376 7.7136 27.4464 5.52235 21.8118 5.52235Z" fill="#2252A0"/><path d="M19.3406 18.9169C21.0512 18.9169 22.438 17.5302 22.438 15.8195C22.438 14.1089 21.0512 12.7222 19.3406 12.7222C17.6299 12.7222 16.2432 14.1089 16.2432 15.8195C16.2432 17.5302 17.6299 18.9169 19.3406 18.9169Z" fill="#2252A0"/><path d="M36.0629 10.3332C35.3874 9.98721 33.9705 9.5918 32.0429 10.9428L29.6045 12.6562C29.621 12.8869 29.6374 13.1011 29.6374 13.3482V26.5286C29.6374 26.7758 29.6045 26.9899 29.6045 27.2206L32.0429 28.934C33.0643 29.659 33.954 29.8896 34.6625 29.8896C35.2721 29.8896 35.7499 29.7249 36.0629 29.5601C36.7384 29.2141 37.8752 28.275 37.8752 25.919V13.9743C37.8752 11.6183 36.7384 10.6792 36.0629 10.3332Z" fill="#2252A0"/></svg>;
20
  const SvgStopCamIcon = () => <svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path opacity="0.4" d="M29.0785 10.8076L6.91966 32.9665C4.61316 31.5002 3.70703 28.8807 3.70703 26.36V13.18C3.70703 7.54555 5.89821 5.35437 11.5327 5.35437H21.4177C26.1789 5.35437 28.4854 6.9195 29.0785 10.8076Z" fill="#2252A0"/><path opacity="0.4" d="M29.2427 15.2394V26.36C29.2427 26.4918 29.2262 26.5907 29.2262 26.706C29.2262 26.8213 29.2097 26.9366 29.2097 27.052H29.2262C29.045 32.1757 26.8208 34.1856 21.417 34.1856H11.532C11.1202 34.1856 10.7412 34.1692 10.3623 34.1197L29.2427 15.2394Z" fill="#2252A0"/><path opacity="0.4" d="M29.21 27.052C29.21 26.9366 29.2264 26.8213 29.2264 26.706C29.2429 26.8213 29.2429 26.9366 29.2264 27.052H29.21Z" fill="#2252A0"/><path opacity="0.4" d="M29.2264 12.4716C29.2429 12.5869 29.2429 12.7187 29.2264 12.834C29.2264 12.7187 29.21 12.6034 29.21 12.488L29.2264 12.4716Z" fill="#2252A0"/><path d="M37.4804 13.8061V25.734C37.4804 28.0899 36.3436 29.029 35.6682 29.3749C35.3551 29.5397 34.8774 29.7209 34.2678 29.7209C33.5594 29.7209 32.6697 29.4903 31.6483 28.7654L29.2264 27.052H29.21C29.21 26.9366 29.2264 26.8213 29.2264 26.706C29.2264 26.5907 29.2429 26.4918 29.2429 26.36V15.2394L34.6302 9.85205C35.0751 9.885 35.421 10.0168 35.6682 10.1651C36.3436 10.5111 37.4804 11.4501 37.4804 13.8061Z" fill="#2252A0"/><path d="M35.8666 3.67393C35.3723 3.17968 34.565 3.17968 34.0708 3.67393L3.6744 34.0868C3.18015 34.581 3.18015 35.3883 3.6744 35.8826C3.92152 36.1132 4.23455 36.245 4.56405 36.245C4.89355 36.245 5.20657 36.1132 5.4537 35.8661L35.8666 5.45323C36.3773 4.95898 36.3773 4.16818 35.8666 3.67393Z" fill="#2252A0"/></svg>;
21
+ const SvgSwitchCameraIcon = () => <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M11 19H4a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h5"/><path d="M13 5h7a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-5"/><path d="m17 12-3-3 3-3"/><path d="m7 12 3 3-3 3"/></svg>;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
 
24
  export type ControlTrayProps = {
25
  videoRef: RefObject<HTMLVideoElement>;
26
+ children?: ReactNode; // ممکن است دیگر استفاده نشود
27
  supportsVideo: boolean;
28
+ onVideoStreamChange: (stream: MediaStream | null) => void;
29
+ // Props جدید از App.tsx
30
+ isAppMicActive: boolean;
31
+ onAppMicToggle: (active: boolean) => void;
32
+ isAppCamActive: boolean;
33
+ onAppCamToggle: (active: boolean) => void;
34
+ createLogoFunction: (isMini: boolean, isActive: boolean, type?: 'human' | 'ai') => ReactNode;
35
  };
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  function ControlTray({
38
  videoRef,
39
+ onVideoStreamChange,
40
  supportsVideo,
41
+ isAppMicActive,
42
+ onAppMicToggle,
43
+ isAppCamActive,
44
+ onAppCamToggle,
45
+ createLogoFunction,
46
  }: ControlTrayProps) {
47
+ const { client, connected, connect, disconnect, volume } // volume ممکن است برای UI جدید استفاده نشود
48
+ = useLiveAPIContext();
49
 
50
+ const [audioRecorder] = useState(() => new AudioRecorder());
51
+ const [muted, setMuted] = useState(true); // Initial state, will be synced with isAppMicActive
52
+ const [inVolume, setInVolume] = useState(0); // برای نمایش ولوم در آینده، اگر نیاز شد
53
 
54
+ const [activeLocalVideoStream, setActiveLocalVideoStream] = useState<MediaStream | null>(null);
55
  const [currentFacingMode, setCurrentFacingMode] = useState<'user' | 'environment'>('user');
56
  const [isSwitchingCamera, setIsSwitchingCamera] = useState(false);
 
 
 
 
 
57
 
58
+ // Sync with App's mic/cam state
59
+ useEffect(() => {
60
+ setMuted(!isAppMicActive);
61
+ }, [isAppMicActive]);
62
+
63
  useEffect(() => {
64
+ if (isAppCamActive && !activeLocalVideoStream) {
65
+ startWebcam();
66
+ } else if (!isAppCamActive && activeLocalVideoStream) {
67
+ stopWebcam();
 
68
  }
69
+ // eslint-disable-next-line react-hooks/exhaustive-deps
70
+ }, [isAppCamActive]);
71
 
72
 
73
+ // Audio recording logic (from your original ControlTray)
74
  useEffect(() => {
75
  const onData = (base64: string) => {
76
+ if (client && connected) {
77
  client.sendRealtimeInput([{ mimeType: "audio/pcm;rate=16000", data: base64 }]);
78
  }
79
  };
80
+ if (connected && !muted && audioRecorder) {
81
+ audioRecorder.on("data", onData).on("volume", setInVolume).start();
 
 
82
  } else if (audioRecorder) {
83
  audioRecorder.stop();
84
  }
85
  return () => {
86
  if (audioRecorder) {
87
+ audioRecorder.off("data", onData).off("volume", setInVolume).stop();
88
  }
89
  };
90
+ }, [connected, client, muted, audioRecorder]);
91
 
92
+ // Video frame sending logic (simplified from your original ControlTray)
93
+ const renderCanvasRef = useRef<HTMLCanvasElement>(null);
94
  useEffect(() => {
95
+ let timeoutId = -1;
96
+ function sendVideoFrame() {
97
+ if (connected && activeLocalVideoStream) {
98
+ timeoutId = window.setTimeout(sendVideoFrame, 1000 / 0.5); // ~2 FPS
 
 
 
 
 
99
  }
100
+ const video = videoRef.current;
101
+ const canvas = renderCanvasRef.current;
102
+ if (!video || !canvas || video.readyState < video.HAVE_METADATA || video.paused || video.ended || !client) return;
103
 
104
+ try {
105
+ const ctx = canvas.getContext("2d");
106
+ if (!ctx) return;
107
+ const scale = 0.25; // کاهش اندازه فریم برای ارسال
 
 
 
 
108
  canvas.width = video.videoWidth * scale;
109
  canvas.height = video.videoHeight * scale;
110
  if (canvas.width > 0 && canvas.height > 0) {
111
+ ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
112
+ const base64 = canvas.toDataURL("image/jpeg", 0.7); // کیفیت JPEG
113
+ const data = base64.slice(base64.indexOf(",") + 1);
114
+ client.sendRealtimeInput([{ mimeType: "image/jpeg", data }]);
 
 
 
115
  }
116
+ } catch (error) {
117
+ console.error("❌ Error processing video frame:", error);
118
  }
 
 
 
 
 
119
  }
 
 
120
 
121
+ if (connected && activeLocalVideoStream && videoRef.current) {
122
+ setTimeout(sendVideoFrame, 200); // Start sending frames after a short delay
123
+ }
124
+ return () => { clearTimeout(timeoutId); };
125
+ }, [connected, activeLocalVideoStream, client, videoRef]);
126
 
127
+ // Assign stream to video element
128
+ useEffect(() => {
129
+ if (videoRef.current) {
130
+ if (videoRef.current.srcObject !== activeLocalVideoStream) {
131
+ videoRef.current.srcObject = activeLocalVideoStream;
132
+ if (activeLocalVideoStream) {
133
+ videoRef.current.play().catch(e => console.warn("Video play failed:", e));
134
  }
135
+ }
136
+ }
137
+ }, [activeLocalVideoStream, videoRef]);
138
+
139
+
140
+ const ensureConnected = async () => {
141
+ if (!connected) {
142
+ try {
143
+ await connect();
144
+ } catch (err) {
145
+ console.error('❌ Connection error:', err);
146
+ return false;
147
+ }
148
  }
149
+ return true;
 
 
150
  };
151
 
152
+ const handleMicToggle = async () => {
153
  if (isSwitchingCamera) return;
154
+ const newMicState = !isAppMicActive;
155
+ if (newMicState) { // Turning mic ON
156
+ if(!await ensureConnected()) {
157
+ onAppMicToggle(false); // Failed to connect, revert UI
158
+ return;
159
+ }
160
+ }
161
+ onAppMicToggle(newMicState);
162
+ // If mic is turned off and cam is also off, consider disconnecting
163
+ if (!newMicState && !isAppCamActive && connected) {
164
+ // await disconnect(); // یا تصمیم بگیرید که اتصال را نگه دارید
165
+ }
166
+ };
167
 
168
+ const startWebcam = async (facingModeToTry: 'user' | 'environment' = currentFacingMode) => {
169
+ if (isSwitchingCamera) return;
170
+ setIsSwitchingCamera(true); // Prevent rapid clicks
171
+
172
+ if(!await ensureConnected()) {
173
+ onAppCamToggle(false); // Failed to connect, revert UI
174
+ setIsSwitchingCamera(false);
175
+ return;
176
+ }
177
+
178
+ try {
179
+ console.log(`🚀 Starting webcam with facingMode: ${facingModeToTry}`);
180
+ const mediaStream = await navigator.mediaDevices.getUserMedia({
181
+ video: { facingMode: facingModeToTry },
182
+ audio: false, // Audio is handled by AudioRecorder
183
+ });
184
+ setActiveLocalVideoStream(mediaStream);
185
+ onVideoStreamChange(mediaStream); // Update App.tsx's videoStream if needed for other components
186
+ setCurrentFacingMode(facingModeToTry);
187
+ onAppCamToggle(true); // Update App's state
188
+ } catch (error) {
189
+ console.error(`❌ Error starting webcam with ${facingModeToTry}:`, error);
190
+ // Try fallback if initial failed
191
+ if (facingModeToTry === 'user' && (error as Error).name !== 'NotFoundError') { // Avoid retry if no camera found
192
+ try {
193
+ const fallbackStream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment' }, audio: false });
194
+ setActiveLocalVideoStream(fallbackStream);
195
+ onVideoStreamChange(fallbackStream);
196
+ setCurrentFacingMode('environment');
197
+ onAppCamToggle(true);
198
+ } catch (fallbackError) {
199
+ console.error('❌ Error starting webcam fallback:', fallbackError);
200
+ setActiveLocalVideoStream(null);
201
+ onVideoStreamChange(null);
202
+ onAppCamToggle(false);
203
+ }
204
+ } else {
205
+ setActiveLocalVideoStream(null);
206
+ onVideoStreamChange(null);
207
+ onAppCamToggle(false);
208
  }
209
+ } finally {
210
+ setIsSwitchingCamera(false);
211
+ }
212
+ };
213
+
214
+ const stopWebcam = () => {
215
+ if (activeLocalVideoStream) {
216
+ activeLocalVideoStream.getTracks().forEach(track => track.stop());
217
+ }
218
+ setActiveLocalVideoStream(null);
219
+ onVideoStreamChange(null);
220
+ onAppCamToggle(false); // Update App's state
221
+ // If mic is also off, consider disconnecting
222
+ if (!isAppMicActive && connected) {
223
+ // await disconnect(); // یا تصمیم بگیرید که اتصال را نگه دارید
224
+ }
225
+ };
226
+
227
+ const handleCamToggle = () => {
228
+ if (isAppCamActive) {
229
+ stopWebcam();
230
+ } else {
231
+ startWebcam();
232
  }
233
  };
234
 
235
  const handleSwitchCamera = async () => {
236
+ if (!isAppCamActive || !activeLocalVideoStream || isSwitchingCamera) return;
237
+
238
  setIsSwitchingCamera(true);
239
+ const targetFacingMode = currentFacingMode === 'user' ? 'environment' : 'user';
240
+
241
+ // Stop current tracks before requesting new ones
242
+ activeLocalVideoStream.getTracks().forEach(track => track.stop());
243
+ setActiveLocalVideoStream(null); // Clear stream temporarily
244
+ onVideoStreamChange(null);
245
+
246
  try {
247
+ console.log(`🔄 Switching camera to: ${targetFacingMode}`);
248
+ const newStream = await navigator.mediaDevices.getUserMedia({
249
+ video: { facingMode: { exact: targetFacingMode } },
250
+ audio: false,
251
+ });
252
+ setActiveLocalVideoStream(newStream);
253
+ onVideoStreamChange(newStream);
254
+ setCurrentFacingMode(targetFacingMode);
255
+ // Ensure video element plays the new stream
256
+ if (videoRef.current) {
257
+ videoRef.current.srcObject = newStream;
258
+ videoRef.current.play().catch(e => console.warn("Play failed on switch:", e));
259
+ }
260
  } catch (error) {
261
+ console.error(`❌ Error switching camera to ${targetFacingMode}:`, error);
262
+ // Try to restore previous stream or a default if switching failed
263
+ console.log(`Attempting to restore camera to: ${currentFacingMode}`);
264
  try {
265
+ const restoredStream = await navigator.mediaDevices.getUserMedia({
266
+ video: { facingMode: currentFacingMode }, // Try previous mode
267
+ audio: false,
268
+ });
269
+ setActiveLocalVideoStream(restoredStream);
270
+ onVideoStreamChange(restoredStream);
271
+ // No need to change currentFacingMode as it's restored
272
+ if (videoRef.current) {
273
+ videoRef.current.srcObject = restoredStream;
274
+ videoRef.current.play().catch(e => console.warn("Play failed on restore:", e));
275
+ }
276
  } catch (restoreError) {
277
+ console.error('❌ Error restoring camera:', restoreError);
278
+ // If all fails, turn off camera
279
+ stopWebcam();
280
+ onAppCamToggle(false);
281
  }
282
  } finally {
283
  setIsSwitchingCamera(false);
284
  }
285
  };
286
 
287
+ // Stop streams on disconnect
288
+ useEffect(() => {
289
+ if (!connected) {
290
+ if (activeLocalVideoStream) {
291
+ activeLocalVideoStream.getTracks().forEach(track => track.stop());
292
+ setActiveLocalVideoStream(null);
293
+ onVideoStreamChange(null);
294
+ onAppCamToggle(false); // Ensure UI consistency
295
+ }
296
+ if (audioRecorder.isRecording()) {
297
+ audioRecorder.stop();
298
+ onAppMicToggle(false); // Ensure UI consistency
299
+ }
 
 
 
 
 
 
 
 
 
 
300
  }
301
+ // eslint-disable-next-line react-hooks/exhaustive-deps
302
+ }, [connected]);
303
 
304
 
305
  return (
306
+ <footer id="footer-controls" className={cn("footer-controls", {
307
+ 'layout-default': !isAppCamActive,
308
+ 'layout-with-small-logo': isAppCamActive
309
+ })}>
310
+ <canvas style={{ display: "none" }} ref={renderCanvasRef} />
311
+ {/* Cam Button Wrapper (Now on the Left) */}
312
+ <div id="cam-button-wrapper" className="relative flex justify-center">
313
+ <button
314
+ id="cam-button"
315
+ className="control-button cam-button-color"
316
+ onClick={handleCamToggle}
317
+ disabled={isSwitchingCamera || !supportsVideo}
318
+ title={isAppCamActive ? "Stop Camera" : "Start Camera"}
319
+ >
320
+ {isAppCamActive ? <SvgStopCamIcon /> : <SvgCameraIcon />}
321
+ </button>
322
+ <div id="switch-camera-button-container" className={cn("switch-camera-button-container", { 'visible': isAppCamActive })}>
323
  <button
324
+ id="switch-camera-button"
325
+ aria-label="Switch Camera"
326
+ className="switch-camera-button-content"
327
+ onClick={handleSwitchCamera}
328
+ disabled={!isAppCamActive || isSwitchingCamera}
329
  >
330
+ <SvgSwitchCameraIcon/>
331
  </button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332
  </div>
333
+ </div>
334
 
335
+ {/* Small Logo Container (middle when cam is active) */}
336
+ {isAppCamActive && (
337
+ <div id="small-logo-container" className="flex items-center justify-center">
338
+ {createLogoFunction(true, isAppCamActive, 'human')}
339
+ </div>
340
+ )}
341
+
342
+ {/* Mic Button (Now on the Right) */}
343
+ <button
344
+ id="mic-button"
345
+ className="control-button mic-button-color"
346
+ onClick={handleMicToggle}
347
+ disabled={isSwitchingCamera} // Disable if camera is switching, or other conditions
348
+ title={isAppMicActive ? "Mute Microphone" : "Unmute Microphone"}
349
+ >
350
+ {isAppMicActive ? <SvgPauseIcon /> : <SvgMicrophoneIcon />}
351
+ </button>
352
+
353
+ {/* Original connect/disconnect button, hidden but logic can be reused or adapted */}
354
+ {/* This button's functionality is now implicitly handled by mic/cam toggles */}
355
+ <button
356
+ style={{ display: 'none'}}
357
+ onClick={async () => {
358
+ if (connected) await disconnect();
359
+ else await connect();
360
+ }}
361
+ title={connected ? "Disconnect Stream" : "Connect Stream"}
362
  >
363
+ {connected ? "Connected (Internal)" : "Disconnected (Internal)"}
364
+ </button>
365
+ </footer>
 
366
  );
367
  }
368