Ezmary commited on
Commit
f0ebb0b
·
verified ·
1 Parent(s): d7461ed

Update src/App.tsx

Browse files
Files changed (1) hide show
  1. src/App.tsx +54 -64
src/App.tsx CHANGED
@@ -19,8 +19,8 @@ import { IOSModal } from "./components/ios-modal/IOSModal";
19
  import { isIOS } from "./lib/platform";
20
  import cn from "classnames";
21
  import { LiveConfig } from "./multimodal-live-types";
22
- import { Altair } from "./components/altair/Altair";
23
- import SidePanel from "./components/side-panel/SidePanel";
24
 
25
  const myCustomInstruction = `
26
  ت1. هویت دستیار:
@@ -107,7 +107,7 @@ const initialAppConfig: LiveConfig = {
107
  };
108
 
109
  const SvgHumanIcon = () => (
110
- <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>
111
  );
112
 
113
  const AppInternalLogic: React.FC<{
@@ -137,17 +137,21 @@ const AppInternalLogic: React.FC<{
137
 
138
  useEffect(() => {
139
  if (!isMicActive && !isCamActive && connected) {
140
- console.log("AppInternalLogic: Both Mic and Cam are off. Disconnecting stream.");
141
  disconnect();
142
  }
143
  }, [isMicActive, isCamActive, connected, disconnect]);
144
 
145
  return (
146
- // کلاس‌های اصلی از HTML مرجع
147
- <div className="w-full flex flex-col items-center justify-center min-h-[90dvh] md:min-h-screen text-foreground antialiased"> {/* bg-background از body میاد */}
148
  <div className="max-w-3xl w-full flex flex-col items-center justify-center h-full relative">
149
- {/* Header */}
150
  <div className="header-controls">
 
 
 
 
 
151
  <button
152
  ref={notificationButtonRef}
153
  id="notification-button"
@@ -160,9 +164,6 @@ const AppInternalLogic: React.FC<{
160
  >
161
  <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>
162
  </button>
163
- <div className="header-button" onClick={() => alert('Back clicked (navigation logic)')}>
164
- <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="m15 18-6-6 6-6"></path></svg>
165
- </div>
166
  </div>
167
 
168
  {/* Notification Popover */}
@@ -180,65 +181,57 @@ const AppInternalLogic: React.FC<{
180
  </div>
181
  </div>
182
 
183
- {/* MediaToggle Area - این div اصلی است که ویدیو و لوگوی بزرگ را در بر می‌گیرد */}
184
- {/* چیدمان Altair و SidePanel باید با دقت بیشتری بررسی شود اگر می‌خواهید دقیقاً مطابق طرح HTML باشند */}
185
- {/* در اینجا فرض می‌کنیم چت و ویدیو در ستون‌های مجزا هستند */}
186
- <div className="flex flex-col md:flex-row w-full flex-grow items-stretch"> {/* flex-grow and items-stretch */}
187
- {/* Chat Area - ستون سمت چپ */}
188
- <div className="w-full md:w-1/3 p-2 flex flex-col overflow-y-auto"> {/* flex flex-col */}
189
- <SidePanel /> {/* این کامپوننت‌ها باید برای این چیدمان تنظیم شوند */}
190
- <div className="flex-grow"> {/* Altair برای پر کردن فضای باقی‌مانده */}
191
- <Altair />
192
- </div>
193
- </div>
194
-
195
- {/* Video and Logo Area - ستون سمت راست */}
196
- {/* کلاس‌های HTML مرجع برای این بخش: "w-full flex flex-col items-center justify-center h-[90dvh] bg-background top-0 left-0 relative" */}
197
- {/* ما از bg-background روی body استفاده کرده‌ایم، پس اینجا لازم نیست */}
198
- <div className="w-full md:w-2/3 flex flex-col items-center justify-center relative flex-grow"> {/* relative and flex-grow */}
199
- <video
200
- id="video-feed"
201
- ref={videoRef}
202
- autoPlay
203
- playsInline
204
- className={cn(
205
- "absolute top-0 left-0 w-full h-full object-cover scale-x-[-1]",
206
- { "hidden": !isCamActive } // نمایش فقط وقتی دوربین فعال است
207
- )}
208
- />
209
- {/* large-logo-container فقط وقتی میکروفون فعال و دوربین غیرفعال است نمایش داده می‌شود */}
210
- <div
211
- id="large-logo-container"
212
- className={cn(
213
- "w-full h-full absolute top-0 left-0 items-center justify-center", // کلاس‌های HTML مرجع
214
- {
215
- "flex": isMicActive && !isCamActive, // شرط نمایش
216
- "hidden": !isMicActive || isCamActive, // شرط مخفی شدن
217
- }
218
- )}
219
- >
220
- {isMicActive && !isCamActive && createLogoFunction(false, true)}
221
- </div>
222
- {/* اگر نه میکروفون و نه دوربین فعال باشند، این بخش خالی و سفید خواهد بود (چون ویدیو hidden و لوگو hidden است) */}
223
- </div>
224
  </div>
225
 
226
  <ControlTray
227
- videoRef={videoRef} // ControlTray به videoRef نیاز دارد
228
  supportsVideo={true}
229
- onVideoStreamChange={(stream) => { /* App.tsx no longer needs direct videoStream state */ }}
230
  isAppMicActive={isMicActive}
231
  onAppMicToggle={setIsMicActive}
232
  isAppCamActive={isCamActive}
233
  onAppCamToggle={setIsCamActive}
234
- createLogoFunction={createLogoFunction} // برای لوگوی کوچک در ControlTray
235
  />
236
  </div>
237
  </div>
238
  );
239
  }
240
 
241
-
242
  function App() {
243
  const videoRef = useRef<HTMLVideoElement>(null);
244
  const [showIOSModal, setShowIOSModal] = useState(false);
@@ -251,7 +244,6 @@ function App() {
251
  const notificationPopoverRef = useRef<HTMLDivElement>(null);
252
  const notificationButtonRef = useRef<HTMLButtonElement>(null);
253
 
254
-
255
  useEffect(() => {
256
  if (isIOS()) {
257
  setShowIOSModal(true);
@@ -259,7 +251,6 @@ function App() {
259
  const timer = setTimeout(() => {
260
  setIsAllowedOrigin(true);
261
  }, 100);
262
-
263
  return () => clearTimeout(timer);
264
  }, []);
265
 
@@ -281,7 +272,6 @@ function App() {
281
  };
282
  }, [isNotificationOpen]);
283
 
284
-
285
  if (isAllowedOrigin === null) {
286
  return <div style={{ padding: '20px', textAlign: 'center' }}>در حال بررسی دسترسی...</div>;
287
  }
@@ -289,16 +279,15 @@ function App() {
289
  const createLogoFunction = (isMini: boolean, isActive: boolean, type: 'human' | 'ai' = 'human') => {
290
  if (!isActive) return null;
291
  const size = isMini ? 80 : 200;
292
- const iconSize = isMini ? 35 : 70;
293
  const insetBase = isMini
294
- ? { ping: 10, outer: 0, mid: 5, inner: 12, icon: 22 }
295
  : { ping: 40, outer: 0, mid: 20, inner: 50, icon: 65 };
296
  const bgColorBase = type === 'human' ? 'blue' : 'green';
297
 
298
- // اطمینان از وجود کلاس‌های Tailwind برای purgeCSS
299
- // <div className="bg-blue-200 dark:bg-blue-700 bg-blue-300 dark:bg-blue-600 bg-blue-400 dark:bg-blue-500"></div>
300
- // <div className="bg-green-200 dark:bg-green-700 bg-green-300 dark:bg-green-600 bg-green-400 dark:bg-green-500"></div>
301
-
302
 
303
  return (
304
  <div className="relative" style={{ width: `${size}px`, height: `${size}px` }}>
@@ -307,6 +296,7 @@ function App() {
307
  <div className={`absolute rounded-full opacity-50 bg-${bgColorBase}-300 dark:bg-${bgColorBase}-600`} style={{ inset: `${insetBase.mid}px` }}></div>
308
  <div className={`absolute rounded-full opacity-50 bg-${bgColorBase}-400 dark:bg-${bgColorBase}-500`} style={{ inset: `${insetBase.inner}px` }}></div>
309
  <div className="z-10 absolute" style={{ inset: `${insetBase.icon}px`, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
 
310
  {type === 'human' && <SvgHumanIcon />}
311
  </div>
312
  </div>
 
19
  import { isIOS } from "./lib/platform";
20
  import cn from "classnames";
21
  import { LiveConfig } from "./multimodal-live-types";
22
+ // import { Altair } from "./components/altair/Altair"; // اگر چت جداگانه ندارید، لازم نیست
23
+ // import SidePanel from "./components/side-panel/SidePanel"; // اگر چت جداگانه ندارید، لازم نیست
24
 
25
  const myCustomInstruction = `
