Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -198,15 +198,25 @@ content_map = {
|
|
| 198 |
"24X7 ๋ชจ๋ํฐ๋ง": "https://seawolf2357-bnews3.hf.space"
|
| 199 |
}
|
| 200 |
|
|
|
|
| 201 |
if st.session_state.selected_item in content_map:
|
|
|
|
| 202 |
main_content.markdown(
|
| 203 |
-
f'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
unsafe_allow_html=True
|
| 205 |
)
|
| 206 |
else:
|
| 207 |
main_content.markdown("<h2>๋ฉ๋ด์์ ํญ๋ชฉ์ ์ ํํ์ธ์.</h2>")
|
| 208 |
|
| 209 |
-
# Add JavaScript for dynamic iframe resizing and
|
| 210 |
st.markdown("""
|
| 211 |
<script>
|
| 212 |
function resizeIframe() {
|
|
@@ -215,6 +225,7 @@ function resizeIframe() {
|
|
| 215 |
iframe.style.height = window.innerHeight + 'px';
|
| 216 |
}
|
| 217 |
}
|
|
|
|
| 218 |
async function requestMicrophonePermission() {
|
| 219 |
try {
|
| 220 |
await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
@@ -223,8 +234,27 @@ async function requestMicrophonePermission() {
|
|
| 223 |
console.error("Error requesting microphone permission:", err);
|
| 224 |
}
|
| 225 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
window.addEventListener('resize', resizeIframe);
|
| 227 |
resizeIframe();
|
| 228 |
requestMicrophonePermission();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
</script>
|
| 230 |
-
""", unsafe_allow_html=True)
|
|
|
|
| 198 |
"24X7 ๋ชจ๋ํฐ๋ง": "https://seawolf2357-bnews3.hf.space"
|
| 199 |
}
|
| 200 |
|
| 201 |
+
|
| 202 |
if st.session_state.selected_item in content_map:
|
| 203 |
+
iframe_url = content_map[st.session_state.selected_item]
|
| 204 |
main_content.markdown(
|
| 205 |
+
f'''
|
| 206 |
+
<iframe src="{iframe_url}"
|
| 207 |
+
width="100%"
|
| 208 |
+
height="800"
|
| 209 |
+
frameborder="0"
|
| 210 |
+
allow="microphone *; camera *; fullscreen *; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
| 211 |
+
allowfullscreen>
|
| 212 |
+
</iframe>
|
| 213 |
+
''',
|
| 214 |
unsafe_allow_html=True
|
| 215 |
)
|
| 216 |
else:
|
| 217 |
main_content.markdown("<h2>๋ฉ๋ด์์ ํญ๋ชฉ์ ์ ํํ์ธ์.</h2>")
|
| 218 |
|
| 219 |
+
# Add JavaScript for dynamic iframe resizing, microphone permission, and enhanced iframe communication
|
| 220 |
st.markdown("""
|
| 221 |
<script>
|
| 222 |
function resizeIframe() {
|
|
|
|
| 225 |
iframe.style.height = window.innerHeight + 'px';
|
| 226 |
}
|
| 227 |
}
|
| 228 |
+
|
| 229 |
async function requestMicrophonePermission() {
|
| 230 |
try {
|
| 231 |
await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
|
|
| 234 |
console.error("Error requesting microphone permission:", err);
|
| 235 |
}
|
| 236 |
}
|
| 237 |
+
|
| 238 |
+
function postMessageToIframe(message) {
|
| 239 |
+
var iframe = document.querySelector('iframe');
|
| 240 |
+
if (iframe) {
|
| 241 |
+
iframe.contentWindow.postMessage(message, '*');
|
| 242 |
+
}
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
window.addEventListener('message', function(event) {
|
| 246 |
+
if (event.data === 'requestMicrophoneAccess') {
|
| 247 |
+
requestMicrophonePermission();
|
| 248 |
+
}
|
| 249 |
+
});
|
| 250 |
+
|
| 251 |
window.addEventListener('resize', resizeIframe);
|
| 252 |
resizeIframe();
|
| 253 |
requestMicrophonePermission();
|
| 254 |
+
|
| 255 |
+
// Attempt to enable microphone access after a short delay
|
| 256 |
+
setTimeout(() => {
|
| 257 |
+
postMessageToIframe('enableMicrophone');
|
| 258 |
+
}, 2000);
|
| 259 |
</script>
|
| 260 |
+
""", unsafe_allow_html=True)
|