Spaces:
Running
Running
Update src/App.tsx
Browse files- src/App.tsx +34 -40
src/App.tsx
CHANGED
@@ -1,16 +1,4 @@
|
|
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";
|
15 |
import './App.scss';
|
16 |
import { LiveAPIProvider, useLiveAPIContext } from "./contexts/LiveAPIContext";
|
@@ -119,6 +107,7 @@ const SvgReferenceMicrophoneIcon = () => (
|
|
119 |
</svg>
|
120 |
);
|
121 |
|
|
|
122 |
const AppInternalLogic: React.FC<{
|
123 |
isMicActive: boolean;
|
124 |
isCamActive: boolean;
|
@@ -140,7 +129,7 @@ const AppInternalLogic: React.FC<{
|
|
140 |
notificationPopoverRef,
|
141 |
notificationButtonRef,
|
142 |
isNotificationOpen,
|
143 |
-
setIsNotificationOpen
|
144 |
}) => {
|
145 |
const { connected, disconnect } = useLiveAPIContext();
|
146 |
|
@@ -153,6 +142,7 @@ const AppInternalLogic: React.FC<{
|
|
153 |
return (
|
154 |
<div className="w-full flex flex-col items-center justify-center min-h-screen text-foreground antialiased">
|
155 |
<div className="main-wrapper max-w-3xl w-full flex flex-col items-center justify-center h-full relative">
|
|
|
156 |
<div className="header-controls">
|
157 |
<div id="notification-trigger-container">
|
158 |
<button
|
@@ -194,6 +184,7 @@ const AppInternalLogic: React.FC<{
|
|
194 |
</div>
|
195 |
</div>
|
196 |
|
|
|
197 |
<div className="media-area w-full flex flex-col items-center justify-center flex-grow relative">
|
198 |
<video
|
199 |
id="video-feed"
|
@@ -205,11 +196,13 @@ const AppInternalLogic: React.FC<{
|
|
205 |
{ "hidden": !isCamActive }
|
206 |
)}
|
207 |
/>
|
|
|
208 |
{isMicActive && !isCamActive && (
|
209 |
<div
|
210 |
id="large-logo-container"
|
211 |
-
className="
|
212 |
>
|
|
|
213 |
{createLogoFunction(false, true, 'human', false)}
|
214 |
</div>
|
215 |
)}
|
@@ -229,7 +222,7 @@ const AppInternalLogic: React.FC<{
|
|
229 |
</div>
|
230 |
</div>
|
231 |
);
|
232 |
-
}
|
233 |
|
234 |
const logoColorConfig = {
|
235 |
blue: {
|
@@ -238,13 +231,8 @@ const logoColorConfig = {
|
|
238 |
mid: "bg-blue-300 dark:bg-blue-600",
|
239 |
inner: "bg-blue-400 dark:bg-blue-500",
|
240 |
},
|
241 |
-
|
242 |
-
|
243 |
-
outer: "bg-green-200 dark:bg-green-700",
|
244 |
-
mid: "bg-green-300 dark:bg-green-600",
|
245 |
-
inner: "bg-green-400 dark:bg-green-500",
|
246 |
-
},
|
247 |
-
gray: {
|
248 |
ping: "bg-gray-200 dark:bg-gray-700",
|
249 |
outer: "bg-gray-200 dark:bg-gray-700",
|
250 |
mid: "bg-gray-300 dark:bg-gray-600",
|
@@ -253,6 +241,7 @@ const logoColorConfig = {
|
|
253 |
};
|
254 |
|
255 |
function App() {
|
|
|
256 |
const videoRef = useRef<HTMLVideoElement>(null);
|
257 |
const [showIOSModal, setShowIOSModal] = useState(false);
|
258 |
const [isAllowedOrigin, setIsAllowedOrigin] = useState<boolean | null>(null);
|
@@ -296,33 +285,38 @@ function App() {
|
|
296 |
return <div style={{ padding: '20px', textAlign: 'center' }}>در حال بررسی دسترسی...</div>;
|
297 |
}
|
298 |
|
|
|
299 |
const createLogoFunction = (isMini: boolean, isActive: boolean, type: 'human' | 'ai' = 'human', forFooter: boolean = false) => {
|
300 |
if (!isActive) return null;
|
301 |
|
302 |
-
const colorKey = type === 'human' ? 'blue' :
|
303 |
-
const currentColors = logoColorConfig[colorKey as keyof typeof logoColorConfig]
|
304 |
|
305 |
-
const size = isMini ? 80 : 200;
|
306 |
-
const iconDisplaySize = isMini ? 35 : 70;
|
307 |
-
const iconInset = (size - iconDisplaySize) / 2;
|
308 |
|
309 |
-
const
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
};
|
316 |
|
317 |
const IconComponent = type === 'human' ? SvgHumanIcon : null;
|
318 |
|
319 |
return (
|
|
|
320 |
<div className={cn("logo-animation-wrapper", {"for-footer": forFooter})} style={{ width: `${size}px`, height: `${size}px` }}>
|
321 |
-
|
322 |
-
<div className={`absolute rounded-full opacity-50 ${currentColors.
|
323 |
-
|
324 |
-
<div className={`absolute rounded-full opacity-50 ${currentColors.
|
325 |
-
|
|
|
|
|
|
|
|
|
|
|
326 |
{IconComponent && <IconComponent />}
|
327 |
</div>
|
328 |
</div>
|
|
|
1 |
+
// ... (ایمپورتها، myCustomInstruction, initialAppConfig، تعریف SvgHumanIcon و SvgReferenceMicrophoneIcon بدون تغییر) ...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import React, { useEffect, useRef, useState } from "react";
|
3 |
import './App.scss';
|
4 |
import { LiveAPIProvider, useLiveAPIContext } from "./contexts/LiveAPIContext";
|
|
|
107 |
</svg>
|
108 |
);
|
109 |
|
110 |
+
|
111 |
const AppInternalLogic: React.FC<{
|
112 |
isMicActive: boolean;
|
113 |
isCamActive: boolean;
|
|
|
129 |
notificationPopoverRef,
|
130 |
notificationButtonRef,
|
131 |
isNotificationOpen,
|
132 |
+
setIsNotificationOpen
|
133 |
}) => {
|
134 |
const { connected, disconnect } = useLiveAPIContext();
|
135 |
|
|
|
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 |
+
{/* ... (Header and Notification Popover بدون تغییر) ... */}
|
146 |
<div className="header-controls">
|
147 |
<div id="notification-trigger-container">
|
148 |
<button
|
|
|
184 |
</div>
|
185 |
</div>
|
186 |
|
187 |
+
|
188 |
<div className="media-area w-full flex flex-col items-center justify-center flex-grow relative">
|
189 |
<video
|
190 |
id="video-feed"
|
|
|
196 |
{ "hidden": !isCamActive }
|
197 |
)}
|
198 |
/>
|
199 |
+
{/* نمایش لوگوی بزرگ فقط زمانی که میکروفون فعال است و دوربین غیرفعال */}
|
200 |
{isMicActive && !isCamActive && (
|
201 |
<div
|
202 |
id="large-logo-container"
|
203 |
+
className="large-logo-container-class" // استفاده از کلاس برای استایل دهی بهتر
|
204 |
>
|
205 |
+
{/* پارامتر forFooter اینجا false است چون برای لوگوی بزرگ است */}
|
206 |
{createLogoFunction(false, true, 'human', false)}
|
207 |
</div>
|
208 |
)}
|
|
|
222 |
</div>
|
223 |
</div>
|
224 |
);
|
225 |
+
}
|
226 |
|
227 |
const logoColorConfig = {
|
228 |
blue: {
|
|
|
231 |
mid: "bg-blue-300 dark:bg-blue-600",
|
232 |
inner: "bg-blue-400 dark:bg-blue-500",
|
233 |
},
|
234 |
+
// ... (رنگهای دیگر اگر نیاز باشد) ...
|
235 |
+
gray: { // fallback
|
|
|
|
|
|
|
|
|
|
|
236 |
ping: "bg-gray-200 dark:bg-gray-700",
|
237 |
outer: "bg-gray-200 dark:bg-gray-700",
|
238 |
mid: "bg-gray-300 dark:bg-gray-600",
|
|
|
241 |
};
|
242 |
|
243 |
function App() {
|
244 |
+
// ... (state ها و useEffect های دیگر بدون تغییر) ...
|
245 |
const videoRef = useRef<HTMLVideoElement>(null);
|
246 |
const [showIOSModal, setShowIOSModal] = useState(false);
|
247 |
const [isAllowedOrigin, setIsAllowedOrigin] = useState<boolean | null>(null);
|
|
|
285 |
return <div style={{ padding: '20px', textAlign: 'center' }}>در حال بررسی دسترسی...</div>;
|
286 |
}
|
287 |
|
288 |
+
|
289 |
const createLogoFunction = (isMini: boolean, isActive: boolean, type: 'human' | 'ai' = 'human', forFooter: boolean = false) => {
|
290 |
if (!isActive) return null;
|
291 |
|
292 |
+
const colorKey = type === 'human' ? 'blue' : 'gray'; // Simplified for now
|
293 |
+
const currentColors = logoColorConfig[colorKey as keyof typeof logoColorConfig];
|
294 |
|
295 |
+
const size = isMini ? 80 : 200; // اندازه کلی کانتینر لوگو
|
296 |
+
const iconDisplaySize = isMini ? 35 : 70; // اندازه بصری آیکون SVG
|
|
|
297 |
|
298 |
+
const iconInset = (size - iconDisplaySize) / 2; // محاسبه برای وسط چین کردن
|
299 |
+
|
300 |
+
// مقادیر inset برای حلقهها از HTML مرجع شما (با توجه به isMini)
|
301 |
+
const baseInsets = isMini
|
302 |
+
? { ping: 10, outer: 0, mid: 5, inner: 12 } // مقادیر HTML برای isMini=true
|
303 |
+
: { ping: 40, outer: 0, mid: 20, inner: 50 };// مقادیر HTML برای isMini=false
|
|
|
304 |
|
305 |
const IconComponent = type === 'human' ? SvgHumanIcon : null;
|
306 |
|
307 |
return (
|
308 |
+
// کانتینر اصلی با اندازه مشخص شده
|
309 |
<div className={cn("logo-animation-wrapper", {"for-footer": forFooter})} style={{ width: `${size}px`, height: `${size}px` }}>
|
310 |
+
{/* حلقه پینگ */}
|
311 |
+
<div className={`absolute rounded-full opacity-50 animate-ping ${currentColors.ping}`} style={{ inset: `${baseInsets.ping}px` }}></div>
|
312 |
+
{/* حلقه بیرونی */}
|
313 |
+
<div className={`absolute rounded-full opacity-50 ${currentColors.outer}`} style={{ inset: `${baseInsets.outer}px` }}></div>
|
314 |
+
{/* حلقه میانی */}
|
315 |
+
<div className={`absolute rounded-full opacity-50 ${currentColors.mid}`} style={{ inset: `${baseInsets.mid}px` }}></div>
|
316 |
+
{/* حلقه داخلی */}
|
317 |
+
<div className={`absolute rounded-full opacity-50 ${currentColors.inner}`} style={{ inset: `${baseInsets.inner}px` }}></div>
|
318 |
+
{/* کانتینر آیکون */}
|
319 |
+
<div className="z-10 absolute flex items-center justify-center" style={{ inset: `${iconInset}px`, width: `${iconDisplaySize}px`, height: `${iconDisplaySize}px` }}>
|
320 |
{IconComponent && <IconComponent />}
|
321 |
</div>
|
322 |
</div>
|