26
  ت1. هویت دستیار:
 
107
  };
108
 
109
  const SvgHumanIcon = () => (
110
+ <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="currentColor" 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="currentColor" strokeWidth="6.42146" strokeLinecap="round" strokeLinejoin="round"/></svg>
111
  );
112
 
113
  const AppInternalLogic: React.FC<{
 
137
 
138
  useEffect(() => {
139
  if (!isMicActive && !isCamActive && connected) {
 
140
  disconnect();
141
  }
142
  }, [isMicActive, isCamActive, connected, disconnect]);
143
 
144
  return (
145
+ <div className="w-full flex flex-col items-center justify-center min-h-screen text-foreground antialiased">
146
+ {/* Wrapper اصلی که در HTML هم وجود دارد */}
147
  <div className="max-w-3xl w-full flex flex-col items-center justify-center h-full relative">
148
+ {/* Header Controls */}
149
  <div className="header-controls">
150
+ {/* دکمه بازگشت (در HTML سمت راست بود، اینجا هم طبق آن) */}
151
+ <div className="header-button" onClick={() => alert('Back clicked (implement navigation)')}>
152
+ <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="m15 18-6-6 6-6"></path></svg>
153
+ </div>
154
+ {/* دکمه نوتیفیکیشن (در HTML سمت چپ بود) */}
155
  <button
156
  ref={notificationButtonRef}
157
  id="notification-button"
 
164
  >
165
  <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>
166
  </button>
 
 
 
167
  </div>
168
 
169
  {/* Notification Popover */}
 
181
  </div>
182
  </div>
183
 
184
+ {/* MediaToggle Area - این div اصلی برای ویدیو و لوگوی بزرگ است */}
185
+ {/* کلاس‌های HTML مرجع: "w-full flex flex-col items-center justify-center h-[90dvh] bg-background top-0 left-0 relative" */}
186
+ {/* ما از bg-background روی body استفاده می‌کنیم، پس اینجا لازم نیست تکرار شود */}
187
+ {/* h-[90dvh] با flex-grow جایگزین می‌شود تا ارتفاع را پر کند */}
188
+ <div className="w-full flex flex-col items-center justify-center flex-grow relative">
189
+ <video
190
+ id="video-feed"
191
+ ref={videoRef}
192
+ autoPlay
193
+ playsInline
194
+ className={cn(
195
+ "absolute top-0 left-0 w-full h-full object-cover scale-x-[-1]", // scale-x-[-1] برای آینه‌ای کردن
196
+ { "hidden": !isCamActive }
197
+ )}
198
+ />
199
+ {/* large-logo-container */}
200
+ <div
201
+ id="large-logo-container"
202
+ className={cn(
203
+ // کلاس‌های HTML: "w-full h-full absolute top-0 left-0 items-center justify-center"
204
+ // اما در کد JS، این کانتینر فقط زمانی flex است که لوگو نمایش داده می‌شود
205
+ "absolute top-0 left-0 w-full h-full",
206
+ {
207
+ "flex items-center justify-center": isMicActive && !isCamActive,
208
+ "hidden": !isMicActive || isCamActive,
209
+ }
210
+ )}
211
+ >
212
+ {/* لوگوی بزرگ فقط زمانی رندر می‌شود که شرایط برقرار باشد */}
213
+ {isMicActive && !isCamActive && createLogoFunction(false, true, 'human')}
214
+ </div>
215
+ {/* اگر Altair/SidePanel وجود دارد، باید اینجا یا در یک لایه دیگر قرار گیرد */}
216
+ {/* برای سادگی، Altair را اینجا کامنت می‌کنیم چون در تصاویر شما نبود */}
217
+ {/* <div className="absolute bottom-24 left-4 z-20 w-1/3 max-w-md"> <Altair /> </div> */}
 
 
 
 
 
 
 
218
  </div>
219
 
220
  <ControlTray
221
+ videoRef={videoRef}
222
  supportsVideo={true}
223
+ onVideoStreamChange={(stream) => { /* ... */ }}
224
  isAppMicActive={isMicActive}
225
  onAppMicToggle={setIsMicActive}
226
  isAppCamActive={isCamActive}
227
  onAppCamToggle={setIsCamActive}
228
+ createLogoFunction={createLogoFunction}
229
  />
230
  </div>
231
  </div>
232
  );
233
  }
