Skip to content

Commit

Permalink
Save options from contribEme calls
Browse files Browse the repository at this point in the history
  • Loading branch information
gesinger committed Aug 23, 2016
1 parent c6718d8 commit 66104d1
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import videojs from 'video.js';
import {standard5July2016} from './eme';
import fairplay from './fairplay';

let savedOptions;

const handleEncryptedEvent = (event, options) => {
standard5July2016({
video: event.target,
Expand Down Expand Up @@ -30,19 +32,19 @@ const handleWebKitNeedKeyEvent = (event, options) => {
* @param {Player} player
* @param {Object} [options={}]
*/
const onPlayerReady = (player, options) => {
const onPlayerReady = (player) => {
if (!player.tech_.el_.techName_ === 'Html5') {
return;
}

// Support EME 05 July 2016
player.tech_.el_.addEventListener('encrypted', (event) => {
handleEncryptedEvent(event, options);
handleEncryptedEvent(event, savedOptions);
});
// Support Safari EME with FairPlay
// (also used in early Chrome or Chrome with EME disabled flag)
player.tech_.el_.addEventListener('webkitneedkey', (event) => {
handleWebKitNeedKeyEvent(event, options);
handleWebKitNeedKeyEvent(event, savedOptions);
});
};

Expand All @@ -59,9 +61,14 @@ const onPlayerReady = (player, options) => {
* An object of options left to the plugin author to define.
*/
const contribEme = function(options) {
this.ready(() => {
onPlayerReady(this, videojs.mergeOptions({}, options));
});
// savedOptions doubles as a state to tell us if we've listened for player ready yet
if (!savedOptions) {
this.ready(() => {
onPlayerReady(this);
});
}

savedOptions = options;
};

// Register the plugin with video.js.
Expand Down

0 comments on commit 66104d1

Please sign in to comment.