Added network timeout retry logic for direct streams
This commit is contained in:
@@ -119,15 +119,39 @@ class VideoPlayer {
|
|||||||
if (data.fatal) {
|
if (data.fatal) {
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case Hls.ErrorTypes.NETWORK_ERROR:
|
case Hls.ErrorTypes.NETWORK_ERROR:
|
||||||
// If it's a network error and we haven't tried the proxy yet, try it
|
// Track network retry attempts
|
||||||
if (this.currentChannel && !this.isUsingProxy) {
|
this.networkRetryCount = (this.networkRetryCount || 0) + 1;
|
||||||
console.log('Network error detected, trying via proxy...');
|
const now = Date.now();
|
||||||
const proxiedUrl = this.getProxiedUrl(this.currentUrl);
|
const timeSinceLastNetworkError = now - (this.lastNetworkErrorTime || 0);
|
||||||
|
this.lastNetworkErrorTime = now;
|
||||||
|
|
||||||
|
// Reset retry count if it's been more than 30 seconds since last error
|
||||||
|
if (timeSinceLastNetworkError > 30000) {
|
||||||
|
this.networkRetryCount = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Network error (attempt ${this.networkRetryCount}/3):`, data.details);
|
||||||
|
|
||||||
|
if (this.networkRetryCount <= 3 && !this.isUsingProxy) {
|
||||||
|
// Retry with increasing delay (1s, 2s, 3s)
|
||||||
|
const retryDelay = this.networkRetryCount * 1000;
|
||||||
|
console.log(`[HLS] Retrying in ${retryDelay}ms...`);
|
||||||
|
setTimeout(() => {
|
||||||
|
if (this.hls) {
|
||||||
|
this.hls.startLoad();
|
||||||
|
}
|
||||||
|
}, retryDelay);
|
||||||
|
} else if (!this.isUsingProxy) {
|
||||||
|
// After 3 retries, try proxy
|
||||||
|
console.log('[HLS] Max retries reached, switching to proxy...');
|
||||||
|
this.networkRetryCount = 0;
|
||||||
this.isUsingProxy = true;
|
this.isUsingProxy = true;
|
||||||
|
const proxiedUrl = this.getProxiedUrl(this.currentUrl);
|
||||||
this.hls.loadSource(proxiedUrl);
|
this.hls.loadSource(proxiedUrl);
|
||||||
this.hls.startLoad();
|
this.hls.startLoad();
|
||||||
} else {
|
} else {
|
||||||
console.log('Network error, attempting recovery...');
|
// Already using proxy, just retry
|
||||||
|
console.log('[HLS] Network error on proxy, retrying...');
|
||||||
this.hls.startLoad();
|
this.hls.startLoad();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user