Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: wasmUrl config #169

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/post-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/pre-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 3 additions & 1 deletion src/subtitles-octopus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -678,7 +680,7 @@ var SubtitlesOctopus = function (options) {
style: style
});
};

self.getStyles = function (onSuccess, onError) {
self.fetchFromWorker({
target: 'get-styles'
Expand Down