Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Upload folder using huggingface_hub
Browse files- index.html +29 -2
index.html
CHANGED
@@ -154,8 +154,6 @@
|
|
154 |
top: 20px;
|
155 |
left: 50%;
|
156 |
transform: translateX(-50%);
|
157 |
-
background-color: #f44336;
|
158 |
-
color: white;
|
159 |
padding: 16px 24px;
|
160 |
border-radius: 4px;
|
161 |
font-size: 14px;
|
@@ -163,6 +161,16 @@
|
|
163 |
display: none;
|
164 |
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
165 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
</style>
|
167 |
</head>
|
168 |
|
@@ -250,6 +258,7 @@
|
|
250 |
function showError(message) {
|
251 |
const toast = document.getElementById('error-toast');
|
252 |
toast.textContent = message;
|
|
|
253 |
toast.style.display = 'block';
|
254 |
|
255 |
// Hide toast after 5 seconds
|
@@ -263,6 +272,18 @@
|
|
263 |
peerConnection = new RTCPeerConnection(config);
|
264 |
webrtc_id = Math.random().toString(36).substring(7);
|
265 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
266 |
try {
|
267 |
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
268 |
stream.getTracks().forEach(track => peerConnection.addTrack(track, stream));
|
@@ -293,6 +314,11 @@
|
|
293 |
// Add connection state change listener
|
294 |
peerConnection.addEventListener('connectionstatechange', () => {
|
295 |
console.log('connectionstatechange', peerConnection.connectionState);
|
|
|
|
|
|
|
|
|
|
|
296 |
updateButtonState();
|
297 |
});
|
298 |
|
@@ -375,6 +401,7 @@
|
|
375 |
|
376 |
await peerConnection.setRemoteDescription(serverResponse);
|
377 |
} catch (err) {
|
|
|
378 |
console.error('Error setting up WebRTC:', err);
|
379 |
showError('Failed to establish connection. Please try again.');
|
380 |
stop();
|
|
|
154 |
top: 20px;
|
155 |
left: 50%;
|
156 |
transform: translateX(-50%);
|
|
|
|
|
157 |
padding: 16px 24px;
|
158 |
border-radius: 4px;
|
159 |
font-size: 14px;
|
|
|
161 |
display: none;
|
162 |
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
163 |
}
|
164 |
+
|
165 |
+
.toast.error {
|
166 |
+
background-color: #f44336;
|
167 |
+
color: white;
|
168 |
+
}
|
169 |
+
|
170 |
+
.toast.warning {
|
171 |
+
background-color: #ffd700;
|
172 |
+
color: black;
|
173 |
+
}
|
174 |
</style>
|
175 |
</head>
|
176 |
|
|
|
258 |
function showError(message) {
|
259 |
const toast = document.getElementById('error-toast');
|
260 |
toast.textContent = message;
|
261 |
+
toast.className = 'toast error';
|
262 |
toast.style.display = 'block';
|
263 |
|
264 |
// Hide toast after 5 seconds
|
|
|
272 |
peerConnection = new RTCPeerConnection(config);
|
273 |
webrtc_id = Math.random().toString(36).substring(7);
|
274 |
|
275 |
+
const timeoutId = setTimeout(() => {
|
276 |
+
const toast = document.getElementById('error-toast');
|
277 |
+
toast.textContent = "Connection is taking longer than usual. Are you on a VPN?";
|
278 |
+
toast.className = 'toast warning';
|
279 |
+
toast.style.display = 'block';
|
280 |
+
|
281 |
+
// Hide warning after 5 seconds
|
282 |
+
setTimeout(() => {
|
283 |
+
toast.style.display = 'none';
|
284 |
+
}, 5000);
|
285 |
+
}, 5000);
|
286 |
+
|
287 |
try {
|
288 |
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
289 |
stream.getTracks().forEach(track => peerConnection.addTrack(track, stream));
|
|
|
314 |
// Add connection state change listener
|
315 |
peerConnection.addEventListener('connectionstatechange', () => {
|
316 |
console.log('connectionstatechange', peerConnection.connectionState);
|
317 |
+
if (peerConnection.connectionState === 'connected') {
|
318 |
+
clearTimeout(timeoutId);
|
319 |
+
const toast = document.getElementById('error-toast');
|
320 |
+
toast.style.display = 'none';
|
321 |
+
}
|
322 |
updateButtonState();
|
323 |
});
|
324 |
|
|
|
401 |
|
402 |
await peerConnection.setRemoteDescription(serverResponse);
|
403 |
} catch (err) {
|
404 |
+
clearTimeout(timeoutId);
|
405 |
console.error('Error setting up WebRTC:', err);
|
406 |
showError('Failed to establish connection. Please try again.');
|
407 |
stop();
|