From 73ad9dcb1f1d11029184c4053626d83dab93baa4 Mon Sep 17 00:00:00 2001 From: Gary Katsevman Date: Tue, 19 Oct 2021 17:07:53 -0400 Subject: [PATCH 1/2] fix: convert initData to a string This is to help get around the change in data type of initData between the legacy API and the standards API. In the legacy API, the initData was a Uint8Array but needed to be converted to a Uint16Array to be able to toString it. In the standards API, initData is an ArrayBuffer but can be converted to a Uint8Array to be able to toString it. We now do this string conversion for you so that you can just use the contentId and not need to figure out whether legacy or standard API is used. BREAKING CHANGE: getContentId will now receive a string representation of the initData --- README.md | 4 ++-- src/eme.js | 4 ++-- src/fairplay.js | 8 ++++---- src/utils.js | 4 ++++ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d0930ca..6f567c3 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ or You can control the license and certificate request processes by providing the following methods instead of the properties discussed above: * `getCertificate()` - Allows asynchronous retrieval of a certificate. -* `getContentId()` - Allows synchronous retrieval of a content ID. +* `getContentId()` - Allows synchronous retrieval of a content ID. It takes `emeOptions`, as well as the `initData` converted into a String. * `getLicense()` - Allows asynchronous retrieval of a license. ```js @@ -149,7 +149,7 @@ You can control the license and certificate request processes by providing the f // if err, callback(err) // if success, callback(null, certificate) }, - getContentId: function(emeOptions, initData) { + getContentId: function(emeOptions, contentId) { // return content ID }, getLicense: function(emeOptions, contentId, keyMessage, callback) { diff --git a/src/eme.js b/src/eme.js index 97781c2..8c70c7a 100644 --- a/src/eme.js +++ b/src/eme.js @@ -1,7 +1,7 @@ import videojs from 'video.js'; import { requestPlayreadyLicense } from './playready'; import window from 'global/window'; -import {mergeAndRemoveNull} from './utils'; +import {uint8ArrayToString, mergeAndRemoveNull} from './utils'; import {httpResponseHandler} from './http-handler.js'; import { defaultGetCertificate as defaultFairplayGetCertificate, @@ -398,7 +398,7 @@ export const standard5July2016 = ({ } const contentId = keySystemOptions.getContentId ? - keySystemOptions.getContentId(options, initData) : null; + keySystemOptions.getContentId(options, uint8ArrayToString(initData)) : null; if (typeof video.mediaKeysObject === 'undefined') { // Prevent entering this path again. diff --git a/src/fairplay.js b/src/fairplay.js index c5ec89c..3009957 100644 --- a/src/fairplay.js +++ b/src/fairplay.js @@ -7,7 +7,7 @@ */ import videojs from 'video.js'; import window from 'global/window'; -import {stringToUint16Array, uint8ArrayToString, getHostnameFromUri, mergeAndRemoveNull} from './utils'; +import {stringToUint16Array, uint16ArrayToString, getHostnameFromUri, mergeAndRemoveNull} from './utils'; import {httpResponseHandler} from './http-handler.js'; export const FAIRPLAY_KEY_SYSTEM = 'com.apple.fps.1_0'; @@ -128,8 +128,8 @@ export const defaultGetCertificate = (fairplayOptions) => { }; }; -export const defaultGetContentId = (emeOptions, initData) => { - return getHostnameFromUri(uint8ArrayToString(initData)); +export const defaultGetContentId = (emeOptions, contentId) => { + return getHostnameFromUri(contentId); }; export const defaultGetLicense = (fairplayOptions) => { @@ -174,7 +174,7 @@ const fairplay = ({video, initData, options, eventBus}) => { initData, getLicense, options, - contentId: getContentId(options, initData), + contentId: getContentId(options, uint16ArrayToString(initData)), eventBus }); }); diff --git a/src/utils.js b/src/utils.js index c5f990e..b44394a 100644 --- a/src/utils.js +++ b/src/utils.js @@ -17,6 +17,10 @@ export const uint8ArrayToString = (array) => { return String.fromCharCode.apply(null, new Uint8Array(array.buffer || array)); }; +export const uint16ArrayToString = (array) => { + return String.fromCharCode.apply(null, new Uint16Array(array.buffer || array)); +}; + export const getHostnameFromUri = (uri) => { const link = document.createElement('a'); From f47cb3c5fe54cc38304c0dab3f270a1c048efa22 Mon Sep 17 00:00:00 2001 From: Gary Katsevman Date: Wed, 20 Oct 2021 11:37:27 -0400 Subject: [PATCH 2/2] contentId->initDataString --- src/fairplay.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fairplay.js b/src/fairplay.js index 3009957..591b902 100644 --- a/src/fairplay.js +++ b/src/fairplay.js @@ -128,8 +128,8 @@ export const defaultGetCertificate = (fairplayOptions) => { }; }; -export const defaultGetContentId = (emeOptions, contentId) => { - return getHostnameFromUri(contentId); +export const defaultGetContentId = (emeOptions, initDataString) => { + return getHostnameFromUri(initDataString); }; export const defaultGetLicense = (fairplayOptions) => {