Skip to content

Commit ad5b5d3

Browse files
author
Bryan Yao
committed
fix unit drmsystemoptions test
1 parent 9895289 commit ad5b5d3

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export type EMEControllerConfig = {
5353
emeEnabled: boolean,
5454
widevineLicenseUrl?: string,
5555
clearkeyServerUrl?: string,
56-
clearkeyPair: KeyidValue,
56+
clearkeyPair: KeyidValue | null,
5757
drmSystemOptions: DRMSystemOptions,
5858
requestMediaKeySystemAccessFunc: MediaKeyFunc | null,
5959
};
@@ -251,7 +251,7 @@ export const hlsDefaultConfig: HlsConfig = {
251251
minAutoBitrate: 0, // used by hls
252252
emeEnabled: false, // used by eme-controller
253253
clearkeyServerUrl: void 0,
254-
clearkeyPair: {},
254+
clearkeyPair: null,
255255
widevineLicenseUrl: void 0, // used by eme-controller
256256
drmSystemOptions: {}, // used by eme-controller
257257
requestMediaKeySystemAccessFunc: requestMediaKeySystemAccess, // used by eme-controller

src/controller/eme-controller.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ const createWidevineMediaKeySystemConfigurations = function (
5858

5959
const createClearkeyMediaKeySystemConfigurations = function (
6060
audioCodecs: string[],
61-
videoCodecs: string[],
62-
drmSystemOptions: DRMSystemOptions
61+
videoCodecs: string[]
6362
): MediaKeySystemConfiguration[] { /* jshint ignore:line */
6463
const baseConfig: MediaKeySystemConfiguration = {
6564
initDataTypes: ['keyids', 'mp4'],
@@ -108,7 +107,7 @@ const getSupportedMediaKeySystemConfigurations = function (
108107
case KeySystems.WIDEVINE:
109108
return createWidevineMediaKeySystemConfigurations(audioCodecs, videoCodecs, drmSystemOptions);
110109
case KeySystems.CLEARKEY:
111-
return createClearkeyMediaKeySystemConfigurations(audioCodecs, videoCodecs, drmSystemOptions);
110+
return createClearkeyMediaKeySystemConfigurations(audioCodecs, videoCodecs);
112111
default:
113112
throw new Error(`Unknown key-system: ${keySystem}`);
114113
}
@@ -135,7 +134,7 @@ class EMEController implements ComponentAPI {
135134
private _licenseXhrSetup?: (xhr: XMLHttpRequest, url: string) => void;
136135
private _emeEnabled: boolean;
137136
private _clearkeyServerUrl?: string;
138-
private _clearkeyPair: KeyidValue;
137+
private _clearkeyPair: KeyidValue | null;
139138
private _requestMediaKeySystemAccess: MediaKeyFunc | null;
140139
private _drmSystemOptions: DRMSystemOptions;
141140

@@ -295,7 +294,7 @@ class EMEController implements ComponentAPI {
295294
// Uint8Array, would then be passed to session.update().
296295
// Instead, we will generate the license synchronously on the client, using
297296
// the hard-coded KEY.
298-
if (this._clearkeyPair == null) {
297+
if (!this._clearkeyPair) {
299298
logger.error('Failed to load the keys');
300299
}
301300

@@ -321,17 +320,17 @@ class EMEController implements ComponentAPI {
321320

322321
const keyarray: responseFormat[] = [];
323322
for (const id of request.kids) {
324-
const decodedBase64 = this.base64ToHex(id);
323+
const decodedBase64 = this._base64ToHex(id);
325324
// logger.log(`decodedBase64: ${decodedBase64}`);
326-
if (!this._clearkeyPair.hasOwnProperty(decodedBase64)) {
325+
if (!(this._clearkeyPair as KeyidValue).hasOwnProperty(decodedBase64)) {
327326
logger.error('No pair key, please use lower case');
328327
}
329328
keyarray.push(
330329
{
331330
kty: 'oct',
332331
alg: 'A128KW',
333332
kid: id,
334-
k: this.hexToBase64(this._clearkeyPair[decodedBase64])
333+
k: this._hexToBase64((this._clearkeyPair as KeyidValue)[decodedBase64])
335334
// k: "aeqoAqZ2Ovl56NGUD7iDkg"
336335
}
337336
);
@@ -348,7 +347,7 @@ class EMEController implements ComponentAPI {
348347
}));
349348
}
350349

351-
private hexToBase64 (hexstring) {
350+
private _hexToBase64 (hexstring) {
352351
var encodedBase64 = btoa(hexstring.match(/\w{2}/g).map(function (a) {
353352
return String.fromCharCode(parseInt(a, 16));
354353
}).join(''));
@@ -361,7 +360,7 @@ class EMEController implements ComponentAPI {
361360
return (start > 0 || end < encodedBase64.length) ? encodedBase64.substring(start, end) : encodedBase64;
362361
}
363362

364-
private base64ToHex (str) {
363+
private _base64ToHex (str) {
365364
const raw = atob(str);
366365
logger.log(raw);
367366
let result = '';
@@ -392,7 +391,7 @@ class EMEController implements ComponentAPI {
392391
private _onKeySessionMessage (keySession: MediaKeySession, message: ArrayBuffer) {
393392
logger.log('Got EME message event, creating license request');
394393

395-
if (this._clearkeyPair && this._clearkeyServerUrl === void 0) {
394+
if (this._clearkeyPair && !this._clearkeyServerUrl) {
396395
this._handleMessage(keySession, message);
397396
} else {
398397
this._requestLicense(message, (data: ArrayBuffer) => {
@@ -728,7 +727,6 @@ class EMEController implements ComponentAPI {
728727
const videoCodecs = data.levels.map((level) => level.videoCodec).filter(
729728
(videoCodec: string | undefined): videoCodec is string => !!videoCodec
730729
);
731-
732730
if (this._clearkeyPair || this._clearkeyServerUrl) {
733731
this._attemptKeySystemAccess(KeySystems.CLEARKEY, audioCodecs, videoCodecs);
734732
} else {

tests/unit/controller/eme-controller.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ describe('EMEController', function () {
9090
audioRobustness: 'HW_SECURE_ALL',
9191
videoRobustness: 'HW_SECURE_ALL'
9292
},
93+
clearkeyPair: null,
94+
clearkeyServerUrl: void 0,
9395
requestMediaKeySystemAccessFunc: reqMediaKsAccessSpy
9496
});
9597

0 commit comments

Comments
 (0)