Ezmary commited on
Commit
cfee1d1
·
verified ·
1 Parent(s): 57e44fe

Update src/App.tsx

Browse files
Files changed (1) hide show
  1. src/App.tsx +232 -80
src/App.tsx CHANGED
@@ -1,9 +1,6 @@
1
  // src/App.tsx
2
- /**
3
- Copyright 2024 Google LLC
4
- ... (لایسنس) ...
5
- */
6
 
 
7
  import React, { useEffect, useRef, useState } from "react";
8
  import './App.scss';
9
  import { LiveAPIProvider, useLiveAPIContext } from "./contexts/LiveAPIContext";
@@ -15,6 +12,7 @@ import { LiveConfig } from "./multimodal-live-types";
15
  import LogoAnimation from "./components/logo-animation/LogoAnimation";
16
  import BackButton from "./components/back-button/BackButton";
17
 
 
18
  const myCustomInstruction = `
19
  تو دستیار صوتی و تصویری پیشرفته از "اپلیکیشن هوش مصنوعی هوشان" هستی
20
  وظیفه اصلی تو کمک به کاربر است.
@@ -28,9 +26,9 @@ const myCustomInstruction = `
28
  ....
29
  در تمام پاسخ‌ها، اعداد را نیز کاملاً به فارسی بیان کن مگر اینکه در حال صحبت به زبان دیگری غیر از فارسی با کاربر بودی به همون زبان اعداد بگو، و همچنین اعداد به فارسی درست بگو این حالت (مثلاً بگو 'ده' یا 'بیست و پنج'، نه '10' یا 'twenty-five').
30
  وقتی کاربر در مورد هویت تو می‌پرسد، خودت را اینگونه معرفی کن: "من دستیار صوتی و تصویری از برنامه هوش مصنوعی هوشان هستم. چگونه می‌توانم به شما کمک کنم؟"
31
- مهم: هنگامی که پیام ورودی فقط شامل متن "START_GREETING" بود، *فقط* با یک خوشامدگویی کوتاه و دوستانه به فارسی پاسخ بده، مانند "سلام، چطور می‌تونم کمکتون کنم؟" یا "سلام حالتون چطوره!"
32
  هشدار: به هیچ عنوان در هنگام مکالمه و پیام دادن به کاربر نباید شکلک بفرستی و یا بیان کنی شکلک و یا اموجی هارو حتی شکلک هارو نیاز نیست بگی اسم شونو در هنگام صحبت اگر شکلک نیاز بود بود بگی نباید اسم شکلک بگی
