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

fix: convert initData to a string #147

Merged
merged 2 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/eme.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/fairplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -128,8 +128,8 @@ export const defaultGetCertificate = (fairplayOptions) => {
};
};

export const defaultGetContentId = (emeOptions, initData) => {
return getHostnameFromUri(uint8ArrayToString(initData));
export const defaultGetContentId = (emeOptions, initDataString) => {
return getHostnameFromUri(initDataString);
};

export const defaultGetLicense = (fairplayOptions) => {
Expand Down Expand Up @@ -174,7 +174,7 @@ const fairplay = ({video, initData, options, eventBus}) => {
initData,
getLicense,
options,
contentId: getContentId(options, initData),
contentId: getContentId(options, uint16ArrayToString(initData)),
eventBus
});
});
Expand Down
4 changes: 4 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down