Spaces:
Running
Running
Update src/App.tsx
Browse files- src/App.tsx +262 -140
src/App.tsx
CHANGED
@@ -1,75 +1,35 @@
|
|
1 |
/**
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
import SidePanel from "./components/side-panel/SidePanel";
|
21 |
import { Altair } from "./components/altair/Altair";
|
22 |
-
import ControlTray from "./components/control-tray/ControlTray";
|
23 |
import { IOSModal } from "./components/ios-modal/IOSModal";
|
24 |
import { isIOS } from "./lib/platform";
|
25 |
-
import cn from "classnames";
|
26 |
import { LiveConfig } from "./multimodal-live-types";
|
27 |
|
28 |
// --- 👇 دامنه مجاز خودتان را اینجا قرار دهید (با https یا http) 👇 ---
|
29 |
const ALLOWED_ORIGIN = "https://www.aisada.ir"; // یا "http://www.aisada.ir"; // یا "https://aisada.ir"; // یا "http://aisada.ir" اگر سایتتان http است
|
30 |
// --- 👆 ---
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
const [videoStream, setVideoStream] = useState<MediaStream | null>(null);
|
35 |
-
const [showIOSModal, setShowIOSModal] = useState(false);
|
36 |
-
const [isAllowedOrigin, setIsAllowedOrigin] = useState<boolean | null>(null);
|
37 |
-
|
38 |
-
useEffect(() => {
|
39 |
-
if (isIOS()) {
|
40 |
-
setShowIOSModal(true);
|
41 |
-
}
|
42 |
-
|
43 |
-
// --- 👇 منطق بررسی دامنه مجاز (بدون تغییر) 👇 ---
|
44 |
-
try {
|
45 |
-
if (window.self !== window.top) {
|
46 |
-
if (window.location.ancestorOrigins && window.location.ancestorOrigins.length > 0) {
|
47 |
-
const parentOrigin = window.location.ancestorOrigins[0];
|
48 |
-
console.log("Parent Origin:", parentOrigin);
|
49 |
-
if (parentOrigin === ALLOWED_ORIGIN) {
|
50 |
-
setIsAllowedOrigin(true);
|
51 |
-
} else {
|
52 |
-
console.warn(`Blocked load from origin: ${parentOrigin}`);
|
53 |
-
setIsAllowedOrigin(false);
|
54 |
-
}
|
55 |
-
} else {
|
56 |
-
console.warn("Cannot verify parent origin (ancestorOrigins not available/empty). Blocking.");
|
57 |
-
setIsAllowedOrigin(false);
|
58 |
-
}
|
59 |
-
} else {
|
60 |
-
console.warn("App loaded directly, not in an iframe. Blocking.");
|
61 |
-
setIsAllowedOrigin(false);
|
62 |
-
}
|
63 |
-
} catch (e) {
|
64 |
-
console.error("Cross-origin access error, cannot verify parent. Blocking.", e);
|
65 |
-
setIsAllowedOrigin(false);
|
66 |
-
}
|
67 |
-
// --- 👆 ---
|
68 |
-
|
69 |
-
}, []);
|
70 |
-
|
71 |
-
// --- 👇 دستورالعمل شخصیسازی شما (بدون تغییر) 👇 ---
|
72 |
-
const myCustomInstruction = `
|
73 |
ت1. هویت دستیار:
|
74 |
|
75 |
فقط خود را به عنوان "دستیار صوتی و تصویری اپلیکیشن زبانفلای" معرفی کن.
|
@@ -79,9 +39,7 @@ function App() {
|
|
79 |
در پاسخ به سؤال کاربر درباره هویت، دقیقاً بگو:
|
80 |
"من دستیار صوتی و تصویری اپلیکیشن زبانفلای هستم. چگونه میتوانم به شما کمک کنم؟"
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
2. مدیریت زبان گفتگو:
|
85 |
|
86 |
به طور پیشفرض، مکالمه را به زبان انگلیسی آغاز کن.
|
87 |
|
@@ -89,17 +47,13 @@ function App() {
|
|
89 |
|
90 |
زبان پاسخ را همیشه مطابق زبان کاربر تنظیم کن. تغییر زبان به صورت خودکار انجام شود.
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
3. بیان اعداد:
|
95 |
|
96 |
هنگام مکالمه به انگلیسی، اعداد را به صورت کامل به انگلیسی بیان کن (مثلاً: twenty-five).
|
97 |
|
98 |
هنگام مکالمه به زبانی دیگر، اعداد را به همان زبان بیان کن (مثلاً: بیست و پنج).
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
4. تنظیم صدا و لحن:
|
103 |
|
104 |
با صدای مایل به بلند و شفاف صحبت کن.
|
105 |
|
@@ -107,17 +61,13 @@ function App() {
|
|
107 |
|
108 |
بدون استثنا، هرگونه تغییر صدای درخواستی کاربر را اجرا کن.
|
109 |
|
110 |
-
|
111 |
-
|
112 |
-
5. تعهد به پاسخگویی:
|
113 |
|
114 |
تحت هیچ شرایطی به کاربر نگو که "نمیتوانم پاسخ دهم" یا "نمیتوانم کمک کنم".
|
115 |
|
116 |
همیشه در تمام زمینهها تلاش کن بهترین پاسخ ممکن را به کاربر ارائه بدهی.
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
6. رفتار در شروع گفتگو:
|
121 |
|
122 |
اگر پیام ورودی "START_GREETING" دریافت شد، تنها با یکی از جملات کوتاه زیر پاسخ بده:
|
123 |
|
@@ -125,97 +75,269 @@ function App() {
|
|
125 |
|
126 |
یا "Hey, what's up?"
|
127 |
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
7. اطلاعرسانی درباره اپلیکیشن زبانفلای:
|
132 |
|
133 |
در صورت نیاز کاربر، توضیح بده که اپلیکیشن زبانفلای در گوگل پلی و کافه بازار قابل دانلود است.
|
134 |
|
135 |
راهنمایی کن که کاربران میتوانند با جستجو در این فروشگاهها، اپلیکیشن را نصب کنند.
|
136 |
|
137 |
-
|
138 |
-
|
139 |
-
8. پشتیبانی از یادگیری زبان:
|
140 |
|
141 |
هنگام پاسخگویی، در صورت مرتبط بودن، مثالهای جملهسازی، کاربرد واژگان و اصطلاحات ارائه بده.
|
142 |
|
143 |
در صورت درخواست کاربر، معانی واژگان، هممعنیها، متضادها، و نمونه جملهها را هم ارائه بده.
|
144 |
|
145 |
-
|
146 |
-
|
147 |
-
9. تمرین شنیداری و گفتاری:
|
148 |
|
149 |
اگر کاربر بخواهد، جملهای را بخوان و از او بخواه آن را تکرار کند (تمرین shadowing).
|
150 |
|
151 |
فرصت کامل برای تکرار بده و کاربر را با بازخورد مثبت تشویق کن.
|
152 |
|
153 |
-
|
154 |
-
|
155 |
-
10. شخصیسازی تجربه یادگیری:
|
156 |
|
157 |
در صورت درخواست کاربر، سرعت مکالمه را کند یا تند کن.
|
158 |
|
159 |
سطح سختی واژگان و جملات را بر اساس سطح کاربر (مبتدی، متوسط، پیشرفته) تنظیم کن.".
|
160 |
`.trim();
|
161 |
-
|
162 |
-
|
163 |
|
164 |
-
|
165 |
-
|
166 |
model: "models/gemini-2.0-flash-exp", // یا هر مدلی که استفاده میکنید
|
167 |
systemInstruction: {
|
168 |
-
|
169 |
}
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
|
|
|
|
|
|
203 |
</div>
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
/>
|
209 |
-
</main>
|
210 |
</div>
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
|
|
219 |
}
|
220 |
|
221 |
export default App;
|
|
|
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, useCallback } from "react";
|
15 |
+
import "./App.scss"; // Updated SCSS file
|
16 |
+
import { LiveAPIProvider, useLiveAPIContext } from "./contexts/LiveAPIContext";
|
17 |
+
// SidePanel and Altair are part of the original Gemini UI.
|
18 |
+
// You need to decide if/how they fit into the new UI.
|
19 |
+
// For now, we'll include them but they might need styling or to be conditionally rendered.
|
20 |
import SidePanel from "./components/side-panel/SidePanel";
|
21 |
import { Altair } from "./components/altair/Altair";
|
22 |
+
import ControlTray from "./components/control-tray/ControlTray"; // This will be our new footer
|
23 |
import { IOSModal } from "./components/ios-modal/IOSModal";
|
24 |
import { isIOS } from "./lib/platform";
|
|
|
25 |
import { LiveConfig } from "./multimodal-live-types";
|
26 |
|
27 |
// --- 👇 دامنه مجاز خودتان را اینجا قرار دهید (با https یا http) 👇 ---
|
28 |
const ALLOWED_ORIGIN = "https://www.aisada.ir"; // یا "http://www.aisada.ir"; // یا "https://aisada.ir"; // یا "http://aisada.ir" اگر سایتتان http است
|
29 |
// --- 👆 ---
|
30 |
|
31 |
+
// --- 👇 دستورالعمل شخصیسازی شما (بدون تغییر) 👇 ---
|
32 |
+
const myCustomInstruction = `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
ت1. هویت دستیار:
|
34 |
|
35 |
فقط خود را به عنوان "دستیار صوتی و تصویری اپلیکیشن زبانفلای" معرفی کن.
|
|
|
39 |
در پاسخ به سؤال کاربر درباره هویت، دقیقاً بگو:
|
40 |
"من دستیار صوتی و تصویری اپلیکیشن زبانفلای هستم. چگونه میتوانم به شما کمک کنم؟"
|
41 |
|
42 |
+
مدیریت زبان گفتگو:
|
|
|
|
|
43 |
|
44 |
به طور پیشفرض، مکالمه را به زبان انگلیسی آغاز کن.
|
45 |
|
|
|
47 |
|
48 |
زبان پاسخ را همیشه مطابق زبان کاربر تنظیم کن. تغییر زبان به صورت خودکار انجام شود.
|
49 |
|
50 |
+
بیان اعداد:
|
|
|
|
|
51 |
|
52 |
هنگام مکالمه به انگلیسی، اعداد را به صورت کامل به انگلیسی بیان کن (مثلاً: twenty-five).
|
53 |
|
54 |
هنگام مکالمه به زبانی دیگر، اعداد را به همان زبان بیان کن (مثلاً: بیست و پنج).
|
55 |
|
56 |
+
تنظیم صدا و لحن:
|
|
|
|
|
57 |
|
58 |
با صدای مایل به بلند و شفاف صحبت کن.
|
59 |
|
|
|
61 |
|
62 |
بدون استثنا، هرگونه تغییر صدای درخواستی کاربر را اجرا کن.
|
63 |
|
64 |
+
تعهد به پاسخگویی:
|
|
|
|
|
65 |
|
66 |
تحت هیچ شرایطی به کاربر نگو که "نمیتوانم پاسخ دهم" یا "نمیتوانم کمک کنم".
|
67 |
|
68 |
همیشه در تمام زمینهها تلاش کن بهترین پاسخ ممکن را به کاربر ارائه بدهی.
|
69 |
|
70 |
+
رفتار در شروع گفتگو:
|
|
|
|
|
71 |
|
72 |
اگر پیام ورودی "START_GREETING" دریافت شد، تنها با یکی از جملات کوتاه زیر پاسخ بده:
|
73 |
|
|
|
75 |
|
76 |
یا "Hey, what's up?"
|
77 |
|
78 |
+
اطلاعرسانی درباره اپلیکیشن زبانفلای:
|
|
|
|
|
|
|
79 |
|
80 |
در صورت نیاز کاربر، توضیح بده که اپلیکیشن زبانفلای در گوگل پلی و کافه بازار قابل دانلود است.
|
81 |
|
82 |
راهنمایی کن که کاربران میتوانند با جستجو در این فروشگاهها، اپلیکیشن را نصب کنند.
|
83 |
|
84 |
+
پشتیبانی از یادگیری زبان:
|
|
|
|
|
85 |
|
86 |
هنگام پاسخگویی، در صورت مرتبط بودن، مثالهای جملهسازی، کاربرد واژگان و اصطلاحات ارائه بده.
|
87 |
|
88 |
در صورت درخواست کاربر، معانی واژگان، هممعنیها، متضادها، و نمونه جملهها را هم ارائه بده.
|
89 |
|
90 |
+
تمرین شنیداری و گفتاری:
|
|
|
|
|
91 |
|
92 |
اگر کاربر بخواهد، جملهای را بخوان و از او بخواه آن را تکرار کند (تمرین shadowing).
|
93 |
|
94 |
فرصت کامل برای تکرار بده و کاربر را با بازخورد مثبت تشویق کن.
|
95 |
|
96 |
+
شخصیسازی تجربه یادگیری:
|
|
|
|
|
97 |
|
98 |
در صورت درخواست کاربر، سرعت مکالمه را کند یا تند کن.
|
99 |
|
100 |
سطح سختی واژگان و جملات را بر اساس سطح کاربر (مبتدی، متوسط، پیشرفته) تنظیم کن.".
|
101 |
`.trim();
|
102 |
+
// --- 👆 ---
|
|
|
103 |
|
104 |
+
// --- 👇 تنظیمات اولیه (بدون تغییر) 👇 ---
|
105 |
+
const initialAppConfig: LiveConfig = {
|
106 |
model: "models/gemini-2.0-flash-exp", // یا هر مدلی که استفاده میکنید
|
107 |
systemInstruction: {
|
108 |
+
parts: [{ text: myCustomInstruction }]
|
109 |
}
|
110 |
+
};
|
111 |
+
// --- 👆 ---
|
112 |
+
|
113 |
+
// SVG Icons (as React components or functions returning JSX)
|
114 |
+
const NotificationIcon = () => (
|
115 |
+
<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>
|
116 |
+
);
|
117 |
+
|
118 |
+
const BackIcon = () => (
|
119 |
+
<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>
|
120 |
+
);
|
121 |
+
|
122 |
+
const HumanIconSVG = ({ width = 70, height = 70 }: { width?: number, height?: number }) => (
|
123 |
+
<svg width={width} height={height} 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>
|
124 |
+
);
|
125 |
+
|
126 |
+
const LogoDisplay = ({ isMini, isHumanActive }: { isMini: boolean, isHumanActive: boolean }) => {
|
127 |
+
if (!isHumanActive) return null; // Simplified: only show human logo
|
128 |
+
|
129 |
+
const size = isMini ? 80 : 200;
|
130 |
+
const iconSize = isMini ? 35 : 70;
|
131 |
+
const insetBase = isMini
|
132 |
+
? { ping: 10, outer: 0, mid: 5, inner: 12, icon: 22.5 } // Centered icon
|
133 |
+
: { ping: 40, outer: 0, mid: 20, inner: 50, icon: 65 }; // Centered icon
|
134 |
+
const bgColorBase = 'blue'; // Simplified to blue for human
|
135 |
+
|
136 |
+
return (
|
137 |
+
<div className="relative" style={{ width: `${size}px`, height: `${size}px` }}>
|
138 |
+
{/* These divs are for Tailwind JIT, not strictly needed if classes are used directly */}
|
139 |
+
{/* <div className="hidden bg-blue-200 bg-blue-300 bg-blue-400"></div> */}
|
140 |
+
<div className={`absolute rounded-full opacity-50 animate-ping bg-${bgColorBase}-200 dark:bg-${bgColorBase}-700`} style={{ inset: `${insetBase.ping}px` }}></div>
|
141 |
+
<div className={`absolute rounded-full opacity-50 bg-${bgColorBase}-200 dark:bg-${bgColorBase}-700`} style={{ inset: `${insetBase.outer}px` }}></div>
|
142 |
+
<div className={`absolute rounded-full opacity-50 bg-${bgColorBase}-300 dark:bg-${bgColorBase}-600`} style={{ inset: `${insetBase.mid}px` }}></div>
|
143 |
+
<div className={`absolute rounded-full opacity-50 bg-${bgColorBase}-400 dark:bg-${bgColorBase}-500`} style={{ inset: `${insetBase.inner}px` }}></div>
|
144 |
+
<div className="z-10 absolute" style={{ top: `${insetBase.icon}px`, left: `${insetBase.icon}px` }}>
|
145 |
+
<HumanIconSVG width={iconSize} height={iconSize} />
|
146 |
</div>
|
147 |
+
</div>
|
148 |
+
);
|
149 |
+
};
|
150 |
+
|
151 |
+
|
152 |
+
function AppContent() {
|
153 |
+
const videoRef = useRef<HTMLVideoElement>(null);
|
154 |
+
const [videoStream, setVideoStream] = useState<MediaStream | null>(null);
|
155 |
+
const [showIOSModal, setShowIOSModal] = useState(false);
|
156 |
+
const [isAllowedOrigin, setIsAllowedOrigin] = useState<boolean | null>(null);
|
157 |
+
const [isNotificationOpen, setIsNotificationOpen] useState(false);
|
158 |
+
const notificationPopoverRef = useRef<HTMLDivElement>(null);
|
159 |
+
const notificationButtonRef = useRef<HTMLButtonElement>(null);
|
160 |
+
|
161 |
+
// States for new UI, to be controlled by ControlTray or LiveAPIContext
|
162 |
+
const [isMicActive, setIsMicActive] = useState(false); // Is microphone capturing
|
163 |
+
const [isCamActive, setIsCamActive] = useState(false); // Is camera capturing
|
164 |
+
|
165 |
+
const { connected, volume } = useLiveAPIContext(); // Get connection status and volume
|
166 |
+
|
167 |
+
useEffect(() => {
|
168 |
+
if (isIOS()) {
|
169 |
+
setShowIOSModal(true);
|
170 |
+
}
|
171 |
+
|
172 |
+
try {
|
173 |
+
if (window.self !== window.top) {
|
174 |
+
if (window.location.ancestorOrigins && window.location.ancestorOrigins.length > 0) {
|
175 |
+
const parentOrigin = window.location.ancestorOrigins[0];
|
176 |
+
if (parentOrigin === ALLOWED_ORIGIN) {
|
177 |
+
setIsAllowedOrigin(true);
|
178 |
+
} else {
|
179 |
+
console.warn(`Blocked load from origin: ${parentOrigin}`);
|
180 |
+
setIsAllowedOrigin(false);
|
181 |
+
}
|
182 |
+
} else {
|
183 |
+
console.warn("Cannot verify parent origin (ancestorOrigins not available/empty). Blocking.");
|
184 |
+
setIsAllowedOrigin(false);
|
185 |
+
}
|
186 |
+
} else {
|
187 |
+
console.warn("App loaded directly, not in an iframe. Blocking.");
|
188 |
+
setIsAllowedOrigin(false); // For security, must be in iframe from allowed origin
|
189 |
+
}
|
190 |
+
} catch (e) {
|
191 |
+
console.error("Cross-origin access error, cannot verify parent. Blocking.", e);
|
192 |
+
setIsAllowedOrigin(false);
|
193 |
+
}
|
194 |
+
|
195 |
+
// Dark mode toggle for testing (can be removed or integrated with a theme switcher)
|
196 |
+
// document.documentElement.classList.add('dark');
|
197 |
+
|
198 |
+
// Click outside listener for notification popover
|
199 |
+
const handleClickOutside = (event: MouseEvent) => {
|
200 |
+
if (isNotificationOpen &&
|
201 |
+
notificationPopoverRef.current &&
|
202 |
+
!notificationPopoverRef.current.contains(event.target as Node) &&
|
203 |
+
notificationButtonRef.current &&
|
204 |
+
!notificationButtonRef.current.contains(event.target as Node)
|
205 |
+
) {
|
206 |
+
setIsNotificationOpen(false);
|
207 |
+
}
|
208 |
+
};
|
209 |
+
document.addEventListener('click', handleClickOutside);
|
210 |
+
return () => {
|
211 |
+
document.removeEventListener('click', handleClickOutside);
|
212 |
+
};
|
213 |
+
|
214 |
+
}, [isNotificationOpen]);
|
215 |
+
|
216 |
+
|
217 |
+
const handleVideoStreamChange = useCallback((stream: MediaStream | null) => {
|
218 |
+
setVideoStream(stream);
|
219 |
+
setIsCamActive(!!stream); // Update cam active state based on stream
|
220 |
+
if (videoRef.current) {
|
221 |
+
videoRef.current.srcObject = stream;
|
222 |
+
if (stream) {
|
223 |
+
videoRef.current.play().catch(e => console.warn("Video play failed:", e));
|
224 |
+
}
|
225 |
+
}
|
226 |
+
}, []);
|
227 |
+
|
228 |
+
// Update CSS --volume variable for mic pulse animation
|
229 |
+
useEffect(() => {
|
230 |
+
// The volume from useLiveAPIContext is the output volume.
|
231 |
+
// For input volume pulse, ControlTray will handle its own state if it keeps AudioPulse logic
|
232 |
+
// Or, if App.tsx controls the mic button directly, it would need input volume.
|
233 |
+
// For now, let's assume ControlTray handles the visual pulse based on its internal state or props.
|
234 |
+
// If we want the pulse on the App's mic button, we need the input volume here.
|
235 |
+
// The original ControlTray uses 'inVolume' from AudioRecorder.
|
236 |
+
// Let's pass the 'volume' (output volume) from context to ControlTray for now.
|
237 |
+
// Or better, ControlTray should get inVolume itself if it renders the mic button.
|
238 |
+
// Let's assume `volume` from `useLiveAPIContext` is for the *output* visualization.
|
239 |
+
// The mic button pulse in new design is different (CSS based on active state and --volume from recorder)
|
240 |
+
// `ControlTray` will manage its own input volume for the pulse.
|
241 |
+
}, [volume]);
|
242 |
+
|
243 |
+
|
244 |
+
if (isAllowedOrigin === null) {
|
245 |
+
return <div style={{ padding: '20px', textAlign: 'center' }}>در حال بررسی دسترسی...</div>;
|
246 |
+
}
|
247 |
+
|
248 |
+
if (isAllowedOrigin === false) {
|
249 |
+
return <div style={{ padding: '20px', textAlign: 'center', color: 'red' }}>دسترسی غیرمجاز! اگر چت صوتی و تصویری برای شما باز نمیشود این لینک رو با مرورگر کروم باز کنید و همچنین مرورگر کروم رو به عنوان مرورگر پیشفرض گوشی خود قرار دهید تا هر بار زدن روی دکمه شروع داخل برنامه لینک با مرورگر کروم باز بشه، برای پیشفرض قرار دادن مرورگر کروم وارد تنظیمات گوشی خود شوید قسمت برنامه ها ، مدیریت برنامه ها رو کلیک کنید بالای صفحه روی سه نقطه بزنید و تنظیمات بیشتر رو انتخاب کنید بعدا وارد قسمت برنامه های پیش فرض شوید و مرورگر کروم رو به عنوان مرورگر پیشفرض خود قرار دهید، اگر مشکلی بود حتماً به پشتیبانی برنامه پیام بفرستید</div>;
|
250 |
+
}
|
251 |
+
|
252 |
+
// If you keep SidePanel and Altair, they need to be integrated into the new layout.
|
253 |
+
// For this example, I'm wrapping the new UI structure.
|
254 |
+
// The original structure was <SidePanel /> <main> <Altair /> <video /> <ControlTray /> </main>
|
255 |
+
// This might need careful restyling if SidePanel and Altair are to be used with the new fullscreen-like UI.
|
256 |
+
// For simplicity, I'll focus on the new UI elements and keep Altair for chat display.
|
257 |
+
|
258 |
+
return (
|
259 |
+
<div className="App"> {/* Main container from original Gemini App */}
|
260 |
+
{/* <SidePanel /> // You may want to hide or reposition this */}
|
261 |
+
<main> {/* Original main, Altair will go here */}
|
262 |
+
<div className="main-app-area"> {/* For Altair and video */}
|
263 |
+
{/* Altair is the chat bubbles. Position it as needed. */}
|
264 |
+
<Altair />
|
265 |
+
|
266 |
+
{/* Header */}
|
267 |
+
<div className="header-controls">
|
268 |
+
<button
|
269 |
+
id="notification-button"
|
270 |
+
ref={notificationButtonRef}
|
271 |
+
aria-label="Notifications"
|
272 |
+
className="header-button"
|
273 |
+
onClick={(e) => {
|
274 |
+
e.stopPropagation();
|
275 |
+
setIsNotificationOpen(!isNotificationOpen);
|
276 |
+
}}
|
277 |
+
>
|
278 |
+
<NotificationIcon />
|
279 |
+
</button>
|
280 |
+
<button className="header-button" onClick={() => alert('Back clicked (TODO: implement)')}>
|
281 |
+
<BackIcon />
|
282 |
+
</button>
|
283 |
+
</div>
|
284 |
+
|
285 |
+
{/* Notification Popover */}
|
286 |
+
<div id="notification-popover-wrapper" className="notification-popover-wrapper">
|
287 |
+
<div
|
288 |
+
id="notification-popover"
|
289 |
+
ref={notificationPopoverRef}
|
290 |
+
className={`popover-content ${isNotificationOpen ? 'open' : ''}`}
|
291 |
+
>
|
292 |
+
<div className="notification-popover-text-content">
|
293 |
+
مدلهای هوش مصنوعی میتوانند اشتباه کنند، صحت اطلاعات مهم را بررسی کنید و از وارد کردن اطلاعات حساس بپرهیزید.
|
294 |
+
</div>
|
295 |
+
</div>
|
296 |
+
</div>
|
297 |
+
|
298 |
+
{/* Media Area (Video feed and Logos) */}
|
299 |
+
<div className="media-toggle-area">
|
300 |
+
<video
|
301 |
+
id="video-feed"
|
302 |
+
ref={videoRef}
|
303 |
+
autoPlay
|
304 |
+
playsInline
|
305 |
+
className={`video-feed ${!isCamActive ? 'hidden' : ''}`}
|
306 |
+
/>
|
307 |
+
{!isCamActive && isMicActive && ( // Show large logo if mic is on and cam is off
|
308 |
+
<div id="large-logo-container" className="large-logo-container">
|
309 |
+
<LogoDisplay isMini={false} isHumanActive={true} />
|
310 |
+
</div>
|
311 |
+
)}
|
312 |
+
{/* The small logo is part of the footer logic in ControlTray */}
|
313 |
+
</div>
|
314 |
+
</div>
|
315 |
+
|
316 |
+
{/* Footer Controls */}
|
317 |
+
<ControlTray
|
318 |
+
videoRef={videoRef} // Pass videoRef for video operations
|
319 |
+
onVideoStreamChange={handleVideoStreamChange}
|
320 |
+
// Pass setters for App to know mic/cam state for UI logic (e.g., logos)
|
321 |
+
setIsMicActive={setIsMicActive}
|
322 |
+
setIsCamActiveExternal={setIsCamActive} // Renamed to avoid conflict if ControlTray has its own isCamActive
|
323 |
+
isCamActiveApp={isCamActive} // Pass down App's view of cam state
|
324 |
+
/>
|
325 |
+
</main>
|
326 |
+
|
327 |
+
<IOSModal
|
328 |
+
isOpen={showIOSModal}
|
329 |
+
onClose={() => setShowIOSModal(false)}
|
330 |
/>
|
|
|
331 |
</div>
|
332 |
+
);
|
333 |
+
}
|
334 |
+
|
335 |
+
function App() {
|
336 |
+
return (
|
337 |
+
<LiveAPIProvider initialConfig={initialAppConfig}>
|
338 |
+
<AppContent />
|
339 |
+
</LiveAPIProvider>
|
340 |
+
);
|
341 |
}
|
342 |
|
343 |
export default App;
|