Skip to content

Commit

Permalink
refactor: add support for future Video.js 8.x (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
misteroneill committed Aug 24, 2022
1 parent d6fbf30 commit 6a19aba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
],
"dependencies": {
"global": "^4.3.2",
"video.js": "^6 || ^7"
"video.js": "^6 || ^7 || ^8"
},
"devDependencies": {
"conventional-changelog-cli": "^2.0.12",
Expand Down
10 changes: 4 additions & 6 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
default as msPrefixed,
PLAYREADY_KEY_SYSTEM
} from './ms-prefixed';
import { arrayBuffersEqual, arrayBufferFrom } from './utils';
import { arrayBuffersEqual, arrayBufferFrom, merge } from './utils';
import {version as VERSION} from '../package.json';

export const hasSession = (sessions, initData) => {
Expand Down Expand Up @@ -156,7 +156,7 @@ export const handleMsNeedKeyEvent = (event, options, sessions, eventBus) => {
};

export const getOptions = (player) => {
return videojs.mergeOptions(player.currentSource(), player.eme.options);
return merge(player.currentSource(), player.eme.options);
};

/**
Expand Down Expand Up @@ -349,7 +349,7 @@ const eme = function(options = {}) {
initializeMediaKeys(emeOptions = {}, callback = function() {}, suppressErrorIfPossible = false) {
// TODO: this should be refactored and renamed to be less tied
// to encrypted events
const mergedEmeOptions = videojs.mergeOptions(
const mergedEmeOptions = merge(
player.currentSource(),
options,
emeOptions
Expand Down Expand Up @@ -406,9 +406,7 @@ const eme = function(options = {}) {
};

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

registerPlugin('eme', eme);
videojs.registerPlugin('eme', eme);

// Include the version number.
eme.VERSION = VERSION;
Expand Down
10 changes: 9 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,16 @@ export const arrayBufferFrom = (bufferOrTypedArray) => {
return bufferOrTypedArray;
};

// Normalize between Video.js 6/7 (videojs.mergeOptions) and 8 (videojs.obj.merge).
export const merge = (...args) => {
const context = videojs.obj || videojs;
const fn = context.merge || context.mergeOptions;

return fn.apply(context, args);
};

export const mergeAndRemoveNull = (...args) => {
const result = videojs.mergeOptions(...args);
const result = merge(...args);

// Any header whose value is `null` will be removed.
Object.keys(result).forEach(k => {
Expand Down

0 comments on commit 6a19aba

Please sign in to comment.