Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Commit

Permalink
use webwackify for webworkers to support webpack bundle (#1363)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjneil authored Mar 7, 2018
1 parent 7a632c2 commit e2f40f2
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 179 deletions.
182 changes: 11 additions & 171 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@
"mux.js": "4.3.2",
"url-toolkit": "^2.1.3",
"video.js": "^5.19.1 || ^6.2.0",
"videojs-contrib-media-sources": "4.6.2",
"webworkify": "1.0.2"
"videojs-contrib-media-sources": "4.7.0",
"webwackify": "0.1.3"
},
"devDependencies": {
"babel": "^5.8.0",
Expand Down
16 changes: 14 additions & 2 deletions src/master-playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import videojs from 'video.js';
import AdCueTags from './ad-cue-tags';
import SyncController from './sync-controller';
import { translateLegacyCodecs } from 'videojs-contrib-media-sources/es5/codec-utils';
import worker from 'webworkify';
import worker from 'webwackify';
import Decrypter from './decrypter-worker';
import Config from './config';
import { parseCodecs } from './util/codecs.js';
Expand Down Expand Up @@ -43,6 +43,18 @@ const sumLoaderStat = function(stat) {
this.mainSegmentLoader_[stat];
};

const resolveDecrypterWorker = () => {
let result;

try {
result = require.resolve('./decrypter-worker');
} catch (e) {
// no result
}

return result;
};

/**
* Replace codecs in the codec string with the old apple-style `avc1.<dd>.<dd>` to the
* standard `avc1.<hhhhhh>`.
Expand Down Expand Up @@ -275,7 +287,7 @@ export class MasterPlaylistController extends videojs.EventTarget {
label: 'segment-metadata'
}, false).track;

this.decrypter_ = worker(Decrypter);
this.decrypter_ = worker(Decrypter, resolveDecrypterWorker());

const segmentLoaderSettings = {
hls: this.hls_,
Expand Down
16 changes: 14 additions & 2 deletions test/loader-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ import {
import { MasterPlaylistController } from '../src/master-playlist-controller';
import SyncController from '../src/sync-controller';
import Decrypter from '../src/decrypter-worker';
import worker from 'webworkify';
import worker from 'webwackify';

const resolveDecrypterWorker = () => {
let result;

try {
result = require.resolve('../src/decrypter-worker');
} catch (e) {
// no result
}

return result;
};

/**
* beforeEach and afterEach hooks that should be run segment loader tests regardless of
Expand Down Expand Up @@ -44,7 +56,7 @@ export const LoaderCommonHooks = {
this.mediaSource = new videojs.MediaSource();
this.mediaSource.trigger('sourceopen');
this.syncController = new SyncController();
this.decrypter = worker(Decrypter);
this.decrypter = worker(Decrypter, resolveDecrypterWorker());
},
afterEach(assert) {
this.env.restore();
Expand Down
16 changes: 14 additions & 2 deletions test/media-segment-request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,27 @@ import {mediaSegmentRequest, REQUEST_ERRORS} from '../src/media-segment-request'
import xhrFactory from '../src/xhr';
import {useFakeEnvironment} from './test-helpers';
import Decrypter from '../src/decrypter-worker';
import worker from 'webworkify';
import worker from 'webwackify';

const resolveDecrypterWorker = () => {
let result;

try {
result = require.resolve('../src/decrypter-worker');
} catch (e) {
// no result
}

return result;
};

QUnit.module('Media Segment Request', {
beforeEach(assert) {
this.env = useFakeEnvironment(assert);
this.clock = this.env.clock;
this.requests = this.env.requests;
this.xhr = xhrFactory();
this.realDecrypter = worker(Decrypter);
this.realDecrypter = worker(Decrypter, resolveDecrypterWorker());
this.mockDecrypter = {
listeners: [],
postMessage(message) {
Expand Down

0 comments on commit e2f40f2

Please sign in to comment.