Ezmary commited on
Commit
d1e3e16
·
verified ·
1 Parent(s): d11eeb2

Update src/App.tsx

Browse files
Files changed (1) hide show
  1. src/App.tsx +29 -34
src/App.tsx CHANGED
@@ -1,14 +1,6 @@
1
  /**
2
  Copyright 2024 Google LLC
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- http://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
  */
13
 
14
  import React, { useEffect, useRef, useState } from "react";
@@ -20,6 +12,7 @@ import { isIOS } from "./lib/platform";
20
  import cn from "classnames";
21
  import { LiveConfig } from "./multimodal-live-types";
22
 
 
23
  const myCustomInstruction = `
24
  ت1. هویت دستیار:
25
 
@@ -111,11 +104,24 @@ const SvgHumanIcon = () => (
111
  </svg>
112
  );
113
 
114
- // SVG آیکون میکروفون اولیه (ساده‌تر)
115
- const SvgOriginalMicrophoneIcon = () => <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>;
116
-
 
 
 
 
 
 
 
 
 
 
 
 
 
117
 
118
- const AppInternalLogic: React.FC<{ /* ... (props بدون تغییر) ... */ }> = ({ /* ... (props بدون تغییر) ... */
119
  isMicActive,
120
  isCamActive,
121
  setIsMicActive,
@@ -127,7 +133,7 @@ const AppInternalLogic: React.FC<{ /* ... (props بدون تغییر) ... */ }>
127
  isNotificationOpen,
128
  setIsNotificationOpen
129
  }) => {
130
- // ... (useEffect ها بدون تغییر) ...
131
  const { connected, disconnect } = useLiveAPIContext();
132
 
133
  useEffect(() => {
@@ -139,7 +145,7 @@ const AppInternalLogic: React.FC<{ /* ... (props بدون تغییر) ... */ }>
139
  return (
140
  <div className="w-full flex flex-col items-center justify-center min-h-screen text-foreground antialiased">
141
  <div className="main-wrapper max-w-3xl w-full flex flex-col items-center justify-center h-full relative">
142
- <div className="header-controls"> {/* دکمه‌های نوتیفیکیشن و بازگشت */}
143
  <div id="notification-trigger-container">
144
  <button ref={notificationButtonRef} id="notification-button" aria-label="Notifications" className="header-button"
145
  onClick={(e) => { e.stopPropagation(); setIsNotificationOpen(!isNotificationOpen); }}>
@@ -153,23 +159,22 @@ const AppInternalLogic: React.FC<{ /* ... (props بدون تغییر) ... */ }>
153
  </div>
154
  </div>
155
 
156
- <div ref={notificationPopoverRef} id="notification-popover-wrapper" className="notification-popover-wrapper"> {/* پاپ‌اور نوتیفیکیشن */}
157
  <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'), })}>
158
  <div className="notification-popover-text-content">مدل‌های هوش مصنوعی می‌توانند اشتباه کنند، صحت اطلاعات مهم را بررسی کنید و از وارد کردن اطلاعات حساس بپرهیزید.</div>
159
  </div>
160
  </div>
161
 
162
- <div className="media-area w-full flex flex-col items-center justify-center flex-grow relative"> {/* منطقه نمایش ویدیو و لوگوی بزرگ */}
163
  <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 })} />
164
- {/* لوگوی بزرگ فقط زمانی که میکروفون فعال است و دوربین غیرفعال */}
165
  {isMicActive && !isCamActive && (
166
- <div className="large-logo-container-class"> {/* استفاده از کلاس جدید */}
167
  {createLogoFunction(false, true, 'human', false)}
168
  </div>
169
  )}
170
  </div>
171
 
172
- <ControlTray /* ... (props های ControlTray مثل قبل، اما با آیکون میکروفون اولیه) ... */
173
  videoRef={videoRef}
174
  supportsVideo={true}
175
  onVideoStreamChange={(stream) => { /* ... */ }}
@@ -178,23 +183,21 @@ const AppInternalLogic: React.FC<{ /* ... (props بدون تغییر) ... */ }>
178
  isAppCamActive={isCamActive}
179
  onAppCamToggle={setIsCamActive}
180
  createLogoFunction={createLogoFunction}
181
- ReferenceMicrophoneIcon={SvgOriginalMicrophoneIcon} // بازگشت به آیکون اولیه
182
  />
183
  </div>
184
  </div>
185
  );
186
  };
187
 
188
- // ... (logoColorConfig بدون تغییر) ...
189
  const logoColorConfig = {
190
  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", },
191
  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", },
192
  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", }
193
  };
194
 
195
-
196
  function App() {
197
- // ... (state ها و useEffect های دیگر بدون تغییر) ...
198
  const videoRef = useRef<HTMLVideoElement>(null);
199
  const [showIOSModal, setShowIOSModal] = useState(false);
200
  const [isAllowedOrigin, setIsAllowedOrigin] = useState<boolean | null>(null);
@@ -204,31 +207,23 @@ function App() {
204
  const notificationPopoverRef = useRef<HTMLDivElement>(null);
205
  const notificationButtonRef = useRef<HTMLButtonElement>(null);
206
 
207
- useEffect(() => { /* ... */ if (isIOS()) { setShowIOSModal(true); } const timer = setTimeout(() => { setIsAllowedOrigin(true); }, 100); return () => clearTimeout(timer); }, []);
208
- 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]);
209
  if (isAllowedOrigin === null) { return <div style={{ padding: '20px', textAlign: 'center' }}>در حال بررسی دسترسی...</div>; }
210
 
211
- // *** تابع createLogoFunction با دقت برای انیمیشن کامل ***
212
  const createLogoFunction = (isMini: boolean, isActive: boolean, type: 'human' | 'ai' = 'human', forFooter: boolean = false) => {
213
  if (!isActive) return null;
214
-
215
  const colorKey = type === 'human' ? 'blue' : 'gray';
216
  const currentColors = logoColorConfig[colorKey as keyof typeof logoColorConfig];
217
-
218
  const size = isMini ? 80 : 200;
219
  const iconDisplaySize = isMini ? 35 : 70;
220
  const iconInset = (size - iconDisplaySize) / 2;
221
-
222
- // مقادیر دقیق inset برای حلقه‌ها از HTML مرجع شما
223
  const baseInsets = isMini
224
  ? { ping: 10, outer: 0, mid: 5, inner: 12 }
225
  : { ping: 40, outer: 0, mid: 20, inner: 50 };
226
-
227
  const IconComponent = type === 'human' ? SvgHumanIcon : null;
228
-
229
  return (
230
  <div className={cn("logo-animation-wrapper", {"for-footer": forFooter})} style={{ width: `${size}px`, height: `${size}px` }}>
231
- {/* حلقه‌های انیمیشن با کلاس‌ها و استایل‌های صحیح */}
232
  <div className={`absolute rounded-full opacity-50 animate-ping ${currentColors.ping}`} style={{ inset: `${baseInsets.ping}px` }}></div>
233
  <div className={`absolute rounded-full opacity-50 ${currentColors.outer}`} style={{ inset: `${baseInsets.outer}px` }}></div>
234
  <div className={`absolute rounded-full opacity-50 ${currentColors.mid}`} style={{ inset: `${baseInsets.mid}px` }}></div>
 
1
  /**
2
  Copyright 2024 Google LLC
3
+ ... (لایسنس و توضیحات دیگر مثل قبل) ...
 
 
 
 
 
 
 
 
4
  */
5
 
6
  import React, { useEffect, useRef, useState } from "react";
 
12
  import cn from "classnames";
13
  import { LiveConfig } from "./multimodal-live-types";
14
 
15
+ // ... (myCustomInstruction, initialAppConfig, SvgHumanIcon, SvgOriginalMicrophoneIcon بدون تغییر) ...
16
  const myCustomInstruction = `
