Spaces:
Running
Running
Upload kimi-utils.js
Browse files- kimi-js/kimi-utils.js +27 -0
kimi-js/kimi-utils.js
CHANGED
|
@@ -1532,6 +1532,15 @@ class KimiVideoManager {
|
|
| 1532 |
}
|
| 1533 |
this._recentFailures.set(videoSrc, performance.now());
|
| 1534 |
this._consecutiveErrorCount++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1535 |
if (videoSrc !== fallbackVideo) {
|
| 1536 |
// Try fallback video
|
| 1537 |
this._fallbackIndex = (this._fallbackIndex + 1) % this._fallbackPool.length; // advance for next time
|
|
@@ -1594,6 +1603,24 @@ class KimiVideoManager {
|
|
| 1594 |
}, this._timeoutExtension);
|
| 1595 |
return;
|
| 1596 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1597 |
if (this.inactiveVideo.readyState >= 2) {
|
| 1598 |
onReady();
|
| 1599 |
} else {
|
|
|
|
| 1532 |
}
|
| 1533 |
this._recentFailures.set(videoSrc, performance.now());
|
| 1534 |
this._consecutiveErrorCount++;
|
| 1535 |
+
// Stop runaway fallback loop: pause if too many sequential errors relative to pool size
|
| 1536 |
+
if (this._fallbackPool && this._consecutiveErrorCount >= this._fallbackPool.length * 2) {
|
| 1537 |
+
console.error("Temporarily pausing fallback loop after repeated failures. Retrying in 2s.");
|
| 1538 |
+
setTimeout(() => {
|
| 1539 |
+
this._consecutiveErrorCount = 0;
|
| 1540 |
+
this.loadAndSwitchVideo(fallbackVideo, "high");
|
| 1541 |
+
}, 2000);
|
| 1542 |
+
return;
|
| 1543 |
+
}
|
| 1544 |
if (videoSrc !== fallbackVideo) {
|
| 1545 |
// Try fallback video
|
| 1546 |
this._fallbackIndex = (this._fallbackIndex + 1) % this._fallbackPool.length; // advance for next time
|
|
|
|
| 1603 |
}, this._timeoutExtension);
|
| 1604 |
return;
|
| 1605 |
}
|
| 1606 |
+
// Grace retry: still fetching over network (networkState=2) with no data (readyState=0)
|
| 1607 |
+
if (
|
| 1608 |
+
this.inactiveVideo.networkState === 2 &&
|
| 1609 |
+
this.inactiveVideo.readyState === 0 &&
|
| 1610 |
+
(this._graceRetryCounts?.[videoSrc] || 0) < 1
|
| 1611 |
+
) {
|
| 1612 |
+
if (!this._graceRetryCounts) this._graceRetryCounts = {};
|
| 1613 |
+
this._graceRetryCounts[videoSrc] = (this._graceRetryCounts[videoSrc] || 0) + 1;
|
| 1614 |
+
const extra = this._timeoutExtension + 600;
|
| 1615 |
+
console.debug(`Grace retry for ${videoSrc} (network loading). Extending by ${extra}ms`);
|
| 1616 |
+
this._loadTimeout = setTimeout(() => {
|
| 1617 |
+
if (!fired) {
|
| 1618 |
+
if (this.inactiveVideo.readyState >= 2) onReady();
|
| 1619 |
+
else this._currentErrorHandler();
|
| 1620 |
+
}
|
| 1621 |
+
}, extra);
|
| 1622 |
+
return;
|
| 1623 |
+
}
|
| 1624 |
if (this.inactiveVideo.readyState >= 2) {
|
| 1625 |
onReady();
|
| 1626 |
} else {
|