Ezmary commited on
Commit
96cc076
·
verified ·
1 Parent(s): 9884fab

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

Browse files
src/components/control-tray/ControlTray.tsx CHANGED
@@ -7,50 +7,12 @@ import React, { memo, ReactNode, RefObject, useEffect, useState } from "react";
7
  import { useLiveAPIContext } from "../../contexts/LiveAPIContext";
8
  import { AudioRecorder } from "../../lib/audio-recorder";
9
 
10
- // --- NEW SVG Icons from your HTML ---
11
- // Make sure these are defined correctly as React components
12
- // or adjust the rendering logic if you keep them as raw strings/elements.
13
-
14
- // Mic Icon (from your HTML's svg-microphoneIcon)
15
- const SvgUserMicrophoneIcon = () => (
16
- <svg width="38" height="38" viewBox="0 0 69 68" fill="none" xmlns="http://www.w3.org/2000/svg" transform="scale(0.55)">
17
- <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"/>
18
- <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"/>
19
- </svg>
20
- );
21
-
22
- // Pause Icon (from your HTML's svg-pauseIcon)
23
- const SvgUserPauseIcon = () => (
24
- <svg width="37" height="37" viewBox="0 0 37 37" fill="none" xmlns="http://www.w3.org/2000/svg">
25
- <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"/>
26
- <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"/>
27
- </svg>
28
- );
29
-
30
- // Camera Icon (from your HTML's svg-cameraIcon)
31
- const SvgUserCameraIcon = () => (
32
- <svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
33
- <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"/>
34
- </svg>
35
- );
36
-
37
- // Stop Camera Icon (from your HTML's svg-stopCamIcon)
38
- const SvgUserStopCamIcon = () => (
39
- <svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
40
- <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"/>
41
- </svg>
42
- );
43
-
44
- // Switch Camera Icon (from your HTML)
45
- const SvgUserSwitchCameraIcon = () => (
46
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="switch-camera-svg"> {/* class for styling from App.scss */}
47
- <path d="M11 19H4a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h5"/>
48
- <path d="M13 5h7a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-5"/>
49
- <path d="m17 12-3-3 3-3"/>
50
- <path d="m7 12 3 3-3 3"/>
51
- </svg>
52
- );
53
- // --- End of new SVG Icons ---
54
 
55
 
