Skip to content

Commit b27f20f

Browse files
fix(FEC-14578): [DRM] playkit-js changes needed to support uDRM CPIX multikey solution for HLS FPS
### Description of the Changes Based on #819 Add a custom header for fairplay DRM requests The custom header logic will only work with the configuration ``` playback: { options: { html5: { native: { useKIDHeader: true } } } } ``` Resolves FEC-14578 --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 4211bfb commit b27f20f

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

src/engines/html5/media-source/adapters/fairplay-drm-handler.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const WebkitEvents: WebkitEventsType = {
1616
KEY_ERROR: 'webkitkeyerror'
1717
};
1818

19-
type FairPlayDrmConfigType = {licenseUrl: string, certificate?: string, network: {requestFilter?: (...args: any[]) => any, responseFilter: (...args: any[]) => any}};
19+
type FairPlayDrmConfigType = {licenseUrl: string, certificate?: string, network: {requestFilter?: (...args: any[]) => any, responseFilter: (...args: any[]) => any}, useKIDHeader?: boolean};
2020

2121
class FairPlayDrmHandler {
2222
public static WebkitEvents: WebkitEventsType = WebkitEvents;
@@ -81,7 +81,7 @@ class FairPlayDrmHandler {
8181
const videoElement = event.target;
8282
let initData = event.initData;
8383

84-
const contentId = FairPlayDrmHandler._extractContentId(initData);
84+
const contentId = FairPlayDrmHandler._extractContentId(initData, !!this._config.useKIDHeader);
8585
const fpsCertificate = FairPlayDrmHandler._base64DecodeUint8Array(this._config.certificate);
8686

8787
initData = FairPlayDrmHandler._concatInitDataIdAndCertificate(initData, contentId, fpsCertificate);
@@ -119,13 +119,18 @@ class FairPlayDrmHandler {
119119
private _onWebkitKeyMessage(event: any): void {
120120
this._logger.debug('Webkit key message triggered');
121121
const message = event.message;
122+
// WebkitMediaKeySession has attribute contentId (which is the mykeyid from playlist's skd://mykeyid)
123+
const session = event.target;
124+
const kid = session?.contentId;
125+
const kidBase64 = (kid !== undefined && kid !== null) ? btoa(kid) : '';
126+
122127
const request = new XMLHttpRequest();
123128
request.responseType = 'arraybuffer';
124129
this._eventManager.listenOnce(request, 'load', (e: Event) => this._licenseRequestLoaded(e));
125130
const pkRequest: PKRequestObject = {
126131
url: this._config.licenseUrl,
127132
body: FairPlayDrmHandler._base64EncodeUint8Array(message),
128-
headers: {}
133+
headers: this._config.useKIDHeader ? {'X-Kaltura-InitData': kidBase64} : {} // pass the kid to uDRM
129134
};
130135
let requestFilterPromise;
131136
const requestFilter = this._config.network.requestFilter;
@@ -264,10 +269,16 @@ class FairPlayDrmHandler {
264269
return keySystem;
265270
}
266271

267-
public static _extractContentId(initData: Uint8Array): string {
268-
const link = document.createElement('a');
269-
link.href = FairPlayDrmHandler._arrayToString(initData);
270-
return link.hostname;
272+
public static _extractContentId(initData: Uint8Array, useKIDHeader: boolean): string {
273+
if (useKIDHeader) {
274+
const url = FairPlayDrmHandler._arrayToString(initData);
275+
const hostname = url.slice(url.lastIndexOf("skd://")+6,url.length); // handle the skd://mykeyid format
276+
return hostname;
277+
} else {
278+
const link = document.createElement('a');
279+
link.href = FairPlayDrmHandler._arrayToString(initData);
280+
return link.hostname;
281+
}
271282
}
272283

273284
public static _arrayToString(array: Uint8Array): string {

src/engines/html5/media-source/adapters/native-adapter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ export default class NativeAdapter extends BaseMediaSourceAdapter {
296296
const drmConfig: FairPlayDrmConfigType = {
297297
licenseUrl: '',
298298
certificate: '',
299-
network: this._config.network
299+
network: this._config.network,
300+
useKIDHeader: !!this._config.useKIDHeader
300301
};
301302
NativeAdapter._drmProtocol.setDrmPlayback(drmConfig, this._sourceObj.drmData);
302303
this._drmHandler = new FairPlayDrmHandler(

0 commit comments

Comments
 (0)