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

feat: Enable variant failover for BAD_HTTP_STATUS and TIMEOUT #4769

Merged
merged 1 commit into from
Dec 1, 2022
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

Adrián Gómez Llorente <[email protected]>
AdsWizz <*@adswizz.com>
Albin Larsson <[email protected]>
Alex Jones <[email protected]>
Alugha GmbH <*@alugha.com>
Alvaro Velad Galvan <[email protected]>
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Aaron Vaage <[email protected]>
Adrián Gómez Llorente <[email protected]>
Agajan Jumakuliyev <[email protected]>
Aidan Ridley <[email protected]>
Albin Larsson <[email protected]>
Alex Jones <[email protected]>
Alvaro Velad Galvan <[email protected]>
Amila Sampath <[email protected]>
Expand Down
8 changes: 6 additions & 2 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -6030,8 +6030,12 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
* @private
*/
tryToRecoverFromError_(error) {
if ((error.code != shaka.util.Error.Code.HTTP_ERROR &&
error.code != shaka.util.Error.Code.SEGMENT_MISSING) ||
if (![
shaka.util.Error.Code.HTTP_ERROR,
shaka.util.Error.Code.SEGMENT_MISSING,
shaka.util.Error.Code.BAD_HTTP_STATUS,
shaka.util.Error.Code.TIMEOUT,
].includes(error.code) ||
error.category != shaka.util.Error.Category.NETWORK) {
return false;
}
Expand Down
26 changes: 22 additions & 4 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,18 @@ describe('Player', () => {
shaka.util.Error.Severity.RECOVERABLE,
shaka.util.Error.Category.NETWORK,
shaka.util.Error.Code.HTTP_ERROR);
const nonHttpError = new shaka.util.Error(
const badHttpStatusError = new shaka.util.Error(
shaka.util.Error.Severity.RECOVERABLE,
shaka.util.Error.Category.NETWORK,
shaka.util.Error.Code.BAD_HTTP_STATUS);
const timeoutError = new shaka.util.Error(
shaka.util.Error.Severity.RECOVERABLE,
shaka.util.Error.Category.NETWORK,
shaka.util.Error.Code.TIMEOUT);
const operationAbortedError = new shaka.util.Error(
shaka.util.Error.Severity.RECOVERABLE,
shaka.util.Error.Category.NETWORK,
shaka.util.Error.Code.OPERATION_ABORTED);
/** @type {?jasmine.Spy} */
let dispatchEventSpy;

Expand All @@ -371,9 +379,9 @@ describe('Player', () => {
dispatchEventSpy.calls.reset();
});

it('does not handle non NETWORK HTTP_ERROR', () => {
onErrorCallback(nonHttpError);
expect(nonHttpError.handled).toBeFalsy();
it('does not handle non recoverable network error', () => {
onErrorCallback(operationAbortedError);
expect(operationAbortedError.handled).toBeFalsy();
expect(player.dispatchEvent).toHaveBeenCalled();
});

Expand Down Expand Up @@ -440,6 +448,16 @@ describe('Player', () => {
expect(httpError.handled).toBeTruthy();
});

it('handles BAD_HTTP_STATUS', () => {
onErrorCallback(badHttpStatusError);
expect(badHttpStatusError.handled).toBeTruthy();
});

it('handles TIMEOUT', () => {
onErrorCallback(timeoutError);
expect(timeoutError.handled).toBeTruthy();
});

it('does not dispatch any error', () => {
onErrorCallback(httpError);
expect(dispatchEventSpy).not.toHaveBeenCalled();
Expand Down