56
  export type ControlTrayProps = {
@@ -61,7 +23,8 @@ export type ControlTrayProps = {
61
  onAppMicToggle: (active: boolean) => void;
62
  isAppCamActive: boolean;
63
  onAppCamToggle: (active: boolean) => void;
64
- createLogoFunction: (isMini: boolean, isActive: boolean, type?: 'human' | 'ai') => ReactNode;
 
65
  };
66
 
67
  const ControlTray: React.FC<ControlTrayProps> = ({
@@ -73,6 +36,7 @@ const ControlTray: React.FC<ControlTrayProps> = ({
73
  isAppCamActive,
74
  onAppCamToggle,
75
  createLogoFunction,
 
76
  }) => {
77
  const { client, connected, connect } = useLiveAPIContext();
78
  const [audioRecorder] = useState(() => new AudioRecorder());
@@ -87,8 +51,7 @@ const ControlTray: React.FC<ControlTrayProps> = ({
87
  } else if (!isAppCamActive && activeLocalVideoStream) {
88
  stopWebcam();
89
  }
90
- // eslint-disable-next-line react-hooks/exhaustive-deps
91
- }, [isAppCamActive, activeLocalVideoStream, isSwitchingCamera]); // Consider adding startWebcam/stopWebcam if they change
92
 
93
  useEffect(() => {
94
  const onData = (base64: string) => {
@@ -134,16 +97,15 @@ const ControlTray: React.FC<ControlTrayProps> = ({
134
  } catch (error) { console.error("❌ Error frame:", error); }
135
  }
136
  if (connected && activeLocalVideoStream) {
137
- timeoutId = window.setTimeout(sendVideoFrame, 1000 / 4); // Send 4 frames per second
138
  }
139
  }
140
  if (connected && activeLocalVideoStream && videoRef.current) {
141
- timeoutId = window.setTimeout(sendVideoFrame, 200); // Initial delay
142
  }
143
  return () => clearTimeout(timeoutId);
144
  }, [connected, activeLocalVideoStream, client, videoRef, renderCanvasRef]);
145
 
146
-
147
  useEffect(() => {
148
  if (videoRef.current) {
149
  if (videoRef.current.srcObject !== activeLocalVideoStream) {
@@ -170,12 +132,6 @@ const ControlTray: React.FC<ControlTrayProps> = ({
170
  onAppMicToggle(false); return;
171
  }
172
  onAppMicToggle(newMicState);
173
- // If activating mic and cam is also active, ensure cam stays on user's explicit toggle.
174
- if (newMicState && isAppCamActive) {
175
- // No change to cam state, it's already explicitly managed
176
- } else if (newMicState && !isAppCamActive) {
177
- // Mic on, Cam off - large logo state handled by AppInternalLogic
178
- }
179
  };
180
 
181
  const startWebcam = async (facingModeToTry: 'user' | 'environment' = currentFacingMode) => {
@@ -186,7 +142,7 @@ const ControlTray: React.FC<ControlTrayProps> = ({
186
  setActiveLocalVideoStream(mediaStream); onVideoStreamChange(mediaStream); setCurrentFacingMode(facingModeToTry);
187
  } catch (error) {
188
  console.error(`❌ Start WC err ${facingModeToTry}:`, error);
189
- setActiveLocalVideoStream(null); onVideoStreamChange(null); onAppCamToggle(false); // Turn off cam if failed
190
  } finally { setIsSwitchingCamera(false); }
191
  };
192
 
@@ -198,69 +154,52 @@ const ControlTray: React.FC<ControlTrayProps> = ({
198
  const handleCamToggle = async () => {
199
  if (isSwitchingCamera) return;
200
  const newCamState = !isAppCamActive;
201
-
202
- if (newCamState) { // Turning camera ON
203
  if (!(await ensureConnectedAndReady())) { onAppCamToggle(false); return; }
204
- // If mic is not active, activate it because video implies audio for Gemini.
205
- // However, the user might want cam only. For now, let's keep it simple.
206
- // If Gemini requires audio with video, then this is okay:
207
  if (!isAppMicActive) onAppMicToggle(true);
208
- onAppCamToggle(true); // This will trigger startWebcam via useEffect
209
- } else { // Turning camera OFF
210
- onAppCamToggle(false); // This will trigger stopWebcam via useEffect
211
  }
212
  };
213
 
214
-
215
  const handleSwitchCamera = async () => {
216
  if (!isAppCamActive || !activeLocalVideoStream || isSwitchingCamera) return;
217
  setIsSwitchingCamera(true);
218
  const targetFacingMode = currentFacingMode === 'user' ? 'environment' : 'user';
219
- activeLocalVideoStream.getTracks().forEach(track => track.stop()); // Stop current stream before getting new one
220
  try {
221
- // Try with 'exact' first for better control
222
  const newStream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: { exact: targetFacingMode } }, audio: false });
223
  setActiveLocalVideoStream(newStream); onVideoStreamChange(newStream); setCurrentFacingMode(targetFacingMode);
224
  } catch (error) {
225
- console.warn(`❌ Switch Cam to '${targetFacingMode}' (exact) failed:`, error, "Trying without exact.");
226
- // Fallback to non-exact if 'exact' fails (some browsers/devices are picky)
227
  try {
228
- const newStreamFallback = await navigator.mediaDevices.getUserMedia({ video: { facingMode: targetFacingMode }, audio: false });
229
- setActiveLocalVideoStream(newStreamFallback); onVideoStreamChange(newStreamFallback); setCurrentFacingMode(targetFacingMode);
230
- } catch (fallbackError) {
231
- console.error(`❌ Switch Cam to '${targetFacingMode}' (fallback) also failed:`, fallbackError);
232
- // Restore previous stream if possible, or turn off cam
233
- try {
234
- const restoredStream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: currentFacingMode }, audio: false });
235
- setActiveLocalVideoStream(restoredStream); onVideoStreamChange(restoredStream);
236
- } catch (restoreError) {
237
- console.error('❌ Restore Cam err:', restoreError);
238
- setActiveLocalVideoStream(null); onVideoStreamChange(null); onAppCamToggle(false);
239
- }
240
  }
241
  } finally { setIsSwitchingCamera(false); }
242
  };
243
 
244
- // Determine layout for footer controls based on active states
245
- // The actual positioning of the logo (large vs small) is handled in AppInternalLogic and CSS
246
- const footerLayoutClass = isAppCamActive ? "layout-with-small-logo" : "layout-default";
247
-
248
  return (
249
- // The footer-controls class handles positioning at the bottom.
250
- // The inner structure will define how items are laid out.
251
- <footer id="footer-controls" className={cn("footer-controls", footerLayoutClass)}>
252
  <canvas style={{ display: "none" }} ref={renderCanvasRef} />
253
 
254
  {/* Cam Button (Left) */}
255
- <div className="cam-button-wrapper"> {/* Wrapper for cam button and switch button */}
256
  <button
257
  id="cam-button"
258
  className="control-button cam-button-color"
259
  onClick={handleCamToggle}
260
  disabled={isSwitchingCamera || !supportsVideo}
261
- aria-label={isAppCamActive ? "Stop video" : "Start video"}
262
  >
263
- {isAppCamActive ? <SvgUserStopCamIcon /> : <SvgUserCameraIcon />}
264
  </button>
265
  <div
266
  id="switch-camera-button-container"
@@ -269,32 +208,34 @@ const ControlTray: React.FC<ControlTrayProps> = ({
269
  <button
270
  id="switch-camera-button"
271
  aria-label="Switch Camera"
272
- className="switch-camera-button-content"
273
  onClick={handleSwitchCamera}
274
  disabled={!isAppCamActive || isSwitchingCamera}
275
  >
276
- <SvgUserSwitchCameraIcon />
277
  </button>
278
  </div>
279
  </div>
280
 
281
- {/* Small Logo (Center, only when cam is active) */}
282
  {isAppCamActive && (
283
- <div id="small-logo-container" className="small-logo-container">
284
- {createLogoFunction(true, true, 'human')}
285
  </div>
286
  )}
287
 
288
  {/* Mic Button (Right) */}
289
- <button
290
- id="mic-button"
291
- className="control-button mic-button-color"
292
- onClick={handleMicToggle}
293
- disabled={isSwitchingCamera}
294
- aria-label={isAppMicActive ? "Mute microphone" : "Unmute microphone"}
295
- >
296
- {isAppMicActive ? <SvgUserPauseIcon /> : <SvgUserMicrophoneIcon />}
297
- </button>
 
 
298
  </footer>
299
  );
300
  };
 
7
  import { useLiveAPIContext } from "../../contexts/LiveAPIContext";
8
  import { AudioRecorder } from "../../lib/audio-recorder";
9
 
10
+ // SVG Icons for Controls
11
+ 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>;
12
+ // SvgMicrophoneIcon ( قبلی ) دیگر استفاده نمی شود، SvgReferenceMicrophoneIcon جایگزین آن می شود
13
+ 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>;
14
+ 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>;
15
+ 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]"><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>;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
 
18
  export type ControlTrayProps = {
 
23
  onAppMicToggle: (active: boolean) => void;
24
  isAppCamActive: boolean;
25
  onAppCamToggle: (active: boolean) => void;
26
+ createLogoFunction: (isMini: boolean, isActive: boolean, type?: 'human' | 'ai', forFooter?: boolean) => ReactNode;
27
+ ReferenceMicrophoneIcon: () => JSX.Element; // *** NEW: Prop for reference mic icon ***
28
  };
29
 
30
  const ControlTray: React.FC<ControlTrayProps> = ({
 
36
  isAppCamActive,
37
  onAppCamToggle,
38
  createLogoFunction,
39
+ ReferenceMicrophoneIcon, // *** NEW ***
40
  }) => {
41
  const { client, connected, connect } = useLiveAPIContext();
42
  const [audioRecorder] = useState(() => new AudioRecorder());
 
51
  } else if (!isAppCamActive && activeLocalVideoStream) {
52
  stopWebcam();
53
  }
54
+ }, [isAppCamActive, activeLocalVideoStream, isSwitchingCamera]);
 
55
 
56
  useEffect(() => {
57
  const onData = (base64: string) => {
 
97
  } catch (error) { console.error("❌ Error frame:", error); }
98
  }
99
  if (connected && activeLocalVideoStream) {
100
+ timeoutId = window.setTimeout(sendVideoFrame, 1000 / 4);
101
  }
102
  }
103
  if (connected && activeLocalVideoStream && videoRef.current) {
104
+ timeoutId = window.setTimeout(sendVideoFrame, 200);
105
  }
106
  return () => clearTimeout(timeoutId);
107
  }, [connected, activeLocalVideoStream, client, videoRef, renderCanvasRef]);