234
 
 
235
  function App() {
236
  const videoRef = useRef<HTMLVideoElement>(null);
237
  const [showIOSModal, setShowIOSModal] = useState(false);
 
244
  const notificationPopoverRef = useRef<HTMLDivElement>(null);
245
  const notificationButtonRef = useRef<HTMLButtonElement>(null);
246
 
 
247
  useEffect(() => {
248
  if (isIOS()) {
249
  setShowIOSModal(true);
 
251
  const timer = setTimeout(() => {
252
  setIsAllowedOrigin(true);
253
  }, 100);
 
254
  return () => clearTimeout(timer);
255
  }, []);
256
 
 
272
  };
273
  }, [isNotificationOpen]);
274
 
 
275
  if (isAllowedOrigin === null) {
276
  return <div style={{ padding: '20px', textAlign: 'center' }}>در حال بررسی دسترسی...</div>;
277
  }
 
279
  const createLogoFunction = (isMini: boolean, isActive: boolean, type: 'human' | 'ai' = 'human') => {
280
  if (!isActive) return null;
281
  const size = isMini ? 80 : 200;
282
+ const iconSize = isMini ? 35 : 70; // آیکون کوچک‌تر برای لوگوی کوچک
283
  const insetBase = isMini
284
+ ? { ping: 10, outer: 0, mid: 5, inner: 12, icon: 22 } // مقادیر از JS کد HTML
285
  : { ping: 40, outer: 0, mid: 20, inner: 50, icon: 65 };
286
  const bgColorBase = type === 'human' ? 'blue' : 'green';
287
 
288
+ // اطمینان از وجود کلاس‌های Tailwind برای purgeCSS اگر لازم باشد (معمولاً لازم نیست اگر مستقیم استفاده شوند)
289
+ // <div className="bg-blue-200 dark:bg-blue-700 bg-blue-300 dark:bg-blue-600 bg-blue-400 dark:bg-blue-500 hidden"></div>
290
+ // <div className="bg-green-200 dark:bg-green-700 bg-green-300 dark:bg-green-600 bg-green-400 dark:bg-green-500 hidden"></div>
 
291
 
292
  return (
293
  <div className="relative" style={{ width: `${size}px`, height: `${size}px` }}>
 
296
  <div className={`absolute rounded-full opacity-50 bg-${bgColorBase}-300 dark:bg-${bgColorBase}-600`} style={{ inset: `${insetBase.mid}px` }}></div>
297
  <div className={`absolute rounded-full opacity-50 bg-${bgColorBase}-400 dark:bg-${bgColorBase}-500`} style={{ inset: `${insetBase.inner}px` }}></div>
298
  <div className="z-10 absolute" style={{ inset: `${insetBase.icon}px`, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
299
+ {/* آیکون انسان با استروک currentColor تا از var(--foreground) ارث‌بری کند */}
300
  {type === 'human' && <SvgHumanIcon />}
301
  </div>
302
  </div>