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: added API to set media keys directly #61

Merged
merged 15 commits into from
Oct 24, 2018
14 changes: 14 additions & 0 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,20 @@ const onPlayerReady = (player) => {
const eme = function(options = {}) {

Choose a reason for hiding this comment

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

This worked for me:

const eme = function(options = {}) {
  const player = this;

  this.ready(() => onPlayerReady(this));

  this.eme = {
    initializeMediaKeys(emeOptions = {}) {
      const mergedEmeOptions = videojs.mergeOptions(
        player.currentSource(),
        options,
        emeOptions
      );

      return initializeMediaKeys(player, mergedEmeOptions);
    },
    options
  };
};

// Register the plugin with video.js.
const registerPlugin = videojs.registerPlugin || videojs.plugin;

registerPlugin('eme', eme);

to be clear, I'm trying to avoid an anonymous function being the plugin factory here

this.eme.options = options;

this.eme.init = (config) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to consider a more precise name. Maybe something as direct as initializeMediaKeys, and provide a comment/docs around why you'd want to use this API.

const e = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should use a more descriptive variable name. Maybe something like mockEncryptedEvent or something alongside a comment.

initDataType: '',
initData: null,
target: this.tech_.el_
};

if (this.tech_.el_.setMediaKeys) {
handleEncryptedEvent(e, config, this.eme.sessions, this.tech_);
} else if (this.tech_.el_.msSetMediaKeys) {
handleMsNeedKeyEvent(e, config, this.eme.sessions, this.tech_);
}
};

this.ready(() => onPlayerReady(this));
};

Expand Down