108
 
 
109
  useEffect(() => {
110
  if (videoRef.current) {
111
  if (videoRef.current.srcObject !== activeLocalVideoStream) {
 
132
  onAppMicToggle(false); return;
133
  }
134
  onAppMicToggle(newMicState);
 
 
 
 
 
 
135
  };
136
 
137
  const startWebcam = async (facingModeToTry: 'user' | 'environment' = currentFacingMode) => {
 
142
  setActiveLocalVideoStream(mediaStream); onVideoStreamChange(mediaStream); setCurrentFacingMode(facingModeToTry);
143
  } catch (error) {
144
  console.error(`❌ Start WC err ${facingModeToTry}:`, error);
145
+ setActiveLocalVideoStream(null); onVideoStreamChange(null); onAppCamToggle(false);
146
  } finally { setIsSwitchingCamera(false); }
147
  };
148
 
 
154
  const handleCamToggle = async () => {
155
  if (isSwitchingCamera) return;
156
  const newCamState = !isAppCamActive;
157
+ if (newCamState) {
 
158
  if (!(await ensureConnectedAndReady())) { onAppCamToggle(false); return; }
159
+ // If mic is not active when turning on cam, also turn on mic.
160
+ // This is because the large logo (mic only) should disappear.
161
+ // And the small logo (mic + cam) should appear or video feed.
162
  if (!isAppMicActive) onAppMicToggle(true);
163
+ onAppCamToggle(true);
164
+ } else {
165
+ onAppCamToggle(false);
166
  }
167
  };
168
 
 
169
  const handleSwitchCamera = async () => {
170
  if (!isAppCamActive || !activeLocalVideoStream || isSwitchingCamera) return;
171
  setIsSwitchingCamera(true);
172
  const targetFacingMode = currentFacingMode === 'user' ? 'environment' : 'user';
173
+ activeLocalVideoStream.getTracks().forEach(track => track.stop());
174
  try {
 
175
  const newStream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: { exact: targetFacingMode } }, audio: false });
