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
Merged

feat: added API to set media keys directly #61

merged 15 commits into from
Oct 24, 2018

Conversation

forbesjo
Copy link
Contributor

This is to start a discussion/review around a new API to set up EME directly. This will allow an end user to set up EME on the video element before data is loaded.

src/plugin.js Outdated
@@ -237,6 +237,20 @@ const onPlayerReady = (player) => {
const eme = function(options = {}) {
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.

Copy link
Contributor

@gesinger gesinger left a comment

Choose a reason for hiding this comment

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

Would also be good to add initializeMediaKeys to the README

src/plugin.js Outdated
@@ -231,18 +231,45 @@ const onPlayerReady = (player) => {
* to you; if not, remove the wait for "ready"!
*
* @function eme
* @param {Object} [player]
* A playerobject.
Copy link
Contributor

Choose a reason for hiding this comment

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

player object

src/plugin.js Outdated
const eme = function(options = {}) {
this.eme.options = options;
const eme = function(player, options = {}) {
const initializeMediaKeys = (emeOptions = {}) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be easier to read (and potentially test) if we make this a top level function.

src/plugin.js Outdated
this.eme.options = options;
const eme = function(player, options = {}) {
const initializeMediaKeys = (emeOptions = {}) => {
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.


this.player.eme();

// testing the rejection path because this isn't a real session
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this testing a rejection?

src/plugin.js Outdated
* An object of eme plugin options.
*/
const initializeMediaKeys = (player, emeOptions = {}) => {
// TODO: this should be refactored
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we have the TODO below we can probably remove this one.

src/plugin.js Outdated
// TODO: this should be refactored and renamed to be less tied
// to encrypted events
if (player.tech_.el_.setMediaKeys) {
return handleEncryptedEvent(mockEncryptedEvent, emeOptions, player.eme.sessions, player.tech_);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth catching the promise rejection here since the mock is always expected behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is expected to fail if you don't provide enough capability information for EME so I believe the error should bubble up

README.md Outdated Show resolved Hide resolved
src/plugin.js Outdated Show resolved Hide resolved
src/plugin.js Outdated Show resolved Hide resolved
src/plugin.js Outdated Show resolved Hide resolved
src/plugin.js Show resolved Hide resolved
src/plugin.js Outdated Show resolved Hide resolved
@ldayananda ldayananda self-assigned this Oct 22, 2018
src/plugin.js Outdated
* @param {Object} [options={}]
* An object of options left to the plugin author to define.
*/
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

@ldayananda
Copy link

As a last piece of CR feedback, since initializeMediaKeys can return a promise or nothing, we should at least mention in the README that you will get a Promise on browsers that have promises.

Copy link

@ldayananda ldayananda left a comment

Choose a reason for hiding this comment

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

Tested on FF, Chrome, Safari, IE, Edge


this.player.eme();

// testing the rejection path because this isn't a real session

Choose a reason for hiding this comment

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

you can delete this now!

@forbesjo forbesjo merged commit 57701b9 into master Oct 24, 2018
@forbesjo forbesjo deleted the setup branch October 24, 2018 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants