Spaces:
Running
Running
Update src/App.tsx
Browse files- src/App.tsx +127 -80
src/App.tsx
CHANGED
@@ -13,7 +13,7 @@ limitations under the License.
|
|
13 |
|
14 |
import React, { useEffect, useRef, useState } from "react";
|
15 |
import './App.scss'; // اطمینان از ایمپورت شدن فایل SCSS
|
16 |
-
import { LiveAPIProvider } from "./contexts/LiveAPIContext";
|
17 |
import ControlTray from "./components/control-tray/ControlTray";
|
18 |
import { IOSModal } from "./components/ios-modal/IOSModal";
|
19 |
import { isIOS } from "./lib/platform";
|
@@ -113,6 +113,118 @@ const SvgHumanIcon = () => (
|
|
113 |
<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>
|
114 |
);
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
function App() {
|
118 |
const videoRef = useRef<HTMLVideoElement>(null);
|
@@ -120,7 +232,7 @@ function App() {
|
|
120 |
const [isAllowedOrigin, setIsAllowedOrigin] = useState<boolean | null>(null);
|
121 |
|
122 |
const [isMicActive, setIsMicActive] = useState(false);
|
123 |
-
const [isCamActive, setIsCamActive] = useState(false);
|
124 |
const [isNotificationOpen, setIsNotificationOpen] = useState(false);
|
125 |
|
126 |
const notificationPopoverRef = useRef<HTMLDivElement>(null);
|
@@ -133,7 +245,6 @@ function App() {
|
|
133 |
}
|
134 |
const timer = setTimeout(() => {
|
135 |
setIsAllowedOrigin(true);
|
136 |
-
console.log("Access allowed globally by default in App.tsx.");
|
137 |
}, 100);
|
138 |
|
139 |
return () => clearTimeout(timer);
|
@@ -162,7 +273,7 @@ function App() {
|
|
162 |
return <div style={{ padding: '20px', textAlign: 'center' }}>در حال بررسی دسترسی...</div>;
|
163 |
}
|
164 |
|
165 |
-
const
|
166 |
if (!isActive) return null;
|
167 |
const size = isMini ? 80 : 200;
|
168 |
const iconSize = isMini ? 35 : 70;
|
@@ -184,84 +295,20 @@ function App() {
|
|
184 |
);
|
185 |
};
|
186 |
|
187 |
-
|
188 |
return (
|
189 |
<LiveAPIProvider initialConfig={initialAppConfig}>
|
190 |
-
<
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
}}
|
203 |
-
>
|
204 |
-
<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>
|
205 |
-
</button>
|
206 |
-
<div className="header-button" onClick={() => alert('Back clicked (navigation logic)')}>
|
207 |
-
<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>
|
208 |
-
</div>
|
209 |
-
</div>
|
210 |
-
|
211 |
-
{/* Notification Popover */}
|
212 |
-
<div ref={notificationPopoverRef} id="notification-popover-wrapper" className="notification-popover-wrapper">
|
213 |
-
<div
|
214 |
-
id="notification-popover"
|
215 |
-
className={cn("popover-content", {
|
216 |
-
"open animate-popover-open-top-center": isNotificationOpen,
|
217 |
-
"animate-popover-close-top-center": !isNotificationOpen && document.getElementById('notification-popover')?.classList.contains('open'),
|
218 |
-
})}
|
219 |
-
>
|
220 |
-
<div className="notification-popover-text-content">
|
221 |
-
مدله��ی هوش مصنوعی میتوانند اشتباه کنند، صحت اطلاعات مهم را بررسی کنید و از وارد کردن اطلاعات حساس بپرهیزید.
|
222 |
-
</div>
|
223 |
-
</div>
|
224 |
-
</div>
|
225 |
-
|
226 |
-
{/* Main Media Area and Chat Area */}
|
227 |
-
<div className="flex flex-col md:flex-row w-full h-[calc(100vh-100px)] mt-[60px] mb-[40px]">
|
228 |
-
<div className="w-full md:w-1/3 p-2 overflow-y-auto">
|
229 |
-
<SidePanel />
|
230 |
-
<Altair />
|
231 |
-
</div>
|
232 |
-
|
233 |
-
<div className="w-full md:w-2/3 flex flex-col items-center justify-center bg-background relative">
|
234 |
-
<video
|
235 |
-
id="video-feed"
|
236 |
-
ref={videoRef}
|
237 |
-
autoPlay
|
238 |
-
playsInline
|
239 |
-
className={cn("absolute top-0 left-0 w-full h-full object-cover scale-x-[-1]", {
|
240 |
-
"hidden": !isCamActive, // کنترل نمایش ویدیو با isCamActive از App.tsx
|
241 |
-
})}
|
242 |
-
/>
|
243 |
-
<div id="large-logo-container" className={cn("items-center justify-center w-full h-full absolute top-0 left-0", {
|
244 |
-
"flex": !isCamActive && isMicActive,
|
245 |
-
"hidden": isCamActive || !isMicActive
|
246 |
-
})}>
|
247 |
-
{createLogoHTML(false, !isCamActive && isMicActive)}
|
248 |
-
</div>
|
249 |
-
</div>
|
250 |
-
</div>
|
251 |
-
|
252 |
-
<ControlTray
|
253 |
-
videoRef={videoRef}
|
254 |
-
supportsVideo={true}
|
255 |
-
onVideoStreamChange={(stream) => { /* App.tsx no longer needs direct videoStream state */ }}
|
256 |
-
isAppMicActive={isMicActive}
|
257 |
-
onAppMicToggle={setIsMicActive}
|
258 |
-
isAppCamActive={isCamActive} // <--- اصلاح شده: از isCamActive استفاده میشود
|
259 |
-
onAppCamToggle={setIsCamActive} // <--- کنترل isCamActive توسط App.tsx
|
260 |
-
createLogoFunction={createLogoHTML}
|
261 |
-
/>
|
262 |
-
|
263 |
-
</div>
|
264 |
-
</div>
|
265 |
<IOSModal isOpen={showIOSModal} onClose={() => setShowIOSModal(false)} />
|
266 |
</LiveAPIProvider>
|
267 |
);
|
|
|
13 |
|
14 |
import React, { useEffect, useRef, useState } from "react";
|
15 |
import './App.scss'; // اطمینان از ایمپورت شدن فایل SCSS
|
16 |
+
import { LiveAPIProvider, useLiveAPIContext } from "./contexts/LiveAPIContext"; // useLiveAPIContext ایمپورت شد
|
17 |
import ControlTray from "./components/control-tray/ControlTray";
|
18 |
import { IOSModal } from "./components/ios-modal/IOSModal";
|
19 |
import { isIOS } from "./lib/platform";
|
|
|
113 |
<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>
|
114 |
);
|
115 |
|
116 |
+
// کامپوننت داخلی برای دسترسی به context و اجرای disconnect و سایر منطقهای وابسته به context
|
117 |
+
const AppInternalLogic: React.FC<{
|
118 |
+
isMicActive: boolean;
|
119 |
+
isCamActive: boolean;
|
120 |
+
setIsMicActive: React.Dispatch<React.SetStateAction<boolean>>;
|
121 |
+
setIsCamActive: React.Dispatch<React.SetStateAction<boolean>>;
|
122 |
+
createLogoFunction: (isMini: boolean, isActive: boolean, type?: 'human' | 'ai') => React.ReactNode;
|
123 |
+
videoRef: React.RefObject<HTMLVideoElement>;
|
124 |
+
notificationPopoverRef: React.RefObject<HTMLDivElement>;
|
125 |
+
notificationButtonRef: React.RefObject<HTMLButtonElement>;
|
126 |
+
isNotificationOpen: boolean;
|
127 |
+
setIsNotificationOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
128 |
+
}> = ({
|
129 |
+
isMicActive,
|
130 |
+
isCamActive,
|
131 |
+
setIsMicActive, // برای استفاده در ControlTray
|
132 |
+
setIsCamActive, // برای استفاده در ControlTray
|
133 |
+
createLogoFunction,
|
134 |
+
videoRef,
|
135 |
+
notificationPopoverRef,
|
136 |
+
notificationButtonRef,
|
137 |
+
isNotificationOpen,
|
138 |
+
setIsNotificationOpen
|
139 |
+
}) => {
|
140 |
+
const { connected, disconnect } = useLiveAPIContext();
|
141 |
+
|
142 |
+
useEffect(() => {
|
143 |
+
// اگر هم میکروفون و هم دوربین غیرفعال شدند و ما متصل هستیم، اتصال را قطع کن
|
144 |
+
if (!isMicActive && !isCamActive && connected) {
|
145 |
+
console.log("AppInternalLogic: Both Mic and Cam are off. Disconnecting stream.");
|
146 |
+
disconnect();
|
147 |
+
}
|
148 |
+
}, [isMicActive, isCamActive, connected, disconnect]);
|
149 |
+
|
150 |
+
return (
|
151 |
+
<div className="w-full flex flex-col items-center justify-center min-h-screen bg-background text-foreground antialiased">
|
152 |
+
<div className="max-w-3xl w-full flex flex-col items-center justify-center h-full relative">
|
153 |
+
{/* Header */}
|
154 |
+
<div className="header-controls">
|
155 |
+
<button
|
156 |
+
ref={notificationButtonRef}
|
157 |
+
id="notification-button"
|
158 |
+
aria-label="Notifications"
|
159 |
+
className="header-button"
|
160 |
+
onClick={(e) => {
|
161 |
+
e.stopPropagation();
|
162 |
+
setIsNotificationOpen(!isNotificationOpen);
|
163 |
+
}}
|
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 className="header-button" onClick={() => alert('Back clicked (navigation logic)')}>
|
168 |
+
<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>
|
169 |
+
</div>
|
170 |
+
</div>
|
171 |
+
|
172 |
+
{/* Notification Popover */}
|
173 |
+
<div ref={notificationPopoverRef} id="notification-popover-wrapper" className="notification-popover-wrapper">
|
174 |
+
<div
|
175 |
+
id="notification-popover"
|
176 |
+
className={cn("popover-content", {
|
177 |
+
"open animate-popover-open-top-center": isNotificationOpen,
|
178 |
+
"animate-popover-close-top-center": !isNotificationOpen && document.getElementById('notification-popover')?.classList.contains('open'),
|
179 |
+
})}
|
180 |
+
>
|
181 |
+
<div className="notification-popover-text-content">
|
182 |
+
مدلهای هوش مصنوعی میتوانند اشتباه کنند، صحت اطلاعات مهم را بررسی کنید و از وارد کردن اطلاعات حساس بپرهیزید.
|
183 |
+
</div>
|
184 |
+
</div>
|
185 |
+
</div>
|
186 |
+
|
187 |
+
{/* Main Media Area and Chat Area */}
|
188 |
+
<div className="flex flex-col md:flex-row w-full h-[calc(100vh-100px)] mt-[60px] mb-[40px]">
|
189 |
+
<div className="w-full md:w-1/3 p-2 overflow-y-auto">
|
190 |
+
<SidePanel />
|
191 |
+
<Altair />
|
192 |
+
</div>
|
193 |
+
|
194 |
+
<div className="w-full md:w-2/3 flex flex-col items-center justify-center bg-background relative">
|
195 |
+
<video
|
196 |
+
id="video-feed"
|
197 |
+
ref={videoRef}
|
198 |
+
autoPlay
|
199 |
+
playsInline
|
200 |
+
className={cn("absolute top-0 left-0 w-full h-full object-cover scale-x-[-1]", {
|
201 |
+
"hidden": !isCamActive,
|
202 |
+
})}
|
203 |
+
/>
|
204 |
+
<div id="large-logo-container" className={cn("items-center justify-center w-full h-full absolute top-0 left-0", {
|
205 |
+
"flex": !isCamActive && isMicActive,
|
206 |
+
"hidden": isCamActive || !isMicActive
|
207 |
+
})}>
|
208 |
+
{createLogoFunction(false, !isCamActive && isMicActive)}
|
209 |
+
</div>
|
210 |
+
</div>
|
211 |
+
</div>
|
212 |
+
|
213 |
+
<ControlTray
|
214 |
+
videoRef={videoRef}
|
215 |
+
supportsVideo={true}
|
216 |
+
onVideoStreamChange={(stream) => { /* App.tsx no longer needs direct videoStream state */ }}
|
217 |
+
isAppMicActive={isMicActive}
|
218 |
+
onAppMicToggle={setIsMicActive}
|
219 |
+
isAppCamActive={isCamActive}
|
220 |
+
onAppCamToggle={setIsCamActive}
|
221 |
+
createLogoFunction={createLogoFunction}
|
222 |
+
/>
|
223 |
+
</div>
|
224 |
+
</div>
|
225 |
+
);
|
226 |
+
}
|
227 |
+
|
228 |
|
229 |
function App() {
|
230 |
const videoRef = useRef<HTMLVideoElement>(null);
|
|
|
232 |
const [isAllowedOrigin, setIsAllowedOrigin] = useState<boolean | null>(null);
|
233 |
|
234 |
const [isMicActive, setIsMicActive] = useState(false);
|
235 |
+
const [isCamActive, setIsCamActive] = useState(false);
|
236 |
const [isNotificationOpen, setIsNotificationOpen] = useState(false);
|
237 |
|
238 |
const notificationPopoverRef = useRef<HTMLDivElement>(null);
|
|
|
245 |
}
|
246 |
const timer = setTimeout(() => {
|
247 |
setIsAllowedOrigin(true);
|
|
|
248 |
}, 100);
|
249 |
|
250 |
return () => clearTimeout(timer);
|
|
|
273 |
return <div style={{ padding: '20px', textAlign: 'center' }}>در حال بررسی دسترسی...</div>;
|
274 |
}
|
275 |
|
276 |
+
const createLogoFunction = (isMini: boolean, isActive: boolean, type: 'human' | 'ai' = 'human') => {
|
277 |
if (!isActive) return null;
|
278 |
const size = isMini ? 80 : 200;
|
279 |
const iconSize = isMini ? 35 : 70;
|
|
|
295 |
);
|
296 |
};
|
297 |
|
|
|
298 |
return (
|
299 |
<LiveAPIProvider initialConfig={initialAppConfig}>
|
300 |
+
<AppInternalLogic
|
301 |
+
isMicActive={isMicActive}
|
302 |
+
setIsMicActive={setIsMicActive}
|
303 |
+
isCamActive={isCamActive}
|
304 |
+
setIsCamActive={setIsCamActive}
|
305 |
+
createLogoFunction={createLogoFunction}
|
306 |
+
videoRef={videoRef}
|
307 |
+
notificationPopoverRef={notificationPopoverRef}
|
308 |
+
notificationButtonRef={notificationButtonRef}
|
309 |
+
isNotificationOpen={isNotificationOpen}
|
310 |
+
setIsNotificationOpen={setIsNotificationOpen}
|
311 |
+
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
312 |
<IOSModal isOpen={showIOSModal} onClose={() => setShowIOSModal(false)} />
|
313 |
</LiveAPIProvider>
|
314 |
);
|