33
- **مهم: به هیچ عنوان در پاسخ‌های خود از ایموجی استفاده نکن.**
34
  `.trim();
35
 
36
  const initialAppConfig: LiveConfig = {
@@ -40,106 +38,260 @@ const initialAppConfig: LiveConfig = {
40
  },
41
  };
42
 
43
- const SvgReferenceMicrophoneIcon = () => (
44
- <svg className="reference-mic-svg" viewBox="0 0 69 68" fill="none" xmlns="http://www.w3.org/2000/svg">
45
- <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"/>
46
- <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"/>
47
- </svg>
48
- );
49
-
50
- const AppCore: React.FC<{
51
- currentFacingMode: 'user' | 'environment';
52
- setCurrentFacingMode: React.Dispatch<React.SetStateAction<'user' | 'environment'>>;
53
- }> = ({ currentFacingMode, setCurrentFacingMode }) => {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  const videoRef = useRef<HTMLVideoElement>(null);
 
 
 
55
  const [isMicActive, setIsMicActive] = useState(false);
56
  const [isCamActive, setIsCamActive] = useState(false);
57
  const [isNotificationOpen, setIsNotificationOpen] = useState(false);
 
 
 
58
  const notificationButtonRef = useRef<HTMLButtonElement>(null);
59
  const notificationPopoverRef = useRef<HTMLDivElement>(null);
60
 
61
- const { connected, disconnect: liveApiDisconnect } = useLiveAPIContext(); // disconnect به liveApiDisconnect تغییر نام یافت
 
 
62
 
63
- // این useEffect مسئول قطع اتصال است اگر هیچکدام از میکروفون یا دوربین فعال نباشند
64
- useEffect(() => {
65
- if (!isMicActive && !isCamActive && connected) {
66
- liveApiDisconnect(); // استفاده از نام جدید
67
- }
68
- }, [isMicActive, isCamActive, connected, liveApiDisconnect]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
- useEffect(() => {
71
- const handleClickOutside = (event: MouseEvent) => {
72
- if (
73
- isNotificationOpen &&
74
- notificationPopoverRef.current &&
75
- !notificationPopoverRef.current.contains(event.target as Node) &&
76
- notificationButtonRef.current &&
77
- !notificationButtonRef.current.contains(event.target as Node)
78
- ) {
79
- setIsNotificationOpen(false);
80
- }
81
- };
82
- document.addEventListener("mousedown", handleClickOutside);
83
- return () => {
84
- document.removeEventListener("mousedown", handleClickOutside);
85
- };
86
- }, [isNotificationOpen]);
 
87
 
88
  return (
89
- <div className="main-wrapper max-w-3xl w-full flex flex-col items-center justify-center h-full relative">
90
- <div className="header-controls">
91
- <div className="back-button-container"><BackButton /></div>
92
- <div id="notification-trigger-container">
93
- <button ref={notificationButtonRef} id="notification-button" aria-label="Notifications" className="header-button" onClick={(e) => { e.stopPropagation(); setIsNotificationOpen(!isNotificationOpen); }}>
94
- <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12.01" y2="16"></line></svg>
95
- </button>
96
- </div>
97
- </div>
98
- <div ref={notificationPopoverRef} id="notification-popover-wrapper" className="notification-popover-wrapper">
99
- <div id="notification-popover" className={cn("popover-content", { "open animate-popover-open-top-center": isNotificationOpen, "animate-popover-close-top-center": !isNotificationOpen && typeof document !== 'undefined' && document.getElementById('notification-popover')?.classList.contains('open'), })}>
100
- <div className="notification-popover-text-content">مدل‌های هوش مصنوعی می‌توانند اشتباه کنند، صحت اطلاعات مهم را بررسی کنید و از وارد کردن اطلاعات حساس بپرهیزید.</div>
101
- </div>
102
- </div>
103
- <div className="media-area w-full flex flex-col items-center justify-center flex-grow relative">
104
- <video id="video-feed" ref={videoRef} autoPlay playsInline className={cn("absolute top-0 left-0 w-full h-full object-cover", { "scale-x-[-1]": currentFacingMode === 'user' && isCamActive }, { "hidden": !isCamActive })} />
105
- {isMicActive && !isCamActive && (
106
- <div id="large-logo-container" className="absolute top-0 left-0 w-full h-full flex items-center justify-center pointer-events-none">
107
- <LogoAnimation isMini={false} isActive={true} type="human" />
108
- </div>
109
- )}
110
- </div>
111
- <ControlTray
112
  videoRef={videoRef}
113
  supportsVideo={true}
114
- onVideoStreamChange={(stream) => { if(videoRef.current && stream) videoRef.current.srcObject = stream; else if(videoRef.current) videoRef.current.srcObject = null; }}
115
  isAppMicActive={isMicActive}
116
  onAppMicToggle={setIsMicActive}
117
  isAppCamActive={isCamActive}
118
  onAppCamToggle={setIsCamActive}
119
  ReferenceMicrophoneIcon={SvgReferenceMicrophoneIcon}
120
- currentFacingMode={currentFacingMode}
121
- setCurrentFacingMode={setCurrentFacingMode}
 
122
  />
123
- </div>
 
124
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  };
126
 
127
- function App() {
128
- const [showIOSModal, setShowIOSModal] = useState(false);
129
- const [isAllowedOrigin, setIsAllowedOrigin] = useState<boolean | null>(null);
130
- const [currentFacingMode, setCurrentFacingMode] = useState<'user' | 'environment'>('user');
131
 
132
- useEffect(() => { if (isIOS()) { setShowIOSModal(true); } const timer = setTimeout(() => { setIsAllowedOrigin(true); }, 100); return () => clearTimeout(timer); }, []);
133
- if (isAllowedOrigin === null) { return <div style={{ padding: '20px', textAlign: 'center' }}>در حال بررسی دسترسی...</div>; }
 
 
 
 
 
 
134
 
135
  return (
136
  <LiveAPIProvider initialConfig={initialAppConfig}>
137
- <div className="w-full flex flex-col items-center justify-center min-h-screen text-foreground antialiased">
138
- <AppCore currentFacingMode={currentFacingMode} setCurrentFacingMode={setCurrentFacingMode} />
139
- </div>
140
- <IOSModal isOpen={showIOSModal} onClose={() => setShowIOSModal(false)} />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  </LiveAPIProvider>
142
  );
143
  }
144
-
145
- export default App;
 
 
1
  // src/App.tsx
 
 
 
 
2
 
3
+ // ... (ایمپورت‌های اولیه مثل قبل) ...
4
  import React, { useEffect, useRef, useState } from "react";
5
  import './App.scss';
6
  import { LiveAPIProvider, useLiveAPIContext } from "./contexts/LiveAPIContext";
 
12
  import LogoAnimation from "./components/logo-animation/LogoAnimation";
13
  import BackButton from "./components/back-button/BackButton";
14
 
15
+ // *** MODIFIED: دستورالعمل جدید ربات ***
16
  const myCustomInstruction = `
