Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live reload level switch and error handling improvements #5317

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
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
29 changes: 16 additions & 13 deletions src/controller/base-playlist-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default class BasePlaylistController implements NetworkComponentAPI {
if (!this.canLoad || !details.live) {
return;
}
let deliveryDirectives: HlsUrlParameters;
let deliveryDirectives: HlsUrlParameters | undefined;
let msn: number | undefined = undefined;
let part: number | undefined = undefined;
if (details.canBlockReload && details.endSN && details.advanced) {
Expand Down Expand Up @@ -224,7 +224,7 @@ export default class BasePlaylistController implements NetworkComponentAPI {
this.loadPlaylist(deliveryDirectives);
return;
}
} else {
} else if (details.canBlockReload) {
deliveryDirectives = this.getDeliveryDirectives(
details,
data.deliveryDirectives,
Expand All @@ -239,9 +239,7 @@ export default class BasePlaylistController implements NetworkComponentAPI {
details,
distanceToLiveEdgeMs
);
if (!details.updated) {
this.requestScheduled = -1;
} else if (now > this.requestScheduled + reloadInterval) {
if (details.updated && now > this.requestScheduled + reloadInterval) {
this.requestScheduled = stats.loading.start;
}

Expand All @@ -250,10 +248,13 @@ export default class BasePlaylistController implements NetworkComponentAPI {
stats.loading.first +
reloadInterval -
(details.partTarget * 1000 || 1000);
} else {
this.requestScheduled =
(this.requestScheduled === -1 ? now : this.requestScheduled) +
reloadInterval;
} else if (
this.requestScheduled === -1 ||
this.requestScheduled + reloadInterval < now
) {
this.requestScheduled = now;
} else if (this.requestScheduled - now <= 0) {
this.requestScheduled += reloadInterval;
}
let estimatedTimeUntilUpdate = this.requestScheduled - now;
estimatedTimeUntilUpdate = Math.max(0, estimatedTimeUntilUpdate);
Expand All @@ -262,19 +263,21 @@ export default class BasePlaylistController implements NetworkComponentAPI {
estimatedTimeUntilUpdate
)} ms`
);
// this.log(
// `live reload ${details.updated ? 'REFRESHED' : 'MISSED'}
// this.log(
// `live reload ${details.updated ? 'REFRESHED' : 'MISSED'}
// reload in ${estimatedTimeUntilUpdate / 1000}
// round trip ${(stats.loading.end - stats.loading.start) / 1000}
// diff ${
// (reloadInterval -
// (estimatedTimeUntilUpdate + stats.loading.end - stats.loading.start)) /
// (estimatedTimeUntilUpdate +
// stats.loading.end -
// stats.loading.start)) /
// 1000
// }
// reload interval ${reloadInterval / 1000}
// target duration ${details.targetduration}
// distance to edge ${distanceToLiveEdgeMs / 1000}`
// );
// );

this.timer = self.setTimeout(
() => this.loadPlaylist(deliveryDirectives),
Expand Down
5 changes: 4 additions & 1 deletion src/utils/error-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,8 @@ export function shouldRetry(

export function retryForHttpStatus(httpStatus: number | undefined) {
// Do not retry on status 4xx, status 0 (CORS error), or undefined (decrypt/gap/parse error)
return !!httpStatus && (httpStatus < 400 || httpStatus > 499);
return (
(httpStatus === 0 && navigator.onLine === false) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

cc @robwalch I recent meet this issue. I don't get the point. Are we going to retry under user's good network? I means

(httpStatus === 0 && navigator.onLine)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It means retry later when network is disabled or completely unavailable.

A status of 0 where online equals true is typically a CORS error and should not be retried.

(!!httpStatus && (httpStatus < 400 || httpStatus > 499))
);
}