Spaces:
Running
Running
Update index.html
Browse files- index.html +68 -14
index.html
CHANGED
@@ -439,9 +439,14 @@
|
|
439 |
}, 5000);
|
440 |
}
|
441 |
|
442 |
-
async
|
443 |
const config = __RTC_CONFIGURATION__;
|
444 |
peerConnection = new RTCPeerConnection(config);
|
|
|
|
|
|
|
|
|
|
|
445 |
const timeoutId = setTimeout(() => {
|
446 |
const toast = document.getElementById('error-toast');
|
447 |
toast.textContent = "์ฐ๊ฒฐ์ด ํ์๋ณด๋ค ์ค๋ ๊ฑธ๋ฆฌ๊ณ ์์ต๋๋ค. VPN์ ์ฌ์ฉ ์ค์ด์ ๊ฐ์?";
|
@@ -495,6 +500,27 @@
|
|
495 |
clearTimeout(timeoutId);
|
496 |
const toast = document.getElementById('error-toast');
|
497 |
toast.style.display = 'none';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
498 |
}
|
499 |
updateButtonState();
|
500 |
});
|
@@ -517,11 +543,25 @@
|
|
517 |
return;
|
518 |
}
|
519 |
await peerConnection.setRemoteDescription(serverResponse);
|
|
|
|
|
|
|
|
|
|
|
520 |
const eventSource = new EventSource('/outputs?webrtc_id=' + webrtc_id);
|
|
|
|
|
521 |
eventSource.addEventListener("output", (event) => {
|
522 |
const eventJson = JSON.parse(event.data);
|
523 |
addMessage("assistant", eventJson.content);
|
524 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
525 |
} catch (err) {
|
526 |
clearTimeout(timeoutId);
|
527 |
console.error('Error setting up WebRTC:', err);
|
@@ -549,21 +589,35 @@
|
|
549 |
audioSource = null;
|
550 |
}
|
551 |
if (peerConnection) {
|
552 |
-
|
553 |
-
peerConnection.getTransceivers
|
554 |
-
|
555 |
-
transceiver.stop
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
peerConnection.getSenders
|
561 |
-
|
562 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
563 |
}
|
564 |
-
|
565 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
566 |
}
|
|
|
567 |
updateButtonState();
|
568 |
audioLevel = 0;
|
569 |
}
|
|
|
439 |
}, 5000);
|
440 |
}
|
441 |
|
442 |
+
async function setupWebRTC() {
|
443 |
const config = __RTC_CONFIGURATION__;
|
444 |
peerConnection = new RTCPeerConnection(config);
|
445 |
+
|
446 |
+
// ์ฐ๊ฒฐ ์ฌ์๋ ๋ฉ์ปค๋์ฆ ์ถ๊ฐ
|
447 |
+
let retryCount = 0;
|
448 |
+
const maxRetries = 3;
|
449 |
+
|
450 |
const timeoutId = setTimeout(() => {
|
451 |
const toast = document.getElementById('error-toast');
|
452 |
toast.textContent = "์ฐ๊ฒฐ์ด ํ์๋ณด๋ค ์ค๋ ๊ฑธ๋ฆฌ๊ณ ์์ต๋๋ค. VPN์ ์ฌ์ฉ ์ค์ด์ ๊ฐ์?";
|
|
|
500 |
clearTimeout(timeoutId);
|
501 |
const toast = document.getElementById('error-toast');
|
502 |
toast.style.display = 'none';
|
503 |
+
retryCount = 0; // ์ฐ๊ฒฐ ์ฑ๊ณต ์ ์ฌ์๋ ์นด์ดํธ ์ด๊ธฐํ
|
504 |
+
} else if (peerConnection.connectionState === 'failed' || peerConnection.connectionState === 'disconnected') {
|
505 |
+
if (retryCount < maxRetries) {
|
506 |
+
retryCount++;
|
507 |
+
console.log(`์ฐ๊ฒฐ ์คํจ, ์ฌ์๋ ์ค... (${retryCount}/${maxRetries})`);
|
508 |
+
|
509 |
+
// ํ์ฌ ์ฐ๊ฒฐ ์ ๋ฆฌ
|
510 |
+
if (peerConnection) {
|
511 |
+
peerConnection.close();
|
512 |
+
}
|
513 |
+
|
514 |
+
// ์ ์ ํ ์ฌ์ฐ๊ฒฐ ์๋
|
515 |
+
setTimeout(() => {
|
516 |
+
if (peerConnection.connectionState !== 'connected') {
|
517 |
+
showError(`์ฐ๊ฒฐ ์ฌ์๋ ์ค... (${retryCount}/${maxRetries})`);
|
518 |
+
setupWebRTC();
|
519 |
+
}
|
520 |
+
}, 2000); // 2์ด ํ ์ฌ์๋
|
521 |
+
} else {
|
522 |
+
showError('์ฐ๊ฒฐ์ ์คํจํ์ต๋๋ค. ๋ธ๋ผ์ฐ์ ๋ฅผ ์๋ก๊ณ ์นจ ํ ๋ค์ ์๋ํด์ฃผ์ธ์.');
|
523 |
+
}
|
524 |
}
|
525 |
updateButtonState();
|
526 |
});
|
|
|
543 |
return;
|
544 |
}
|
545 |
await peerConnection.setRemoteDescription(serverResponse);
|
546 |
+
// ์ด์ EventSource๊ฐ ์์ผ๋ฉด ๋ซ๊ธฐ
|
547 |
+
if (window.currentEventSource) {
|
548 |
+
window.currentEventSource.close();
|
549 |
+
}
|
550 |
+
|
551 |
const eventSource = new EventSource('/outputs?webrtc_id=' + webrtc_id);
|
552 |
+
window.currentEventSource = eventSource; // ์ ์ญ์ผ๋ก ์ ์ฅํ์ฌ ๋์ค์ ์ ๋ฆฌํ ์ ์๋๋ก ํจ
|
553 |
+
|
554 |
eventSource.addEventListener("output", (event) => {
|
555 |
const eventJson = JSON.parse(event.data);
|
556 |
addMessage("assistant", eventJson.content);
|
557 |
});
|
558 |
+
|
559 |
+
eventSource.addEventListener("error", (event) => {
|
560 |
+
console.error("EventSource ์ค๋ฅ:", event);
|
561 |
+
if (event.target.readyState === EventSource.CLOSED) {
|
562 |
+
console.log("EventSource ์ฐ๊ฒฐ์ด ๋ซํ์ต๋๋ค.");
|
563 |
+
}
|
564 |
+
});
|
565 |
} catch (err) {
|
566 |
clearTimeout(timeoutId);
|
567 |
console.error('Error setting up WebRTC:', err);
|
|
|
589 |
audioSource = null;
|
590 |
}
|
591 |
if (peerConnection) {
|
592 |
+
try {
|
593 |
+
if (peerConnection.getTransceivers) {
|
594 |
+
peerConnection.getTransceivers().forEach(transceiver => {
|
595 |
+
if (transceiver.stop) {
|
596 |
+
transceiver.stop();
|
597 |
+
}
|
598 |
+
});
|
599 |
+
}
|
600 |
+
if (peerConnection.getSenders) {
|
601 |
+
peerConnection.getSenders().forEach(sender => {
|
602 |
+
if (sender.track && sender.track.stop) sender.track.stop();
|
603 |
+
});
|
604 |
+
}
|
605 |
+
console.log('closing connection');
|
606 |
+
peerConnection.close();
|
607 |
+
} catch (error) {
|
608 |
+
console.error('Error during connection cleanup:', error);
|
609 |
}
|
610 |
+
|
611 |
+
// ํด๋ฆฐ์
์งํ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ๋๋ผ๋ null๋ก ์ค์ ํ์ฌ ์ ์ฐ๊ฒฐ์ด ๊ฐ๋ฅํ๊ฒ ํจ
|
612 |
+
peerConnection = null;
|
613 |
+
}
|
614 |
+
|
615 |
+
// EventSource ๋ซ๊ธฐ (์๋ ๊ฒฝ์ฐ)
|
616 |
+
if (window.currentEventSource) {
|
617 |
+
window.currentEventSource.close();
|
618 |
+
window.currentEventSource = null;
|
619 |
}
|
620 |
+
|
621 |
updateButtonState();
|
622 |
audioLevel = 0;
|
623 |
}
|