Skip to content

Commit

Permalink
Upgrade: Upgrade Shaka-player to fix infinite 401 issue (#164)
Browse files Browse the repository at this point in the history
This is effectively is an upgrade to 2.1.2 with a fix cherry-picked on
top: shaka-project/shaka-player#842. This fixes an
issue where 401s would get infinitely retried. In addition, the viewer
will bind to error-events thrown from shaka-player and propagate it so
that the preview fails faster on error
  • Loading branch information
bhh1988 authored Jun 6, 2017
1 parent a8457f0 commit 5646a79
Show file tree
Hide file tree
Showing 5 changed files with 424 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const webpackConfig = require('./webpack.karma.config');

const DOC_STATIC_ASSETS_VERSION = '0.121.1';
const MEDIA_STATIC_ASSETS_VERSION = '0.122.0';
const MEDIA_STATIC_ASSETS_VERSION = '0.127.0';
const MODEL3D_STATIC_ASSETS_VERSION = '0.125.0';
const SWF_STATIC_ASSETS_VERSION = '0.112.0';
const TEXT_STATIC_ASSETS_VERSION = '0.114.0';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const X_REP_HINT_VIDEO_MP4 = '[mp4]';
// These should be updated to match the Preview version in package.json
// whenever a file in that third party directory is updated
export const DOC_STATIC_ASSETS_VERSION = '0.121.1';
export const MEDIA_STATIC_ASSETS_VERSION = '0.122.0';
export const MEDIA_STATIC_ASSETS_VERSION = '0.127.0';
export const MODEL3D_STATIC_ASSETS_VERSION = '0.125.0';
export const SWF_STATIC_ASSETS_VERSION = '0.112.0';
export const TEXT_STATIC_ASSETS_VERSION = '0.114.0';
Expand Down
20 changes: 20 additions & 0 deletions src/lib/viewers/media/DashViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ const MANIFEST = 'manifest.mpd';
this.adapting = true;
this.player = new shaka.Player(this.mediaEl);
this.player.addEventListener('adaptation', this.adaptationHandler);
this.player.addEventListener('error', this.shakaErrorHandler);
this.player.configure({
abr: {
enabled: true
Expand Down Expand Up @@ -293,6 +294,25 @@ const MANIFEST = 'manifest.mpd';
this.hideLoadingIcon();
}

/**
* Handles errors thrown by shaka player. See https://shaka-player-demo.appspot.com/docs/api/shaka.util.Error.html
*
* @private
* @param {Object} shakaError
* @return {void}
*/
shakaErrorHandler(shakaError) {
const error = new Error(
`Shaka error. Code = ${shakaError.detail.code}, Category = ${shakaError.detail.category}, Severity = ${shakaError.detail.severity}`
);
error.displayMessage = __('error_refresh');

if (shakaError.detail.severity > 1) {
// critical error
this.emit('error', error);
}
}

/**
* Adds event listeners to the media controls.
* Makes changes to the media element.
Expand Down
31 changes: 31 additions & 0 deletions src/lib/viewers/media/__tests__/DashViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ describe('lib/viewers/media/DashViewer', () => {
dash.mediaUrl = 'url';
sandbox.stub(shaka, 'Player').returns(dash.player);
stubs.mockPlayer.expects('addEventListener').withArgs('adaptation', sinon.match.func);
stubs.mockPlayer.expects('addEventListener').withArgs('error', sinon.match.func);
stubs.mockPlayer.expects('configure');
stubs.mockPlayer.expects('load').withArgs('url');

Expand Down Expand Up @@ -347,6 +348,36 @@ describe('lib/viewers/media/DashViewer', () => {
});
});

describe('shakaErrorHandler()', () => {
it('should emit error on critical shaka errors', () => {
const shakaError = {
detail: {
severity: 2, // critical severity
category: 1,
code: 1100
}
};

dash.shakaErrorHandler(shakaError);

expect(dash.emit).to.be.calledWith('error');
});

it('should not emit error on recoverable shaka errors', () => {
const shakaError = {
detail: {
severity: 1, // recoverable severity
category: 1,
code: 1100
}
};

dash.shakaErrorHandler(shakaError);

expect(dash.emit).to.not.be.called;
});
});

describe('addEventListenersForMediaControls()', () => {
const listenerFunc = DashViewer.prototype.addEventListenersForMediaControls;

Expand Down
Loading

0 comments on commit 5646a79

Please sign in to comment.