Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions src/controller/base-playlist-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import {
HlsUrlParameters,
type Level,
} from '../types/level';
import { getRetryDelay, isTimeoutError } from '../utils/error-helper';
import {
getRetryDelay,
isTimeoutError,
offlineHttpStatus,
} from '../utils/error-helper';
import { computeReloadInterval, mergeDetails } from '../utils/level-helper';
import { Logger } from '../utils/logger';
import type Hls from '../hls';
Expand Down Expand Up @@ -426,20 +430,37 @@ export default class BasePlaylistController
);
this.loadPlaylist();
} else {
const delay = getRetryDelay(retryConfig, retryCount);
const offlineStatus = offlineHttpStatus(errorEvent.response?.code);
// Schedule level/track reload
this.clearTimer();
this.timer = self.setTimeout(() => this.loadPlaylist(), delay);
this.warn(
`Retrying playlist loading ${retryCount + 1}/${
retryConfig.maxNumRetry
} after "${errorDetails}" in ${delay}ms`,
);
if (offlineStatus) {
this.log(`Waiting for connection (offline)`);
errorEvent.reason = 'offline';
this.timer = self.setTimeout(() => this.checkOfflineStatus(), 1000);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why timer?
we can probably track navigator.onLine via event Listener:
window.addEventListener("online", loadPlaylist)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some browsers that do not implement that event. The fragment implementation uses polling for that very reason.

} else {
const delay = getRetryDelay(retryConfig, retryCount);
this.warn(
`Retrying playlist loading ${retryCount + 1}/${
retryConfig.maxNumRetry
} after "${errorDetails}" in ${delay}ms`,
);
this.timer = self.setTimeout(() => this.loadPlaylist(), delay);
}
}
// `levelRetry = true` used to inform other controllers that a retry is happening
errorEvent.levelRetry = true;
errorAction.resolved = true;
}
return retry;
}

private checkOfflineStatus() {
this.clearTimer();
if (offlineHttpStatus(0)) {
this.timer = self.setTimeout(() => this.checkOfflineStatus(), 1000);
} else {
this.log(`Connection restored (online)`);
this.loadPlaylist();
}
}
}
Loading