From 3d20b8a52d41e76a0c2f08f90cff51e2f13cb6a2 Mon Sep 17 00:00:00 2001 From: Matthew Neil Date: Tue, 6 Mar 2018 18:09:28 -0500 Subject: [PATCH] use webwackify for webworkers to support webpack bundle (#173) --- package-lock.json | 8 ++++---- package.json | 2 +- src/flash-source-buffer.js | 16 ++++++++++++++-- src/virtual-source-buffer.js | 16 ++++++++++++++-- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index be12df06..209afeb5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25575,10 +25575,10 @@ } } }, - "webworkify": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/webworkify/-/webworkify-1.0.2.tgz", - "integrity": "sha1-thapWmIlJJvyWpHpbglCxmUVWZU=" + "webwackify": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/webwackify/-/webwackify-0.1.3.tgz", + "integrity": "sha512-ttgVaQAd+9kYmZxgAuP8LMlYQRwDa8CujTEIxjXzb/XzMkF9Rg5jN7J4tus1kJvFHeINDa0MlM3pZqR+iRmkAg==" }, "which": { "version": "1.3.0", diff --git a/package.json b/package.json index 770c8af3..d033cc1a 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "global": "^4.3.0", "mux.js": "4.3.2", "video.js": "^5.17.0 || ^6.2.0", - "webworkify": "1.0.2" + "webwackify": "0.1.3" }, "devDependencies": { "babel": "^5.8.0", diff --git a/src/flash-source-buffer.js b/src/flash-source-buffer.js index e34fa729..0e49aa97 100644 --- a/src/flash-source-buffer.js +++ b/src/flash-source-buffer.js @@ -8,9 +8,21 @@ import removeCuesFromTrack from './remove-cues-from-track'; import createTextTracksIfNecessary from './create-text-tracks-if-necessary'; import {addTextTrackData} from './add-text-track-data'; import transmuxWorker from './flash-transmuxer-worker'; -import work from 'webworkify'; +import work from 'webwackify'; import FlashConstants from './flash-constants'; +const resolveFlashTransmuxWorker = () => { + let result; + + try { + result = require.resolve('./flash-transmuxer-worker'); + } catch (e) { + // no result + } + + return result; +}; + /** * A wrapper around the setTimeout function that uses * the flash constant time between ticks value. @@ -125,7 +137,7 @@ export default class FlashSourceBuffer extends videojs.EventTarget { this.mediaSource_.swfObj.vjs_appendChunkReady(this.flashEncodedHeaderName_); - this.transmuxer_ = work(transmuxWorker); + this.transmuxer_ = work(transmuxWorker, resolveFlashTransmuxWorker()); this.transmuxer_.postMessage({ action: 'init', options: {} }); this.transmuxer_.onmessage = (event) => { if (event.data.action === 'data') { diff --git a/src/virtual-source-buffer.js b/src/virtual-source-buffer.js index 40dac8ac..c10d547c 100644 --- a/src/virtual-source-buffer.js +++ b/src/virtual-source-buffer.js @@ -5,10 +5,22 @@ import videojs from 'video.js'; import createTextTracksIfNecessary from './create-text-tracks-if-necessary'; import removeCuesFromTrack from './remove-cues-from-track'; import {addTextTrackData} from './add-text-track-data'; -import work from 'webworkify'; +import work from 'webwackify'; import transmuxWorker from './transmuxer-worker'; import {isAudioCodec, isVideoCodec} from './codec-utils'; +const resolveTransmuxWorker = () => { + let result; + + try { + result = require.resolve('./transmuxer-worker'); + } catch (e) { + // no result + } + + return result; +}; + // We create a wrapper around the SourceBuffer so that we can manage the // state of the `updating` property manually. We have to do this because // Firefox changes `updating` to false long before triggering `updateend` @@ -197,7 +209,7 @@ export default class VirtualSourceBuffer extends videojs.EventTarget { // append muxed segments to their respective native buffers as // soon as they are available - this.transmuxer_ = work(transmuxWorker); + this.transmuxer_ = work(transmuxWorker, resolveTransmuxWorker()); this.transmuxer_.postMessage({action: 'init', options }); this.transmuxer_.onmessage = (event) => {