17
  ت1. هویت دستیار:
18
 
 
104
  </svg>
105
  );
106
 
107
+ const SvgOriginalMicrophoneIcon = () => <svg width="38" height="38" viewBox="0 0 69 68" fill="none" xmlns="http://www.w3.org/2000/svg" transform="scale(0.55)" className="reference-mic-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>;
108
+
109
+
110
+ // *** MODIFIED: تعریف دقیق تایپ پراپ‌ها برای AppInternalLogic ***
111
+ interface AppInternalLogicProps {
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
 
124
+ const AppInternalLogic: React.FC<AppInternalLogicProps> = ({
125
  isMicActive,
126
  isCamActive,
127
  setIsMicActive,
 
133
  isNotificationOpen,
134
  setIsNotificationOpen
135
  }) => {
136
+ // ... (منطق داخلی کامپوننت AppInternalLogic بدون تغییر) ...
137
  const { connected, disconnect } = useLiveAPIContext();
138
 
139
  useEffect(() => {
 
145
  return (
146
  <div className="w-full flex flex-col items-center justify-center min-h-screen text-foreground antialiased">
147
  <div className="main-wrapper max-w-3xl w-full flex flex-col items-center justify-center h-full relative">
148
+ <div className="header-controls">
149
  <div id="notification-trigger-container">
150
  <button ref={notificationButtonRef} id="notification-button" aria-label="Notifications" className="header-button"
151
  onClick={(e) => { e.stopPropagation(); setIsNotificationOpen(!isNotificationOpen); }}>
 
159
  </div>
160
  </div>
161
 
162
+ <div ref={notificationPopoverRef} id="notification-popover-wrapper" className="notification-popover-wrapper">
163
  <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'), })}>
164
  <div className="notification-popover-text-content">مدل‌های هوش مصنوعی می‌توانند اشتباه کنند، صحت اطلاعات مهم را بررسی کنید و از وارد کردن اطلاعات حساس بپرهیزید.</div>
165
  </div>
166
  </div>
167
 
168
+ <div className="media-area w-full flex flex-col items-center justify-center flex-grow relative">
169
  <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 })} />
 
170
  {isMicActive && !isCamActive && (
171
+ <div className="large-logo-container-class">
172
  {createLogoFunction(false, true, 'human', false)}
173
  </div>
174
  )}
175
  </div>
176
 
177
+ <ControlTray
178
  videoRef={videoRef}
179
  supportsVideo={true}
180
  onVideoStreamChange={(stream) => { /* ... */ }}
 
183
  isAppCamActive={isCamActive}
184
  onAppCamToggle={setIsCamActive}
185
  createLogoFunction={createLogoFunction}
186
+ ReferenceMicrophoneIcon={SvgOriginalMicrophoneIcon}
187
  />
188
  </div>
189
  </div>
190
  );
191
  };
