Skip to content

Commit

Permalink
use explicite window property for all previous globals
Browse files Browse the repository at this point in the history
  • Loading branch information
tchakabam committed Jun 5, 2018
1 parent 1d58572 commit 1f21784
Show file tree
Hide file tree
Showing 19 changed files with 37 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/controller/abr-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { ErrorDetails } from '../errors';
import { logger } from '../utils/logger';
import EwmaBandWidthEstimator from '../utils/ewma-bandwidth-estimator';

const { performance } = window;

class AbrController extends EventHandler {
constructor (hls) {
super(hls, Event.FRAG_LOADING,
Expand Down
2 changes: 2 additions & 0 deletions src/controller/audio-stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import TaskLoop from '../task-loop';
import { FragmentState } from './fragment-tracker';
import Fragment from '../loader/fragment';

const { performance } = window;

const State = {
STOPPED: 'STOPPED',
STARTING: 'STARTING',
Expand Down
4 changes: 2 additions & 2 deletions src/controller/buffer-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class BufferController extends EventHandler {
ms.addEventListener('sourceended', this.onmse);
ms.addEventListener('sourceclose', this.onmsc);
// link video and media Source
media.src = URL.createObjectURL(ms);
media.src = window.URL.createObjectURL(ms);
// cache the locally generated object url
this._objectUrl = media.src;
}
Expand Down Expand Up @@ -137,7 +137,7 @@ class BufferController extends EventHandler {
// Detach properly the MediaSource from the HTMLMediaElement as
// suggested in https://github.com/w3c/media-source/issues/53.
if (this.media) {
URL.revokeObjectURL(this._objectUrl);
window.URL.revokeObjectURL(this._objectUrl);

// clean up video tag src only if it's our own url. some external libraries might
// hijack the video tag and change its 'src' without destroying the Hls instance first
Expand Down
2 changes: 1 addition & 1 deletion src/controller/cap-level-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CapLevelController extends EventHandler {
}

onMediaAttaching (data) {
this.media = data.media instanceof HTMLVideoElement ? data.media : null;
this.media = data.media instanceof window.HTMLVideoElement ? data.media : null;
}

onManifestParsed (data) {
Expand Down
2 changes: 2 additions & 0 deletions src/controller/eme-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { ErrorTypes, ErrorDetails } from '../errors';

import { logger } from '../utils/logger';

const { XMLHttpRequest } = window;

const MAX_LICENSE_REQUEST_FAILURES = 3;

/**
Expand Down
4 changes: 3 additions & 1 deletion src/controller/fps-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Event from '../events';
import EventHandler from '../event-handler';
import { logger } from '../utils/logger';

const { performance } = window;

class FPSController extends EventHandler {
constructor (hls) {
super(hls, Event.MEDIA_ATTACHING);
Expand All @@ -22,7 +24,7 @@ class FPSController extends EventHandler {
onMediaAttaching (data) {
const config = this.hls.config;
if (config.capLevelOnFPSDrop) {
const video = this.video = data.media instanceof HTMLVideoElement ? data.media : null;
const video = this.video = data.media instanceof window.HTMLVideoElement ? data.media : null;
if (typeof video.getVideoPlaybackQuality === 'function') {
this.isVideoPlaybackQualityAvailable = true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/controller/level-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { logger } from '../utils/logger';
import { ErrorTypes, ErrorDetails } from '../errors';
import { isCodecSupportedInMp4 } from '../utils/codecs';

const { performance } = window;

export default class LevelController extends EventHandler {
constructor (hls) {
super(hls,
Expand Down
2 changes: 2 additions & 0 deletions src/controller/stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { alignDiscontinuities } from '../utils/discontinuities';
import TaskLoop from '../task-loop';
import { calculateNextPDT, findFragmentByPDT, findFragmentBySN, fragmentWithinToleranceTest } from './fragment-finders';

const { performance } = window;

export const State = {
STOPPED: 'STOPPED',
IDLE: 'IDLE',
Expand Down
2 changes: 2 additions & 0 deletions src/controller/subtitle-stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { logger } from '../utils/logger';
import Decrypter from '../crypt/decrypter';
import TaskLoop from '../task-loop';

const { performance } = window;

const State = {
STOPPED: 'STOPPED',
IDLE: 'IDLE',
Expand Down
4 changes: 4 additions & 0 deletions src/crypt/decrypter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import AESDecryptor from './aes-decryptor';
import { ErrorTypes, ErrorDetails } from '../errors';
import { logger } from '../utils/logger';

import Event from '../events';

const { performance, crypto } = window;

/* globals self: false */

class Decrypter {
Expand Down
2 changes: 2 additions & 0 deletions src/demux/adts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { logger } from '../utils/logger';
import Event from '../events';
import { ErrorTypes, ErrorDetails } from '../errors';

import Event from '../events';

export function getAudioConfig (observer, data, offset, audioCodec) {
let adtsObjectType, // :int
adtsSampleingIndex, // :int
Expand Down
2 changes: 2 additions & 0 deletions src/demux/demuxer-inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import MP3Demuxer from '../demux/mp3demuxer';
import MP4Remuxer from '../remux/mp4-remuxer';
import PassThroughRemuxer from '../remux/passthrough-remuxer';

const { performance } = window;

class DemuxerInline {
constructor (observer, typeSupported, config, vendor) {
this.observer = observer;
Expand Down
4 changes: 2 additions & 2 deletions src/demux/demuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Demuxer {
logger.error('error while initializing DemuxerWorker, fallback on DemuxerInline');
if (w) {
// revoke the Object URL that was used to create demuxer worker, so as not to leak it
URL.revokeObjectURL(w.objectURL);
window.URL.revokeObjectURL(w.objectURL);
}
this.demuxer = new DemuxerInline(observer, typeSupported, config, vendor);
this.w = undefined;
Expand Down Expand Up @@ -129,7 +129,7 @@ class Demuxer {
switch (data.event) {
case 'init':
// revoke the Object URL that was used to create demuxer worker, so as not to leak it
URL.revokeObjectURL(this.w.objectURL);
window.URL.revokeObjectURL(this.w.objectURL);
break;
// special case for FRAG_PARSING_DATA: data1 and data2 are transferable objects
case Event.FRAG_PARSING_DATA:
Expand Down
1 change: 1 addition & 0 deletions src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,5 @@ const HlsEvents = {
// fired upon stream controller state transitions - data: { previousState, nextState }
STREAM_STATE_TRANSITION: 'hlsStreamStateTransition'
};

export default HlsEvents;
2 changes: 2 additions & 0 deletions src/loader/playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { logger } from '../utils/logger';
import MP4Demuxer from '../demux/mp4demuxer';
import M3U8Parser from './m3u8-parser';

const { performance } = window;

/**
* `type` property values for this loaders' context object
* @enum
Expand Down
2 changes: 1 addition & 1 deletion src/utils/codecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function isCodecType (codec, type) {
}

function isCodecSupportedInMp4 (codec, type) {
return MediaSource.isTypeSupported(`${type || 'video'}/mp4;codecs="${codec}"`);
return window.MediaSource.isTypeSupported(`${type || 'video'}/mp4;codecs="${codec}"`);
}

export { isCodecType, isCodecSupportedInMp4 };
2 changes: 2 additions & 0 deletions src/utils/fetch-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* but still it is not bullet proof as it fails to avoid data waste....
*/

const { Request, Headers, fetch, performance } = window;

class FetchLoader {
constructor (config) {
this.fetchSetup = config.fetchSetup;
Expand Down
2 changes: 2 additions & 0 deletions src/utils/xhr-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import { logger } from '../utils/logger';

const { performance, XMLHttpRequest } = window;

class XhrLoader {
constructor (config) {
if (config && config.xhrSetup) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/demuxer/demuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ describe('Demuxer tests', function () {
}
};

let spy = sinon.spy(URL, 'revokeObjectURL');
let spy = sinon.spy(window.URL, 'revokeObjectURL');

demux.onWorkerMessage(evt);

Expand Down

0 comments on commit 1f21784

Please sign in to comment.