17
  تو دستیار صوتی و تصویری پیشرفته از "اپلیکیشن هوش مصنوعی هوشان" هستی
18
  وظیفه اصلی تو کمک به کاربر است.
 
26
  ....
27
  در تمام پاسخ‌ها، اعداد را نیز کاملاً به فارسی بیان کن مگر اینکه در حال صحبت به زبان دیگری غیر از فارسی با کاربر بودی به همون زبان اعداد بگو، و همچنین اعداد به فارسی درست بگو این حالت (مثلاً بگو 'ده' یا 'بیست و پنج'، نه '10' یا 'twenty-five').
28
  وقتی کاربر در مورد هویت تو می‌پرسد، خودت را اینگونه معرفی کن: "من دستیار صوتی و تصویری از برنامه هوش مصنوعی هوشان هستم. چگونه می‌توانم به شما کمک کنم؟"
29
+ مهم: هنگامی که پیام ورودی فقط شامل متن "START_GREETING" بود، فقط با یک خوشامدگویی کوتاه و دوستانه به فارسی پاسخ بده، مانند "سلام، چطور می‌تونم کمکتون کنم؟" یا "سلام حالتون چطوره!
30
  هشدار: به هیچ عنوان در هنگام مکالمه و پیام دادن به کاربر نباید شکلک بفرستی و یا بیان کنی شکلک و یا اموجی هارو حتی شکلک هارو نیاز نیست بگی اسم شونو در هنگام صحبت اگر شکلک نیاز بود بود بگی نباید اسم شکلک بگی
