Ezmary commited on
Commit
6e84dc8
·
verified ·
1 Parent(s): db1de23

Update src/App.tsx

Browse files
Files changed (1) hide show
  1. src/App.tsx +44 -161
src/App.tsx CHANGED
@@ -1,4 +1,4 @@
1
- // ... (ایمپورت‌ها، myCustomInstruction, initialAppConfig, SvgHumanIcon, SvgReferenceMicrophoneIcon بدون تغییر) ...
2
  import React, { useEffect, useRef, useState } from "react";
3
  import './App.scss';
4
  import { LiveAPIProvider, useLiveAPIContext } from "./contexts/LiveAPIContext";
@@ -92,7 +92,6 @@ const initialAppConfig: LiveConfig = {
92
  },
93
  };
94
 
95
-
96
  const SvgHumanIcon = () => (
97
  <svg width="100%" height="100%" viewBox="0 0 88 89" fill="none" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid meet">
98
  <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"/>
@@ -107,186 +106,76 @@ const SvgReferenceMicrophoneIcon = () => (
107
  </svg>
108
  );
109
 
110
- // ... (AppInternalLogic بدون تغییر) ...
111
- const AppInternalLogic: React.FC<{
112
- isMicActive: boolean;
113
- isCamActive: boolean;
114
- setIsMicActive: React.Dispatch<React.SetStateAction<boolean>>;
115
- setIsCamActive: React.Dispatch<React.SetStateAction<boolean>>;
116
- createLogoFunction: (isMini: boolean, isActive: boolean, type?: 'human' | 'ai', forFooter?: boolean) => React.ReactNode;
117
- videoRef: React.RefObject<HTMLVideoElement>;
118
- notificationPopoverRef: React.RefObject<HTMLDivElement>;
119
- notificationButtonRef: React.RefObject<HTMLButtonElement>;
120
- isNotificationOpen: boolean;
121
- setIsNotificationOpen: React.Dispatch<React.SetStateAction<boolean>>;
122
- }> = ({
123
- isMicActive,
124
- isCamActive,
125
- setIsMicActive,
126
- setIsCamActive,
127
- createLogoFunction,
128
- videoRef,
129
- notificationPopoverRef,
130
- notificationButtonRef,
131
- isNotificationOpen,
132
- setIsNotificationOpen
133
  }) => {
134
  const { connected, disconnect } = useLiveAPIContext();
135
-
136
- useEffect(() => {
137
- if (!isMicActive && !isCamActive && connected) {
138
- disconnect();
139
- }
140
- }, [isMicActive, isCamActive, connected, disconnect]);
141
 
142
  return (
143
  <div className="w-full flex flex-col items-center justify-center min-h-screen text-foreground antialiased">
144
  <div className="main-wrapper max-w-3xl w-full flex flex-col items-center justify-center h-full relative">
 
145
  <div className="header-controls">
146
  <div id="notification-trigger-container">
147
- <button
148
- ref={notificationButtonRef}
149
- id="notification-button"
150
- aria-label="Notifications"
151
- className="header-button"
152
- onClick={(e) => {
153
- e.stopPropagation();
154
- setIsNotificationOpen(!isNotificationOpen);
155
- }}
156
- >
157
  <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>
158
  </button>
159
  </div>
160
  <div className="back-button-container">
161
- <button
162
- id="back-button"
163
- aria-label="Go back"
164
- className="header-button"
165
- onClick={() => alert('Back clicked (implement navigation)')}
166
- >
167
  <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"><path d="m15 18-6-6 6-6"></path></svg>
168
  </button>
169
  </div>
170
  </div>
171
-
172
  <div ref={notificationPopoverRef} id="notification-popover-wrapper" className="notification-popover-wrapper">
173
- <div
174
- id="notification-popover"
175
- className={cn("popover-content", {
176
- "open animate-popover-open-top-center": isNotificationOpen,
177
- "animate-popover-close-top-center": !isNotificationOpen && document.getElementById('notification-popover')?.classList.contains('open'),
178
- })}
179
- >
180
- <div className="notification-popover-text-content">
181
- مدل‌های هوش مصنوعی می‌توانند اشتباه کنند، صحت اطلاعات مهم را بررسی کنید و از وارد کردن اطلاعات حساس بپرهیزید.
182
- </div>
183
  </div>
184
  </div>
185
 
186
  <div className="media-area w-full flex flex-col items-center justify-center flex-grow relative">
187
- <video
188
- id="video-feed"
189
- ref={videoRef}
190
- autoPlay
191
- playsInline
192
- className={cn(
193
- "absolute top-0 left-0 w-full h-full object-cover scale-x-[-1]",
194
- { "hidden": !isCamActive }
195
- )}
196
- />
197
  {isMicActive && !isCamActive && (
198
- <div
199
- id="large-logo-container"
200
- className="absolute top-0 left-0 w-full h-full flex items-center justify-center pointer-events-none"
201
- >
202
  {createLogoFunction(false, true, 'human', false)}
203
  </div>
204
  )}
205
  </div>
206
-
207
- <ControlTray
208
- videoRef={videoRef}
209
- supportsVideo={true}
210
- onVideoStreamChange={(stream) => { /* ... */ }}
211
- isAppMicActive={isMicActive}
212
- onAppMicToggle={setIsMicActive}
213
- isAppCamActive={isCamActive}
214
- onAppCamToggle={setIsCamActive}
215
  createLogoFunction={createLogoFunction}
216
  ReferenceMicrophoneIcon={SvgReferenceMicrophoneIcon}
217
  />
218
  </div>
219
  </div>
220
  );
221
- }
222
-
223
 
224
- const logoColorConfig = {
225
- blue: {
226
- ping: "bg-blue-200 dark:bg-blue-700",
227
- outer: "bg-blue-200 dark:bg-blue-700",
228
- mid: "bg-blue-300 dark:bg-blue-600",
229
- inner: "bg-blue-400 dark:bg-blue-500",
230
- },
231
- green: {
232
- ping: "bg-green-200 dark:bg-green-700",
233
- outer: "bg-green-200 dark:bg-green-700",
234
- mid: "bg-green-300 dark:bg-green-600",
235
- inner: "bg-green-400 dark:bg-green-500",
236
- },
237
- gray: {
238
- ping: "bg-gray-200 dark:bg-gray-700",
239
- outer: "bg-gray-200 dark:bg-gray-700",
240
- mid: "bg-gray-300 dark:bg-gray-600",
241
- inner: "bg-gray-400 dark:bg-gray-500",
242
- }
243
  };
244
 
245
- function App() {
246
  const videoRef = useRef<HTMLVideoElement>(null);
247
  const [showIOSModal, setShowIOSModal] = useState(false);
248
  const [isAllowedOrigin, setIsAllowedOrigin] = useState<boolean | null>(null);
249
-
250
  const [isMicActive, setIsMicActive] = useState(false);
251
  const [isCamActive, setIsCamActive] = useState(false);
252
  const [isNotificationOpen, setIsNotificationOpen] = useState(false);
253
-
254
  const notificationPopoverRef = useRef<HTMLDivElement>(null);
255
  const notificationButtonRef = useRef<HTMLButtonElement>(null);
 
 
 
256
 
257
- useEffect(() => {
258
- if (isIOS()) {
259
- setShowIOSModal(true);
260
- }
261
- const timer = setTimeout(() => {
262
- setIsAllowedOrigin(true);
263
- }, 100);
264
- return () => clearTimeout(timer);
265
- }, []);
266
-
267
- useEffect(() => {
268
- const handleClickOutside = (event: MouseEvent) => {
269
- if (
270
- isNotificationOpen &&
271
- notificationPopoverRef.current &&
272
- !notificationPopoverRef.current.contains(event.target as Node) &&
273
- notificationButtonRef.current &&
274
- !notificationButtonRef.current.contains(event.target as Node)
275
- ) {
276
- setIsNotificationOpen(false);
277
- }
278
- };
279
- document.addEventListener("mousedown", handleClickOutside);
280
- return () => {
281
- document.removeEventListener("mousedown", handleClickOutside);
282
- };
283
- }, [isNotificationOpen]);
284
-
285
- if (isAllowedOrigin === null) {
286
- return <div style={{ padding: '20px', textAlign: 'center' }}>در حال بررسی دسترسی...</div>;
287
- }
288
-
289
- // *** MODIFIED: createLogoFunction با دقت بیشتر در inset ها و رنگ ها ***
290
  const createLogoFunction = (isMini: boolean, isActive: boolean, type: 'human' | 'ai' = 'human', forFooter: boolean = false) => {
291
  if (!isActive) return null;
292
 
@@ -297,25 +186,23 @@ function App() {
297
  const iconDisplaySize = isMini ? 35 : 70;
298
  const iconInset = (size - iconDisplaySize) / 2;
299
 
300
- // مقادیر inset برای حلقه‌ها از HTML مرجع شما (با توجه به isMini)
301
- // این مقادیر باید دقیق باشند تا حلقه‌ها درست نمایش داده شوند.
302
- const pingInset = isMini ? 10 : 40;
303
- const outerInset = 0; // در HTML مرجع شما، outer ring معمولاً inset صفر دارد
304
- const midInset = isMini ? 5 : 20;
305
- const innerInset = isMini ? 12 : 50;
306
 
307
  const IconComponent = type === 'human' ? SvgHumanIcon : null;
308
 
309
  return (
 
310
  <div className={cn("logo-animation-wrapper", {"for-footer": forFooter})} style={{ width: `${size}px`, height: `${size}px` }}>
311
- {/* حلقه Ping (متحرک) */}
312
- <div className={`absolute rounded-full opacity-50 animate-ping ${currentColors.ping}`} style={{ inset: `${pingInset}px` }}></div>
313
- {/* حلقه بیرونی */}
314
- <div className={`absolute rounded-full opacity-50 ${currentColors.outer}`} style={{ inset: `${outerInset}px` }}></div>
315
- {/* حلقه میانی */}
316
- <div className={`absolute rounded-full opacity-50 ${currentColors.mid}`} style={{ inset: `${midInset}px` }}></div>
317
- {/* حلقه داخلی */}
318
- <div className={`absolute rounded-full opacity-50 ${currentColors.inner}`} style={{ inset: `${innerInset}px` }}></div>
319
  {/* کانتینر آیکون */}
320
  <div className="z-10 absolute flex items-center justify-center" style={{ inset: `${iconInset}px`, width: `${iconDisplaySize}px`, height: `${iconDisplaySize}px` }}>
321
  {IconComponent && <IconComponent />}
@@ -326,17 +213,13 @@ function App() {
326
 
327
  return (
328
  <LiveAPIProvider initialConfig={initialAppConfig}>
329
- <AppInternalLogic
330
- isMicActive={isMicActive}
331
- setIsMicActive={setIsMicActive}
332
- isCamActive={isCamActive}
333
- setIsCamActive={setIsCamActive}
334
  createLogoFunction={createLogoFunction}
335
  videoRef={videoRef}
336
- notificationPopoverRef={notificationPopoverRef}
337
- notificationButtonRef={notificationButtonRef}
338
- isNotificationOpen={isNotificationOpen}
339
- setIsNotificationOpen={setIsNotificationOpen}
340
  />
341
  <IOSModal isOpen={showIOSModal} onClose={() => setShowIOSModal(false)} />
342
  </LiveAPIProvider>
 
1
+ // ... (ایمپورت‌ها، myCustomInstruction, initialAppConfig, SvgHumanIcon, SvgReferenceMicrophoneIcon، AppInternalLogic بدون تغییر) ...
2
  import React, { useEffect, useRef, useState } from "react";
3
  import './App.scss';
4
  import { LiveAPIProvider, useLiveAPIContext } from "./contexts/LiveAPIContext";
 
92
  },
93
  };
94
 
 
95
  const SvgHumanIcon = () => (
96
  <svg width="100%" height="100%" viewBox="0 0 88 89" fill="none" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid meet">
97
  <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"/>
 
106
  </svg>
107
  );
108
 
109
+ const AppInternalLogic: React.FC<{ /* ...props... */ }> = ({ /* ...props... */
110
+ isMicActive, isCamActive, setIsMicActive, setIsCamActive, createLogoFunction,
111
+ videoRef, notificationPopoverRef, notificationButtonRef, isNotificationOpen, setIsNotificationOpen
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  }) => {
113
  const { connected, disconnect } = useLiveAPIContext();
114
+ useEffect(() => { if (!isMicActive && !isCamActive && connected) { disconnect(); } }, [isMicActive, isCamActive, connected, disconnect]);
 
 
 
 
 
115
 
116
  return (
117
  <div className="w-full flex flex-col items-center justify-center min-h-screen text-foreground antialiased">
118
  <div className="main-wrapper max-w-3xl w-full flex flex-col items-center justify-center h-full relative">
119
+ {/* Header and Popover ... */}
120
  <div className="header-controls">
121
  <div id="notification-trigger-container">
122
+ <button ref={notificationButtonRef} id="notification-button" aria-label="Notifications" className="header-button" onClick={(e) => { e.stopPropagation(); setIsNotificationOpen(!isNotificationOpen); }}>
 
 
 
 
 
 
 
 
 
123
  <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>
124
  </button>
125
  </div>
126
  <div className="back-button-container">
127
+ <button id="back-button" aria-label="Go back" className="header-button" onClick={() => alert('Back clicked (implement navigation)')}>
 
 
 
 
 
128
  <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"><path d="m15 18-6-6 6-6"></path></svg>
129
  </button>
130
  </div>
131
  </div>
 
132
  <div ref={notificationPopoverRef} id="notification-popover-wrapper" className="notification-popover-wrapper">
133
+ <div id="notification-popover" className={cn("popover-content", { "open animate-popover-open-top-center": isNotificationOpen, "animate-popover-close-top-center": !isNotificationOpen && document.getElementById('notification-popover')?.classList.contains('open'), })}>
134
+ <div className="notification-popover-text-content"> مدل‌های هوش مصنوعی می‌توانند اشتباه کنند، صحت اطلاعات مهم را بررسی کنید و از وارد کردن اطلاعات حساس بپرهیزید. </div>
 
 
 
 
 
 
 
 
135
  </div>
136
  </div>
137
 
138
  <div className="media-area w-full flex flex-col items-center justify-center flex-grow relative">
139
+ <video id="video-feed" ref={videoRef} autoPlay playsInline className={cn("absolute top-0 left-0 w-full h-full object-cover scale-x-[-1]", { "hidden": !isCamActive })} />
140
+ {/* *** MODIFIED: Ensure large logo is displayed correctly *** */}
 
 
 
 
 
 
 
 
141
  {isMicActive && !isCamActive && (
142
+ <div id="large-logo-container" className="large-logo-container-style">
 
 
 
143
  {createLogoFunction(false, true, 'human', false)}
144
  </div>
145
  )}
146
  </div>
147
+ <ControlTray /* ...props... */
148
+ videoRef={videoRef} supportsVideo={true} onVideoStreamChange={() => {}}
149
+ isAppMicActive={isMicActive} onAppMicToggle={setIsMicActive}
150
+ isAppCamActive={isCamActive} onAppCamToggle={setIsCamActive}
 
 
 
 
 
151
  createLogoFunction={createLogoFunction}
152
  ReferenceMicrophoneIcon={SvgReferenceMicrophoneIcon}
153
  />
154
  </div>
155
  </div>
156
  );
157
+ };
 
158
 
159
+ const logoColorConfig = { /* ... (بدون تغییر) ... */
160
+ blue: { ping: "bg-blue-200 dark:bg-blue-700", outer: "bg-blue-200 dark:bg-blue-700", mid: "bg-blue-300 dark:bg-blue-600", inner: "bg-blue-400 dark:bg-blue-500", },
161
+ green: { ping: "bg-green-200 dark:bg-green-700", outer: "bg-green-200 dark:bg-green-700", mid: "bg-green-300 dark:bg-green-600", inner: "bg-green-400 dark:bg-green-500", },
162
+ gray: { ping: "bg-gray-200 dark:bg-gray-700", outer: "bg-gray-200 dark:bg-gray-700", mid: "bg-gray-300 dark:bg-gray-600", inner: "bg-gray-400 dark:bg-gray-500", }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  };
164
 
165
+ function App() { /* ... (state ها و useEffect ها بدون تغییر) ... */
166
  const videoRef = useRef<HTMLVideoElement>(null);
167
  const [showIOSModal, setShowIOSModal] = useState(false);
168
  const [isAllowedOrigin, setIsAllowedOrigin] = useState<boolean | null>(null);
 
169
  const [isMicActive, setIsMicActive] = useState(false);
170
  const [isCamActive, setIsCamActive] = useState(false);
171
  const [isNotificationOpen, setIsNotificationOpen] = useState(false);
 
172
  const notificationPopoverRef = useRef<HTMLDivElement>(null);
173
  const notificationButtonRef = useRef<HTMLButtonElement>(null);
174
+ useEffect(() => { if (isIOS()) { setShowIOSModal(true); } const timer = setTimeout(() => { setIsAllowedOrigin(true); }, 100); return () => clearTimeout(timer); }, []);
175
+ useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if (isNotificationOpen && notificationPopoverRef.current && !notificationPopoverRef.current.contains(event.target as Node) && notificationButtonRef.current && !notificationButtonRef.current.contains(event.target as Node)) { setIsNotificationOpen(false); } }; document.addEventListener("mousedown", handleClickOutside); return () => { document.removeEventListener("mousedown", handleClickOutside); }; }, [isNotificationOpen]);
176
+ if (isAllowedOrigin === null) { return <div style={{ padding: '20px', textAlign: 'center' }}>در حال بررسی دسترسی...</div>; }
177
 
178
+ // *** MODIFIED createLogoFunction for complete animation ***
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  const createLogoFunction = (isMini: boolean, isActive: boolean, type: 'human' | 'ai' = 'human', forFooter: boolean = false) => {
180
  if (!isActive) return null;
181
 
 
186
  const iconDisplaySize = isMini ? 35 : 70;
187
  const iconInset = (size - iconDisplaySize) / 2;
188
 
189
+ // مقادیر inset برای حلقه‌ها از HTML مرجع شما (مهم)
190
+ // این مقادیر باید فاصله حلقه‌ها از لبه کانتینر اصلی لوگو باشند
191
+ const insetsForRings = isMini
192
+ ? { ping: 10, outer: 0, mid: 5, inner: 12 } // مقادیر HTML برای لوگوی کوچک
193
+ : { ping: 40, outer: 0, mid: 20, inner: 50 }; // مقادیر HTML برای لوگوی بزرگ
 
194
 
195
  const IconComponent = type === 'human' ? SvgHumanIcon : null;
196
 
197
  return (
198
+ // کلاس logo-animation-wrapper در App.scss استایل‌های position:relative و flex را دارد
199
  <div className={cn("logo-animation-wrapper", {"for-footer": forFooter})} style={{ width: `${size}px`, height: `${size}px` }}>
200
+ {/* حلقه‌های انیمیشن با inset های صحیح */}
201
+ <div className={`absolute rounded-full opacity-50 animate-ping ${currentColors.ping}`} style={{ inset: `${insetsForRings.ping}px` }}></div>
202
+ <div className={`absolute rounded-full opacity-50 ${currentColors.outer}`} style={{ inset: `${insetsForRings.outer}px` }}></div>
203
+ <div className={`absolute rounded-full opacity-50 ${currentColors.mid}`} style={{ inset: `${insetsForRings.mid}px` }}></div>
204
+ <div className={`absolute rounded-full opacity-50 ${currentColors.inner}`} style={{ inset: `${insetsForRings.inner}px` }}></div>
205
+
 
 
206
  {/* کانتینر آیکون */}
207
  <div className="z-10 absolute flex items-center justify-center" style={{ inset: `${iconInset}px`, width: `${iconDisplaySize}px`, height: `${iconDisplaySize}px` }}>
208
  {IconComponent && <IconComponent />}
 
213
 
214
  return (
215
  <LiveAPIProvider initialConfig={initialAppConfig}>
216
+ <AppInternalLogic /* ...props... */
217
+ isMicActive={isMicActive} setIsMicActive={setIsMicActive}
218
+ isCamActive={isCamActive} setIsCamActive={setIsCamActive}
 
 
219
  createLogoFunction={createLogoFunction}
220
  videoRef={videoRef}
221
+ notificationPopoverRef={notificationPopoverRef} notificationButtonRef={notificationButtonRef}
222
+ isNotificationOpen={isNotificationOpen} setIsNotificationOpen={setIsNotificationOpen}
 
 
223
  />
224
  <IOSModal isOpen={showIOSModal} onClose={() => setShowIOSModal(false)} />
225
  </LiveAPIProvider>