@@ -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
2121class 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 {
0 commit comments