diff --git a/README.md b/README.md index 6d9d1ffe..d93ba7cc 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,8 @@ var options = { canvas: document.getElementById('canvas'), // canvas element subUrl: '/test/test.ass', // Link to subtitles fonts: ['/test/font-1.ttf', '/test/font-2.ttf'], // Links to fonts (not required, default font already included in build) - workerUrl: '/libassjs-worker.js' // Link to file "libassjs-worker.js" + workerUrl: '/libassjs-worker.js', // Link to file "libassjs-worker.js" + wasmUrl: '/libassjs.wasm', // Link to file "libassjs.wasm" (not required, default loaded by workerUrl) }; var instance = new SubtitlesOctopus(options); // And then... @@ -111,6 +112,8 @@ When creating an instance of SubtitleOctopus, you can set the following options: - `subContent`: The content of the subtitle file to play. (Require either `subContent` or `subUrl` to be specified) - `workerUrl`: The URL of the worker. (Default: `libassjs-worker.js`) +- `wasmUrl`: The URL of the WebAssembly file. (if your wasm file is not in the + same directory as the worker, you need to specify this) (Optional) - `fonts`: An array of links to the fonts used in the subtitle. (Optional) - `availableFonts`: Object with all available fonts - Key is font name in lower case, value is link: `{"arial": "/font1.ttf"}` (Optional) diff --git a/src/post-worker.js b/src/post-worker.js index 57efb013..ae9a9f73 100644 --- a/src/post-worker.js +++ b/src/post-worker.js @@ -552,7 +552,7 @@ function onMessageFromMainEmscriptenThread(message) { self.renderMode = 'wasm-blend'; console.error("'createImageBitmap' needed for 'lossy' unsupported. Falling back to default!"); } - + self.wasmUrl = message.data.wasmUrl; self.availableFonts = message.data.availableFonts; self.fallbackFont = message.data.fallbackFont; self.lazyFileLoading = message.data.lazyFileLoading; diff --git a/src/pre-worker.js b/src/pre-worker.js index 7b277c9a..ce68fadb 100644 --- a/src/pre-worker.js +++ b/src/pre-worker.js @@ -77,6 +77,15 @@ Module["preRun"].push(function () { } }); +// override locateFile for wasm file requests +Module['locateFile'] = function (url) { + // if we have a wasmUrl, use it + if (self.wasmUrl && /\.wasm$/.test(url)) { + return self.wasmUrl; + } + return url; +}; + Module['onRuntimeInitialized'] = function () { self.octObj = new Module.SubtitleOctopus(); diff --git a/src/subtitles-octopus.js b/src/subtitles-octopus.js index 0bf73c14..4839a543 100644 --- a/src/subtitles-octopus.js +++ b/src/subtitles-octopus.js @@ -32,6 +32,7 @@ var SubtitlesOctopus = function (options) { self.onReadyEvent = options.onReady; // Function called when SubtitlesOctopus is ready (optional) if (supportsWebAssembly) { self.workerUrl = options.workerUrl || 'subtitles-octopus-worker.js'; // Link to WebAssembly worker + self.wasmUrl = options.wasmUrl || null; // Link to WebAssembly binary } else { self.workerUrl = options.legacyWorkerUrl || 'subtitles-octopus-worker-legacy.js'; // Link to legacy worker } @@ -108,6 +109,7 @@ var SubtitlesOctopus = function (options) { height: self.canvas.height, URL: document.URL, currentScript: self.workerUrl, + wasmUrl: self.wasmUrl, preMain: true, renderMode: self.renderMode, subUrl: self.subUrl, @@ -678,7 +680,7 @@ var SubtitlesOctopus = function (options) { style: style }); }; - + self.getStyles = function (onSuccess, onError) { self.fetchFromWorker({ target: 'get-styles'