Skip to content

Commit

Permalink
add getSelfScope to get global window/worker scope
Browse files Browse the repository at this point in the history
  • Loading branch information
tchakabam committed Jun 5, 2018
1 parent ec44fb0 commit 40bd49c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/crypt/decrypter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { logger } from '../utils/logger';

import Event from '../events';

import { getSelfScope } from '../utils/get-self-scope';

// see https://stackoverflow.com/a/11237259/589493
/* eslint-disable-next-line no-undef */
const window = self; // safeguard for code that might run both on worker and main thread
const window = getSelfScope(); // safeguard for code that might run both on worker and main thread

const { performance, crypto } = window;

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

import Event from '../events';

import { getSelfScope } from '../utils/get-self-scope';

export function getAudioConfig (observer, data, offset, audioCodec) {
let adtsObjectType, // :int
adtsSampleingIndex, // :int
Expand Down
4 changes: 3 additions & 1 deletion src/demux/demuxer-inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import MP3Demuxer from '../demux/mp3demuxer';
import MP4Remuxer from '../remux/mp4-remuxer';
import PassThroughRemuxer from '../remux/passthrough-remuxer';

import { getSelfScope } from '../utils/get-self-scope';

// see https://stackoverflow.com/a/11237259/589493
/* eslint-disable-next-line no-undef */
const window = self; // safeguard for code that might run both on worker and main thread
const window = getSelfScope(); // safeguard for code that might run both on worker and main thread

const { performance } = window;

Expand Down
3 changes: 2 additions & 1 deletion src/demux/demuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import DemuxerInline from '../demux/demuxer-inline';
import { logger } from '../utils/logger';
import { ErrorTypes, ErrorDetails } from '../errors';
import { getMediaSource } from '../utils/mediasource-helper';
import { getSelfScope } from '../utils/get-self-scope';

// see https://stackoverflow.com/a/11237259/589493
/* eslint-disable-next-line no-undef */
const window = self; // safeguard for code that might run both on worker and main thread
const window = getSelfScope(); // safeguard for code that might run both on worker and main thread

const MediaSource = getMediaSource();

Expand Down
4 changes: 3 additions & 1 deletion src/utils/logger.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getSelfScope } from './get-self-scope';

function noop () {}

const fakeLogger = {
Expand Down Expand Up @@ -26,7 +28,7 @@ function formatMsg (type, msg) {
}

/* eslint-disable-next-line no-undef */
const window = self;
const window = getSelfScope();

function consolePrintFn (type) {
const func = window.console[type];
Expand Down

0 comments on commit 40bd49c

Please sign in to comment.