Skip to content

Commit 901b323

Browse files
committed
feature: wasmUrl config
feature: update readme
1 parent 275688a commit 901b323

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

Diff for: README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ var options = {
6060
canvas: document.getElementById('canvas'), // canvas element
6161
subUrl: '/test/test.ass', // Link to subtitles
6262
fonts: ['/test/font-1.ttf', '/test/font-2.ttf'], // Links to fonts (not required, default font already included in build)
63-
workerUrl: '/libassjs-worker.js' // Link to file "libassjs-worker.js"
63+
workerUrl: '/libassjs-worker.js', // Link to file "libassjs-worker.js"
64+
wasmUrl: '/libassjs.wasm', // Link to file "libassjs.wasm" (not required, default loaded by workerUrl)
6465
};
6566
var instance = new SubtitlesOctopus(options);
6667
// And then...
@@ -111,6 +112,8 @@ When creating an instance of SubtitleOctopus, you can set the following options:
111112
- `subContent`: The content of the subtitle file to play. (Require either
112113
`subContent` or `subUrl` to be specified)
113114
- `workerUrl`: The URL of the worker. (Default: `libassjs-worker.js`)
115+
- `wasmUrl`: The URL of the WebAssembly file. (if your wasm file is not in the
116+
same directory as the worker, you need to specify this) (Optional)
114117
- `fonts`: An array of links to the fonts used in the subtitle. (Optional)
115118
- `availableFonts`: Object with all available fonts - Key is font name in lower
116119
case, value is link: `{"arial": "/font1.ttf"}` (Optional)

Diff for: src/post-worker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ function onMessageFromMainEmscriptenThread(message) {
552552
self.renderMode = 'wasm-blend';
553553
console.error("'createImageBitmap' needed for 'lossy' unsupported. Falling back to default!");
554554
}
555-
555+
self.wasmUrl = message.data.wasmUrl;
556556
self.availableFonts = message.data.availableFonts;
557557
self.fallbackFont = message.data.fallbackFont;
558558
self.lazyFileLoading = message.data.lazyFileLoading;

Diff for: src/pre-worker.js

+9
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ Module["preRun"].push(function () {
7777
}
7878
});
7979

80+
// override locateFile for wasm file requests
81+
Module['locateFile'] = function (url) {
82+
// if we have a wasmUrl, use it
83+
if (self.wasmUrl && /\.wasm$/.test(url)) {
84+
return self.wasmUrl;
85+
}
86+
return url;
87+
};
88+
8089
Module['onRuntimeInitialized'] = function () {
8190
self.octObj = new Module.SubtitleOctopus();
8291

Diff for: src/subtitles-octopus.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var SubtitlesOctopus = function (options) {
3232
self.onReadyEvent = options.onReady; // Function called when SubtitlesOctopus is ready (optional)
3333
if (supportsWebAssembly) {
3434
self.workerUrl = options.workerUrl || 'subtitles-octopus-worker.js'; // Link to WebAssembly worker
35+
self.wasmUrl = options.wasmUrl || null; // Link to WebAssembly binary
3536
} else {
3637
self.workerUrl = options.legacyWorkerUrl || 'subtitles-octopus-worker-legacy.js'; // Link to legacy worker
3738
}
@@ -108,6 +109,7 @@ var SubtitlesOctopus = function (options) {
108109
height: self.canvas.height,
109110
URL: document.URL,
110111
currentScript: self.workerUrl,
112+
wasmUrl: self.wasmUrl,
111113
preMain: true,
112114
renderMode: self.renderMode,
113115
subUrl: self.subUrl,
@@ -678,7 +680,7 @@ var SubtitlesOctopus = function (options) {
678680
style: style
679681
});
680682
};
681-
683+
682684
self.getStyles = function (onSuccess, onError) {
683685
self.fetchFromWorker({
684686
target: 'get-styles'

0 commit comments

Comments
 (0)