192
 
193
+ // ... (logoColorConfig و تابع App و createLogoFunction بدون تغییر نسبت به پاسخ قبلی) ...
194
  const logoColorConfig = {
195
  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", },
196
  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", },
197
  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", }
198
  };
199
 
 
200
  function App() {
 
201
  const videoRef = useRef<HTMLVideoElement>(null);
202
  const [showIOSModal, setShowIOSModal] = useState(false);
203
  const [isAllowedOrigin, setIsAllowedOrigin] = useState<boolean | null>(null);
 
207
  const notificationPopoverRef = useRef<HTMLDivElement>(null);
208
  const notificationButtonRef = useRef<HTMLButtonElement>(null);
209
 
210
+ useEffect(() => { if (isIOS()) { setShowIOSModal(true); } const timer = setTimeout(() => { setIsAllowedOrigin(true); }, 100); return () => clearTimeout(timer); }, []);
211
+ 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]);
212
  if (isAllowedOrigin === null) { return <div style={{ padding: '20px', textAlign: 'center' }}>در حال بررسی دسترسی...</div>; }
213
 
 
214
  const createLogoFunction = (isMini: boolean, isActive: boolean, type: 'human' | 'ai' = 'human', forFooter: boolean = false) => {
215
  if (!isActive) return null;
 
216
  const colorKey = type === 'human' ? 'blue' : 'gray';
217
  const currentColors = logoColorConfig[colorKey as keyof typeof logoColorConfig];
 
218
  const size = isMini ? 80 : 200;
219
  const iconDisplaySize = isMini ? 35 : 70;
220
  const iconInset = (size - iconDisplaySize) / 2;
 
 
221
  const baseInsets = isMini
222
  ? { ping: 10, outer: 0, mid: 5, inner: 12 }
223
  : { ping: 40, outer: 0, mid: 20, inner: 50 };
 
224
  const IconComponent = type === 'human' ? SvgHumanIcon : null;
 
225
  return (
226
  <div className={cn("logo-animation-wrapper", {"for-footer": forFooter})} style={{ width: `${size}px`, height: `${size}px` }}>
 
227
  <div className={`absolute rounded-full opacity-50 animate-ping ${currentColors.ping}`} style={{ inset: `${baseInsets.ping}px` }}></div>
228
  <div className={`absolute rounded-full opacity-50 ${currentColors.outer}`} style={{ inset: `${baseInsets.outer}px` }}></div>
229
  <div className={`absolute rounded-full opacity-50 ${currentColors.mid}`} style={{ inset: `${baseInsets.mid}px` }}></div>