Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- index.html +29 -2
index.html
CHANGED
@@ -217,8 +217,6 @@
|
|
217 |
top: 20px;
|
218 |
left: 50%;
|
219 |
transform: translateX(-50%);
|
220 |
-
background-color: #f44336;
|
221 |
-
color: white;
|
222 |
padding: 16px 24px;
|
223 |
border-radius: 4px;
|
224 |
font-size: 14px;
|
@@ -226,6 +224,16 @@
|
|
226 |
display: none;
|
227 |
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
228 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
</style>
|
230 |
</head>
|
231 |
|
@@ -291,6 +299,7 @@
|
|
291 |
function showError(message) {
|
292 |
const toast = document.getElementById('error-toast');
|
293 |
toast.textContent = message;
|
|
|
294 |
toast.style.display = 'block';
|
295 |
|
296 |
// Hide toast after 5 seconds
|
@@ -303,6 +312,18 @@
|
|
303 |
const config = __RTC_CONFIGURATION__;
|
304 |
peerConnection = new RTCPeerConnection(config);
|
305 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
306 |
try {
|
307 |
const stream = await navigator.mediaDevices.getUserMedia({
|
308 |
audio: true
|
@@ -337,6 +358,11 @@
|
|
337 |
// Add connection state change listener
|
338 |
peerConnection.addEventListener('connectionstatechange', () => {
|
339 |
console.log('Connection state:', peerConnection.connectionState);
|
|
|
|
|
|
|
|
|
|
|
340 |
updateButtonState();
|
341 |
});
|
342 |
|
@@ -437,6 +463,7 @@
|
|
437 |
addMessage(eventJson.role, eventJson.content);
|
438 |
});
|
439 |
} catch (err) {
|
|
|
440 |
console.error('Error setting up WebRTC:', err);
|
441 |
showError('Failed to establish connection. Please try again.');
|
442 |
stop();
|
|
|
217 |
top: 20px;
|
218 |
left: 50%;
|
219 |
transform: translateX(-50%);
|
|
|
|
|
220 |
padding: 16px 24px;
|
221 |
border-radius: 4px;
|
222 |
font-size: 14px;
|
|
|
224 |
display: none;
|
225 |
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
226 |
}
|
227 |
+
|
228 |
+
.toast.error {
|
229 |
+
background-color: #f44336;
|
230 |
+
color: white;
|
231 |
+
}
|
232 |
+
|
233 |
+
.toast.warning {
|
234 |
+
background-color: #ffd700;
|
235 |
+
color: black;
|
236 |
+
}
|
237 |
</style>
|
238 |
</head>
|
239 |
|
|
|
299 |
function showError(message) {
|
300 |
const toast = document.getElementById('error-toast');
|
301 |
toast.textContent = message;
|
302 |
+
toast.className = 'toast error';
|
303 |
toast.style.display = 'block';
|
304 |
|
305 |
// Hide toast after 5 seconds
|
|
|
312 |
const config = __RTC_CONFIGURATION__;
|
313 |
peerConnection = new RTCPeerConnection(config);
|
314 |
|
315 |
+
const timeoutId = setTimeout(() => {
|
316 |
+
const toast = document.getElementById('error-toast');
|
317 |
+
toast.textContent = "Connection is taking longer than usual. Are you on a VPN?";
|
318 |
+
toast.className = 'toast warning';
|
319 |
+
toast.style.display = 'block';
|
320 |
+
|
321 |
+
// Hide warning after 5 seconds
|
322 |
+
setTimeout(() => {
|
323 |
+
toast.style.display = 'none';
|
324 |
+
}, 5000);
|
325 |
+
}, 5000);
|
326 |
+
|
327 |
try {
|
328 |
const stream = await navigator.mediaDevices.getUserMedia({
|
329 |
audio: true
|
|
|
358 |
// Add connection state change listener
|
359 |
peerConnection.addEventListener('connectionstatechange', () => {
|
360 |
console.log('Connection state:', peerConnection.connectionState);
|
361 |
+
if (peerConnection.connectionState === 'connected') {
|
362 |
+
clearTimeout(timeoutId);
|
363 |
+
const toast = document.getElementById('error-toast');
|
364 |
+
toast.style.display = 'none';
|
365 |
+
}
|
366 |
updateButtonState();
|
367 |
});
|
368 |
|
|
|
463 |
addMessage(eventJson.role, eventJson.content);
|
464 |
});
|
465 |
} catch (err) {
|
466 |
+
clearTimeout(timeoutId);
|
467 |
console.error('Error setting up WebRTC:', err);
|
468 |
showError('Failed to establish connection. Please try again.');
|
469 |
stop();
|