Skip to content

Commit

Permalink
fix(FEC-11785): [Youbora] - update youbora options for drm system tha…
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanTGold authored Jan 20, 2022
1 parent 0c3f3f3 commit 8e0d032
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 10 deletions.
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.*/node_modules
[include]
[options]
esproposal.optional_chaining=enable
1 change: 1 addition & 0 deletions flow-typed/interfaces/drm-protocol.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@flow
declare interface IDrmProtocol {
isConfigured(drmData: Array<Object>, drmConfig: PKDrmConfigObject): boolean;
canPlayDrm(drmData: Array<Object>): boolean;
setDrmPlayback(...any): void;
}
1 change: 1 addition & 0 deletions flow-typed/interfaces/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ declare interface IEngine extends FakeEventTarget {
isOnLiveEdge(): boolean;
addTextTrack(kind: string, label?: string, language): ?TextTrack;
getTextTracks(): Array<TextTrack>;
getDrmInfo(): ?PKDrmDataObject;
+id: string;
currentTime: number;
+duration: number;
Expand Down
1 change: 1 addition & 0 deletions flow-typed/interfaces/media-source-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ declare interface IMediaSourceAdapter extends FakeEventTarget {
detachMediaSource(): void;
getSegmentDuration(): number;
disableNativeTextTracks(): void;
getDrmInfo(): ?PKDrmDataObject;
}
12 changes: 6 additions & 6 deletions src/drm/fairplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@ const _logger = getLogger('FairPlay');
const FairPlay: IDrmProtocol = class FairPlay {
/**
* FairPlay is the configure key system.
* @param {Array<Object>} drmData - The drm data.
* @param {Array<PKDrmDataObject>} drmData - The drm data.
* @param {PKDrmConfigObject} drmConfig - The drm config.
* @return {boolean} - Whether FairPlay is the configure key system.
*/
static isConfigured(drmData: Array<Object>, drmConfig: PKDrmConfigObject): boolean {
static isConfigured(drmData: Array<PKDrmDataObject>, drmConfig: PKDrmConfigObject): boolean {
return DrmScheme.FAIRPLAY === drmConfig.keySystem && !!drmData.find(drmEntry => drmEntry.scheme === drmConfig.keySystem);
}

/**
* FairPlay playback supports in case 2 conditions are met:
* 1. The environment supports FairPlay playback.
* 2. The drm data of the source object contains entry with FairPlay scheme.
* @param {Array<Object>} drmData - The drm data to check.
* @param {Array<PKDrmDataObject>} drmData - The drm data to check.
* @return {boolean} - Whether FairPlay can be play on the current environment.
*/
static canPlayDrm(drmData: Array<Object>): boolean {
static canPlayDrm(drmData: Array<PKDrmDataObject>): boolean {
_logger.debug('Can play DRM scheme of: ' + DrmScheme.FAIRPLAY);
return !!drmData.find(drmEntry => drmEntry.scheme === DrmScheme.FAIRPLAY) && !!window.WebKitMediaKeys;
}

/**
* Sets the FairPlay playback.
* @param {FairPlayDrmConfigType} config - The config to manipulate.
* @param {Array<Object>} drmData - The drm data.
* @param {Array<PKDrmDataObject>} drmData - The drm data.
* @returns {void}
*/
static setDrmPlayback(config: FairPlayDrmConfigType, drmData: Array<Object>): void {
static setDrmPlayback(config: FairPlayDrmConfigType, drmData: Array<PKDrmDataObject>): void {
_logger.debug('Sets drm playback');
let drmEntry = drmData.find(drmEntry => drmEntry.scheme === DrmScheme.FAIRPLAY);
if (drmEntry) {
Expand Down
4 changes: 4 additions & 0 deletions src/engines/html5/html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -1240,4 +1240,8 @@ export default class Html5 extends FakeEventTarget implements IEngine {
getTextTracks(): Array<TextTrack> {
return Array.from(this._el.textTracks);
}

getDrmInfo(): ?PKDrmDataObject {
return this._mediaSourceAdapter?.getDrmInfo();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const WebkitEvents: WebkitEventsType = {
KEY_ERROR: 'webkitkeyerror'
};

type FairPlayDrmConfigType = {licenseUrl: string, certificate: string, network: {requestFilter?: Function, responseFilter: Function}};
type FairPlayDrmConfigType = {licenseUrl: string, certificate?: string, network: {requestFilter?: Function, responseFilter: Function}};

class FairPlayDrmHandler {
static WebkitEvents: WebkitEventsType = WebkitEvents;
Expand Down Expand Up @@ -108,6 +108,11 @@ class FairPlayDrmHandler {
this._eventManager.listen(this._keySession, WebkitEvents.KEY_ERROR, (e: Event) => this._onWebkitKeyError(e));
}

getDrmInfo(): PKDrmDataObject {
const {certificate, licenseUrl} = this._config;
return {certificate, licenseUrl, scheme: DrmScheme.FAIRPLAY};
}

destroy(): void {
this._eventManager.destroy();
this._keySession.close();
Expand Down Expand Up @@ -272,7 +277,7 @@ class FairPlayDrmHandler {
return String.fromCharCode.apply(null, new Uint16Array(array.buffer));
}

static _base64DecodeUint8Array(input: string): Uint8Array {
static _base64DecodeUint8Array(input?: string): Uint8Array {
let raw = window.atob(input);
let rawLength = raw.length;
let array = new Uint8Array(new ArrayBuffer(rawLength));
Expand Down
8 changes: 6 additions & 2 deletions src/engines/html5/media-source/adapters/native-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ export default class NativeAdapter extends BaseMediaSourceAdapter {
* @private
* @static
*/
static _drmProtocols: Array<Function> = [FairPlay];
static _drmProtocols: Array<IDrmProtocol> = [FairPlay];
/**
* The DRM protocol for the current playback.
* @type {?Function}
* @private
* @static
*/
static _drmProtocol: ?Function = null;
static _drmProtocol: ?IDrmProtocol = null;
/**
* The supported progressive mime types by the native adapter.
* @member {Array<string>} _progressiveMimeTypes
Expand Down Expand Up @@ -1226,4 +1226,8 @@ export default class NativeAdapter extends BaseMediaSourceAdapter {
return 0;
}
}

getDrmInfo(): ?PKDrmDataObject {
return this._drmHandler ? this._drmHandler.getDrmInfo() : null;
}
}
4 changes: 4 additions & 0 deletions src/engines/html5/media-source/base-media-source-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,8 @@ export default class BaseMediaSourceAdapter extends FakeEventTarget implements I
get targetBuffer(): number {
return NaN;
}

getDrmInfo(): ?PKDrmDataObject {
return null;
}
}
4 changes: 4 additions & 0 deletions src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,10 @@ export default class Player extends FakeEventTarget {
setLogLevel(level, name);
}

getDrmInfo(): ?PKDrmDataObject {
return this._engine?.getDrmInfo();
}

// </editor-fold>

// </editor-fold>
Expand Down

0 comments on commit 8e0d032

Please sign in to comment.