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

Upgrade: Upgrade Shaka-player to fix infinite 401 issue #164

Merged
merged 2 commits into from
Jun 6, 2017
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
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);
Copy link
Contributor

@tonyjin tonyjin Jun 6, 2017

Choose a reason for hiding this comment

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

In the future, this.shakaErrorHandler should be self-bound in the constructor. It'll look like this:

class DashViewer extends VideoBaseViewer {
    constructor() {
        super();
    
        // Bind event handlers
        this.shakaErrorHandler = this.shakaErrorHandler.bind(this);
        this.adaptationHandler = this.adaptationHandler.bind(this);
    }

This way, we can remove autobind. This pattern follows #4 described here: https://medium.freecodecamp.com/react-binding-patterns-5-approaches-for-handling-this-92c651b5af56. We can't use #5 due to issues with arrow class properties and inheritance (React doesn't use inheritance, but composition). #1 isn't relevant. #2 has some performance implications and is also easy to forget to add the .bind. #3 has the same issues as #2 and also can't be unbound.

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