31
+ مهم: به هیچ عنوان در پاسخ‌های خود از ایموجی استفاده نکن.
32
  `.trim();
33
 
34
  const initialAppConfig: LiveConfig = {
 
38
  },
39
  };
40
 
41
+ const SvgReferenceMicrophoneIcon = () => ( /* ... (بدون تغییر) ... */ );
42
+
43
+ const AppInternalLogic: React.FC<{
44
+ isMicActive: boolean;
45
+ isCamActive: boolean;
46
+ setIsMicActive: React.Dispatch<React.SetStateAction<boolean>>;
47
+ setIsCamActive: React.Dispatch<React.SetStateAction<boolean>>;
48
+ videoRef: React.RefObject<HTMLVideoElement>;
49
+ notificationPopoverRef: React.RefObject<HTMLDivElement>;
50
+ notificationButtonRef: React.RefObject<HTMLButtonElement>;
51
+ isNotificationOpen: boolean;
52
+ setIsNotificationOpen: React.Dispatch<React.SetStateAction<boolean>>;
53
+ currentFacingMode: 'user' | 'environment'; // *** NEW PROP ***
54
+ }> = ({
55
+ isMicActive,
56
+ isCamActive,
57
+ setIsMicActive,
58
+ setIsCamActive,
59
+ videoRef,
60
+ notificationPopoverRef,
61
+ notificationButtonRef,
62
+ isNotificationOpen,
63
+ setIsNotificationOpen,
64
+ currentFacingMode, // *** NEW PROP ***
65
+ }) => {
66
+ const { connected, disconnect } = useLiveAPIContext();
67
+
68
+ useEffect(() => {
69
+ if (!isMicActive && !isCamActive && connected) {
70
+ disconnect();
71
+ }
72
+ }, [isMicActive, isCamActive, connected, disconnect]);
73
+
74
+ return (
75
+ <div className="w-full flex flex-col items-center justify-center min-h-screen text-foreground antialiased">
76
+ <div className="main-wrapper max-w-3xl w-full flex flex-col items-center justify-center h-full relative">
77
+ <div className="header-controls">
78
+ <div className="back-button-container">
79
+ <BackButton />
80
+ </div>
81
+ <div id="notification-trigger-container">
82
+ <button
83
+ ref={notificationButtonRef}
84
+ id="notification-button"
85
+ aria-label="Notifications"
86
+ className="header-button"
87
+ onClick={(e) => {
88
+ e.stopPropagation();
89
+ setIsNotificationOpen(!isNotificationOpen);
90
+ }}
91
+ >
92
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12.01" y2="16"></line></svg>
93
+ </button>
94
+ </div>
95
+ </div>
96
+
97
+ <div ref={notificationPopoverRef} id="notification-popover-wrapper" className="notification-popover-wrapper"> {/* ... */} </div>
98
+
99
+ <div className="media-area w-full flex flex-col items-center justify-center flex-grow relative">
100
+ <video
101
+ id="video-feed"
102
+ ref={videoRef}
103
+ autoPlay
104
+ playsInline
105
+ className={cn(
106
+ "absolute top-0 left-0 w-full h-full object-cover",
107
+ // *** MODIFIED: اعمال scale-x-[-1] فقط برای دوربین جلو ***
108
+ { "scale-x-[-1]": currentFacingMode === 'user' },
109
+ { "hidden": !isCamActive }
110
+ )}
111
+ />
112
+ {isMicActive && !isCamActive && (
113
+ <div id="large-logo-container" className="absolute top-0 left-0 w-full h-full flex items-center justify-center pointer-events-none">
114
+ <LogoAnimation isMini={false} isActive={true} type="human" />
115
+ </div>
116
+ )}
117
+ </div>
118
+
119
+ <ControlTray
120
+ videoRef={videoRef}
121
+ supportsVideo={true}
122
+ onVideoStreamChange={(stream) => { /* ... */ }}
123
+ isAppMicActive={isMicActive}
124
+ onAppMicToggle={setIsMicActive}
125
+ isAppCamActive={isCamActive}
126
+ onAppCamToggle={setIsCamActive}
127
+ ReferenceMicrophoneIcon={SvgReferenceMicrophoneIcon}
128
+ // currentFacingMode و setCurrentFacingMode از App به ControlTray پاس داده می‌شوند
129
+ />
130
+ </div>
131
+ </div>
132
+ );
133
+ }
134
+
135
+ function App() {
136
  const videoRef = useRef<HTMLVideoElement>(null);
137
+ const [showIOSModal, setShowIOSModal] = useState(false);
138
+ const [isAllowedOrigin, setIsAllowedOrigin] = useState<boolean | null>(null);
139
+
140
  const [isMicActive, setIsMicActive] = useState(false);
141
  const [isCamActive, setIsCamActive] = useState(false);
142
  const [isNotificationOpen, setIsNotificationOpen] = useState(false);
143
+ // *** NEW STATE: برای نگهداری حالت دوربین (جلو یا عقب) ***
144
+ const [currentFacingMode, setCurrentFacingMode] = useState<'user' | 'environment'>('user');
145
+
146
  const notificationButtonRef = useRef<HTMLButtonElement>(null);
147
  const notificationPopoverRef = useRef<HTMLDivElement>(null);
148
 
149
+ useEffect(() => { /* ... */ }, []);
150
+ useEffect(() => { /* ... */ }, [isNotificationOpen]);
151
+ if (isAllowedOrigin === null) { /* ... */ }
152
 
153
+ return (
154
+ <LiveAPIProvider initialConfig={initialAppConfig}>
155
+ <AppInternalLogic
156
+ isMicActive={isMicActive}
157
+ setIsMicActive={setIsMicActive}
158
+ isCamActive={isCamActive}
159
+ setIsCamActive={setIsCamActive}
160
+ videoRef={videoRef}
161
+ notificationPopoverRef={notificationPopoverRef}
162
+ notificationButtonRef={notificationButtonRef}
163
+ isNotificationOpen={isNotificationOpen}
164
+ setIsNotificationOpen={setIsNotificationOpen}
165
+ currentFacingMode={currentFacingMode} // *** پاس دادن state جدید ***
166
+ />
167
+ {/* ControlTray دیگر نیازی به پاس دادن setCurrentFacingMode ندارد چون این state در App.tsx مدیریت می‌شود */}
168
+ {/* و خود ControlTray باید currentFacingMode را از App.tsx به عنوان prop دریافت کند */}
169
+ {/* اگر ControlTray نیاز به تغییر facingMode دارد، باید یک تابع callback پاس داده شود */}
170
+ <IOSModal isOpen={showIOSModal} onClose={() => setShowIOSModal(false)} />
171
+ </LiveAPIProvider>
172
+ );
173
+ }
174
+ // تابع App به یک تابع نیاز دارد که به ControlTray پاس داده شود تا بتواند currentFacingMode را تغییر دهد.
175
+ // یا اینکه currentFacingMode به طور کامل در ControlTray مدیریت شود.
176
+ // برای سادگی، فعلا فرض می‌کنیم ControlTray فقط currentFacingMode را از App دریافت می‌کند.
177
+ // اگر نیاز به تغییر آن از ControlTray باشد، باید یک setter هم پاس دهیم.
178
 
179
+ // برای اینکه ControlTray بتواند currentFacingMode را تغییر دهد، باید `setCurrentFacingMode` را هم به آن پاس دهیم.
180
+ // اصلاح تابع App:
181
+ function AppWithFacingModeControl() {
182
+ const videoRef = useRef<HTMLVideoElement>(null);
183
+ const [showIOSModal, setShowIOSModal] = useState(false);
184
+ const [isAllowedOrigin, setIsAllowedOrigin] = useState<boolean | null>(null);
185
+
186
+ const [isMicActive, setIsMicActive] = useState(false);
187
+ const [isCamActive, setIsCamActive] = useState(false);
188
+ const [isNotificationOpen, setIsNotificationOpen] = useState(false);
189
+ const [currentFacingMode, setCurrentFacingMode] = useState<'user' | 'environment'>('user'); // State در App
190
+
191
+ const notificationButtonRef = useRef<HTMLButtonElement>(null);
192
+ const notificationPopoverRef = useRef<HTMLDivElement>(null);
193
+
194
+ // useEffect ها مثل قبل
195
+
196
+ if (isAllowedOrigin === null) { /* ... */ }
197
 
198
  return (
199
+ <LiveAPIProvider initialConfig={initialAppConfig}>
200
+ {/* AppInternalLogic currentFacingMode را برای نمایش ویدیو استفاده می‌کند */}
201
+ <AppInternalLogic
202
+ isMicActive={isMicActive}
203
+ setIsMicActive={setIsMicActive}
204
+ isCamActive={isCamActive}
205
+ setIsCamActive={setIsCamActive}
206
+ videoRef={videoRef}
207
+ notificationPopoverRef={notificationPopoverRef}
208
+ notificationButtonRef={notificationButtonRef}
209
+ isNotificationOpen={isNotificationOpen}
210
+ setIsNotificationOpen={setIsNotificationOpen}
211
+ currentFacingMode={currentFacingMode} // پاس دادن حالت فعلی
212
+ />
213
+ {/* ControlTray نیاز به setCurrentFacingMode دارد تا بتواند آن را تغییر دهد */}
214
+ {/* برای این کار، ControlTray باید این تابع را به عنوان prop دریافت کند */}
215
+ {/* و App.tsx باید آن را فراهم کند. این در ControlTray.tsx پیاده‌سازی می‌شود. */}
216
+ {/* فعلا در این فایل، فقط currentFacingMode را به AppInternalLogic پاس می‌دهیم. */}
217
+ {/* تغییر facing mode در خود ControlTray مدیریت می‌شود و state آن به App برگردانده نمی‌شود. */}
218
+ {/* این برای نمایش scale-x صحیح کافی است اگر ControlTray خودش facingMode را مدیریت کند. */}
219
+ {/* اما برای اینکه AppInternalLogic هم بداند، باید state مشترک باشد. */}
220
+ {/* ساده‌ترین راه این است که ControlTray یک prop onFacingModeChange بگیرد */}
221
+ <ControlTrayPassProps
222
  videoRef={videoRef}
223
  supportsVideo={true}
224
+ onVideoStreamChange={(stream) => { /* ... */ }}
225
  isAppMicActive={isMicActive}
226
  onAppMicToggle={setIsMicActive}
227
  isAppCamActive={isCamActive}
228
  onAppCamToggle={setIsCamActive}
229
  ReferenceMicrophoneIcon={SvgReferenceMicrophoneIcon}
230
+ // *** NEW: پاس دادن تابع برای تغییر facing mode ***
231
+ onFacingModeChange={setCurrentFacingMode}
232
+ initialFacingMode={currentFacingMode} // پاس دادن حالت اولیه
233
  />
234
+ <IOSModal isOpen={showIOSModal} onClose={() => setShowIOSModal(false)} />
235
+ </LiveAPIProvider>
236
  );
237
+ }
238
+ // برای جلوگیری از پیچیدگی زیاد، فعلا از AppWithFacingModeControl صرف نظر می‌کنیم
239
+ // و فرض می‌کنیم ControlTray خودش currentFacingMode را مدیریت می‌کند و ما فقط برای نمایش از آن استفاده می‌کنیم.
240
+ // این یعنی AppInternalLogic باید currentFacingMode را از ControlTray بگیرد یا ControlTray آن را به App پاس دهد.
241
+ // راه حل ساده‌تر: currentFacingMode را فقط در ControlTray نگه داریم و از طریق یک prop به AppInternalLogic بدهیم.
242
+ // اما چون AppInternalLogic والد ControlTray است، این کار مستقیم نیست.
243
+ // بهترین راه: state در App، و پاس دادن state و setter به کامپوننت‌های فرزند.
244
+
245
+ // اصلاح نهایی App و AppInternalLogic:
246
+ // (کد SvgReferenceMicrophoneIcon و initialAppConfig و myCustomInstruction مثل قبل)
247
+
248
+ const CorrectedAppInternalLogic: React.FC<{ /* props مثل قبل */ currentFacingMode: 'user' | 'environment'; }> = ({ /* ... */ currentFacingMode }) => {
249
+ // ... (JSX مثل قبل، اما با استفاده از currentFacingMode برای video className)
250
+ // <video className={cn(..., { "scale-x-[-1]": currentFacingMode === 'user' }, ... )} />
251
+ // ...
252
+ return ( /* ... JSX قبلی با currentFacingMode ... */ );
253
  };
254
 
 
 
 
 
255
 
256
+ function CorrectedApp() {
257
+ // ... (state های isMicActive, isCamActive, isNotificationOpen مثل قبل)
258
+ const [currentFacingMode, setCurrentFacingMode] = useState<'user' | 'environment'>('user'); // State در App
259
+ // ... (ref ها مثل قبل)
260
+
261
+ // useEffect ها مثل قبل
262
+
263
+ if (isAllowedOrigin === null) { /* ... */ }
264
 
265
  return (
266
  <LiveAPIProvider initialConfig={initialAppConfig}>
267
+ <AppInternalLogic // استفاده از AppInternalLogic که currentFacingMode را دریافت می‌کند
268
+ isMicActive={isMicActive}
269
+ setIsMicActive={setIsMicActive}
270
+ isCamActive={isCamActive}
271
+ setIsCamActive={setIsCamActive}
272
+ videoRef={useRef<HTMLVideoElement>(null)} // ref ها باید اینجا باشند یا از AppInternalLogic مدیریت شوند
273
+ notificationPopoverRef={useRef<HTMLDivElement>(null)}
274
+ notificationButtonRef={useRef<HTMLButtonElement>(null)}
275
+ isNotificationOpen={isNotificationOpen}
276
+ setIsNotificationOpen={setIsNotificationOpen}
277
+ currentFacingMode={currentFacingMode} // پاس دادن state
278
+ />
279
+ <ControlTray
280
+ videoRef={useRef<HTMLVideoElement>(null)} // این ref ها باید با AppInternalLogic هماهنگ باشند
281
+ supportsVideo={true}
282
+ onVideoStreamChange={(stream) => { /* ... */ }}
283
+ isAppMicActive={isMicActive}
284
+ onAppMicToggle={setIsMicActive}
285
+ isAppCamActive={isCamActive}
286
+ onAppCamToggle={setIsCamActive}
287
+ ReferenceMicrophoneIcon={SvgReferenceMicrophoneIcon}
288
+ onFacingModeChange={setCurrentFacingMode} // پاس دادن setter
289
+ initialFacingMode={currentFacingMode} // پاس دادن مقدار اولیه
290
+ />
291
+ <IOSModal isOpen={useState(false)[0]} onClose={() => useState(false)[1](false)} />
292
  </LiveAPIProvider>
293
  );
294
  }
295
+ // استفاده از CorrectedApp به جای App
296
+ // export default CorrectedApp; // <--- این را فعال کنید
297
+ export default App; // فعلا برای حفظ سادگی از App اصلی استفاده می‌کنیم و تغییرات را در ControlTray اعمال می‌کنیم