176
  setActiveLocalVideoStream(newStream); onVideoStreamChange(newStream); setCurrentFacingMode(targetFacingMode);
177
  } catch (error) {
178
+ console.error(`❌ Switch Cam err ${targetFacingMode}:`, error);
 
179
  try {
180
+ const restoredStream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: currentFacingMode }, audio: false });
181
+ setActiveLocalVideoStream(restoredStream); onVideoStreamChange(restoredStream);
182
+ } catch (restoreError) {
183
+ console.error('❌ Restore Cam err:', restoreError);
184
+ setActiveLocalVideoStream(null); onVideoStreamChange(null); onAppCamToggle(false);
 
 
 
 
 
 
 
185
  }
186
  } finally { setIsSwitchingCamera(false); }
187
  };
188
 
189
+ // *** MODIFIED: Footer layout for fixed positions and middle logo ***
 
 
 
190
  return (
191
+ <footer id="footer-controls" className="footer-controls fixed-layout">
 
 
192
  <canvas style={{ display: "none" }} ref={renderCanvasRef} />
193
 
194
  {/* Cam Button (Left) */}
195
+ <div id="cam-button-wrapper" className="control-button-wrapper cam-wrapper">
196
  <button
197
  id="cam-button"
198
  className="control-button cam-button-color"
199
  onClick={handleCamToggle}
200
  disabled={isSwitchingCamera || !supportsVideo}
 
201
  >
202
+ {isAppCamActive ? <SvgStopCamIcon /> : <SvgCameraIcon />}
203
  </button>
204
  <div
205
  id="switch-camera-button-container"
 
208
  <button
209
  id="switch-camera-button"
210
  aria-label="Switch Camera"
211
+ className="switch-camera-button-content group"
212
  onClick={handleSwitchCamera}
213
  disabled={!isAppCamActive || isSwitchingCamera}
214
  >
215
+ <SvgSwitchCameraIcon/>
216
  </button>
217
  </div>
218
  </div>
219
 
220
+ {/* Small Logo Container (Middle - Only when Cam is Active) */}
221
  {isAppCamActive && (
222
+ <div id="small-logo-footer-container" className="small-logo-footer">
223
+ {createLogoFunction(true, true, 'human', true)}
224
  </div>
225
  )}
226
 
227
  {/* Mic Button (Right) */}
228
+ <div id="mic-button-wrapper" className="control-button-wrapper mic-wrapper">
229
+ <button
230
+ id="mic-button"
231
+ className="control-button mic-button-color"
232
+ onClick={handleMicToggle}
233
+ disabled={isSwitchingCamera}
234
+ >
235
+ {/* *** MODIFIED: Use SvgPauseIcon for active, ReferenceMicrophoneIcon for inactive *** */}
236
+ {isAppMicActive ? <SvgPauseIcon /> : <ReferenceMicrophoneIcon />}
237
+ </button>
238
+ </div>
239
  </footer>
240
  );
241
  };