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(FEC-10524): align logger ref #486

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 3 additions & 4 deletions src/drm/fairplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import Env from '../../src/utils/env';
import getLogger from '../utils/logger';
import {DrmScheme} from './drm-scheme';

const _logger = getLogger('FairPlay');

const FairPlay: IDrmProtocol = class FairPlay {
static _logger = getLogger('FairPlay');
/**
* FairPlay is the configure key system.
* @param {Array<Object>} drmData - The drm data.
Expand All @@ -25,7 +24,7 @@ const FairPlay: IDrmProtocol = class FairPlay {
* @return {boolean} - Whether FairPlay can be play on the current environment.
*/
static canPlayDrm(drmData: Array<Object>): boolean {
_logger.debug('Can play DRM scheme of: ' + DrmScheme.FAIRPLAY);
FairPlay._logger.debug('Can play DRM scheme of: ' + DrmScheme.FAIRPLAY);
const isSafari = Env.browser.name && Env.browser.name.includes('Safari');
return !!drmData.find(drmEntry => drmEntry.scheme === DrmScheme.FAIRPLAY) && isSafari;
}
Expand All @@ -37,7 +36,7 @@ const FairPlay: IDrmProtocol = class FairPlay {
* @returns {void}
*/
static setDrmPlayback(config: FairPlayDrmConfigType, drmData: Array<Object>): void {
_logger.debug('Sets drm playback');
FairPlay._logger.debug('Sets drm playback');
let drmEntry = drmData.find(drmEntry => drmEntry.scheme === DrmScheme.FAIRPLAY);
if (drmEntry) {
config.licenseUrl = drmEntry.licenseUrl;
Expand Down
25 changes: 13 additions & 12 deletions src/engines/html5/media-source/adapters/fairplay-drm-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type FairPlayDrmConfigType = {licenseUrl: string, certificate: string, network:

class FairPlayDrmHandler {
static WebkitEvents: WebkitEventsType = WebkitEvents;
static _logger: any;

_logger = getLogger('FairPlayDrmHandler');
_eventManager: EventManager;
_keySession: any;
_config: FairPlayDrmConfigType;
Expand Down Expand Up @@ -70,6 +70,7 @@ class FairPlayDrmHandler {
* @param {Function} drmResponseCallback - drm license response callback function
*/
constructor(videoElement: HTMLVideoElement, config: FairPlayDrmConfigType, errorCallback: Function, drmResponseCallback: Function): void {
FairPlayDrmHandler._logger = getLogger('FairPlayDrmHandler');
this._config = Utils.Object.mergeDeep({}, this._defaultConfig, config);
this._errorCallback = errorCallback;
this._drmResponseCallback = drmResponseCallback;
Expand All @@ -80,7 +81,7 @@ class FairPlayDrmHandler {
}

_onWebkitNeedKey(event: any): void {
this._logger.debug('Webkit need key triggered');
FairPlayDrmHandler._logger.debug('Webkit need key triggered');
let videoElement = event.target;
let initData = event.initData;

Expand All @@ -91,13 +92,13 @@ class FairPlayDrmHandler {

if (!videoElement.webkitKeys) {
let keySystem = this._selectKeySystem();
this._logger.debug('Sets media keys');
FairPlayDrmHandler._logger.debug('Sets media keys');
videoElement.webkitSetMediaKeys(new window.WebKitMediaKeys(keySystem));
}
if (!videoElement.webkitKeys) {
this._onError((Error.Code: CodeType).COULD_NOT_CREATE_MEDIA_KEYS);
}
this._logger.debug('Creates session');
FairPlayDrmHandler._logger.debug('Creates session');
this._keySession = videoElement.webkitKeys.createSession('video/mp4', initData);
if (!this._keySession) {
this._onError((Error.Code: CodeType).COULD_NOT_CREATE_KEY_SESSION);
Expand All @@ -115,7 +116,7 @@ class FairPlayDrmHandler {
}

_onWebkitKeyMessage(event: any): void {
this._logger.debug('Webkit key message triggered');
FairPlayDrmHandler._logger.debug('Webkit key message triggered');
let message = event.message;
let request = new XMLHttpRequest();
request.responseType = 'arraybuffer';
Expand All @@ -128,7 +129,7 @@ class FairPlayDrmHandler {
let requestFilterPromise;
const requestFilter = this._config.network.requestFilter;
if (requestFilter) {
this._logger.debug('Apply request filter');
FairPlayDrmHandler._logger.debug('Apply request filter');
try {
requestFilterPromise = requestFilter(RequestType.LICENSE, pkRequest);
} catch (error) {
Expand All @@ -147,7 +148,7 @@ class FairPlayDrmHandler {
});
}
setContentType && request.setRequestHeader('Content-type', 'application/json');
this._logger.debug('Ready for license request');
FairPlayDrmHandler._logger.debug('Ready for license request');
request.onerror = () => {
this._onError((Error.Code: CodeType).LICENSE_REQUEST_FAILED, {
status: request.status,
Expand All @@ -171,19 +172,19 @@ class FairPlayDrmHandler {
}

_onWebkitKeyAdded(): void {
this._logger.debug('Decryption key was added to session');
FairPlayDrmHandler._logger.debug('Decryption key was added to session');
}

_onWebkitKeyError(e: any): void {
this._logger.error('A decryption key error was encountered', e);
FairPlayDrmHandler._logger.error('A decryption key error was encountered', e);
if (this._retryLicenseRequest <= 0) {
this._onError((Error.Code: CodeType).LICENSE_REQUEST_FAILED, e.target.error);
}
this._retryLicenseRequest--;
}

_licenseRequestLoaded(event: any): void {
this._logger.debug('License request loaded');
FairPlayDrmHandler._logger.debug('License request loaded');
let request = event.target;
if (request.status > 299) {
this._onError((Error.Code: CodeType).LICENSE_REQUEST_FAILED, {
Expand All @@ -201,7 +202,7 @@ class FairPlayDrmHandler {
const headers = Utils.Http.convertHeadersToDictionary(request.getAllResponseHeaders());

const pkResponse: PKResponseObject = {url, originalUrl, data, headers};
this._logger.debug('Apply response filter');
FairPlayDrmHandler._logger.debug('Apply response filter');
let responseFilterPromise;
try {
responseFilterPromise = this._config.network.responseFilter(RequestType.LICENSE, pkResponse);
Expand Down Expand Up @@ -254,7 +255,7 @@ class FairPlayDrmHandler {
if (window.WebKitMediaKeys.isTypeSupported(KeySystem, 'video/mp4')) {
keySystem = KeySystem;
} else {
this._logger.warn('Key System not supported');
FairPlayDrmHandler._logger.warn('Key System not supported');
}
return keySystem;
}
Expand Down
19 changes: 9 additions & 10 deletions src/middleware/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ import getLogger from '../utils/logger';
*/
export default class Middleware {
/**
* The registered middlewares.
* The logger of the middleware.
* @private
* @member
*/
_middlewares: MultiMap<*>;
static _logger: any = getLogger('Middleware');
/**
* The actions supported by the middleware.
* The registered middlewares.
* @private
* @member
*/
_actions: {[action: string]: string};
_middlewares: MultiMap<*>;
/**
* The logger of the middleware.
* The actions supported by the middleware.
* @private
* @member
*/
_logger: any;
_actions: {[action: string]: string};

/**
* @constructor
Expand All @@ -33,7 +33,6 @@ export default class Middleware {
constructor(actions: {[action: string]: string}) {
this._actions = actions;
this._middlewares = new MultiMap();
this._logger = getLogger('Middleware');
}

/**
Expand All @@ -47,7 +46,7 @@ export default class Middleware {
let apiAction = this._actions[action];
// $FlowFixMe
if (typeof middlewareInstance[apiAction] === 'function') {
this._logger.debug(`Register <${middlewareInstance.id}> for action ${apiAction}`);
Middleware._logger.debug(`Register <${middlewareInstance.id}> for action ${apiAction}`);
// $FlowFixMe
this._middlewares.push(apiAction, middlewareInstance[apiAction].bind(middlewareInstance));
}
Expand All @@ -62,10 +61,10 @@ export default class Middleware {
* @returns {void}
*/
run(action: string, callback: Function): void {
this._logger.debug('Start middleware chain for action ' + action);
Middleware._logger.debug('Start middleware chain for action ' + action);
let middlewares = this._middlewares.get(action);
this._executeMiddleware(middlewares, () => {
this._logger.debug('Finish middleware chain for action ' + action);
Middleware._logger.debug('Finish middleware chain for action ' + action);
callback();
});
}
Expand Down
7 changes: 3 additions & 4 deletions src/state/state-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class StateManager {
* @type {any}
* @private
*/
_logger: any;
static _logger: any = getLogger('StateManager');
/**
* Reference to the actual player.
* @member
Expand Down Expand Up @@ -155,7 +155,6 @@ export default class StateManager {
*/
constructor(player: Player) {
this._player = player;
this._logger = getLogger('StateManager');
this._eventManager = new EventManager();
this._history = [];
this._prevState = null;
Expand Down Expand Up @@ -189,7 +188,7 @@ export default class StateManager {
*/
_doTransition(event: FakeEvent): void {
if (event.type !== Html5EventType.TIME_UPDATE || (this._curState === StateType.BUFFERING && event.type === Html5EventType.TIME_UPDATE)) {
this._logger.debug('Do transition request', event.type); // don't show most of 'timeupdate' events
StateManager._logger.debug('Do transition request', event.type); // don't show most of 'timeupdate' events
}
let transition = this._transitions[this._curState.type];
if (typeof transition[event.type] === 'function') {
Expand All @@ -209,7 +208,7 @@ export default class StateManager {
this._history.push(this._curState);
this._prevState = this._curState;
this._curState = new State(type);
this._logger.debug(`Switch player state: from ${this._prevState.type} to ${this._curState.type}`);
StateManager._logger.debug(`Switch player state: from ${this._prevState.type} to ${this._curState.type}`);
}
}

Expand Down