Fix worker script origin issue
This commit is contained in:
parent
680b4df933
commit
4cf2fe2395
@ -66,7 +66,7 @@ $ node --experimental-wasm-threads --experimental-wasm-bulk-memory transcode.js
|
|||||||
Or, using a script tag in the browser (only works in Chrome):
|
Or, using a script tag in the browser (only works in Chrome):
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<script src="https://unpkg.com/@ffmpeg/ffmpeg@0.8.0/dist/ffmpeg.min.js"></script>
|
<script src="https://unpkg.com/@ffmpeg/ffmpeg@0.8.1/dist/ffmpeg.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
const { createFFmpeg } = FFmpeg;
|
const { createFFmpeg } = FFmpeg;
|
||||||
...
|
...
|
||||||
|
@ -1,23 +1,28 @@
|
|||||||
const { log } = require('../utils/log');
|
const { log } = require('../utils/log');
|
||||||
|
|
||||||
module.exports = ({ corePath }) => new Promise((resolve) => {
|
module.exports = async ({ corePath }) => {
|
||||||
if (typeof window.Module === 'undefined') {
|
if (typeof window.Module === 'undefined') {
|
||||||
|
log('info', 'fetch ffmpeg-core.worker.js script');
|
||||||
|
const workerBlob = await (await fetch(corePath.replace('ffmpeg-core.js', 'ffmpeg-core.worker.js'))).blob();
|
||||||
|
window.FFMPEG_CORE_WORKER_SCRIPT = URL.createObjectURL(workerBlob);
|
||||||
|
log('info', `worker object URL=${window.FFMPEG_CORE_WORKER_SCRIPT}`);
|
||||||
log('info', `download ffmpeg-core script (~25 MB) from ${corePath}`);
|
log('info', `download ffmpeg-core script (~25 MB) from ${corePath}`);
|
||||||
const script = document.createElement('script');
|
return new Promise((resolve) => {
|
||||||
const eventHandler = () => {
|
const script = document.createElement('script');
|
||||||
script.removeEventListener('load', eventHandler);
|
const eventHandler = () => {
|
||||||
log('info', 'initialize ffmpeg-core');
|
script.removeEventListener('load', eventHandler);
|
||||||
window.Module.onRuntimeInitialized = () => {
|
log('info', 'initialize ffmpeg-core');
|
||||||
log('info', 'ffmpeg-core initialized');
|
window.Module.onRuntimeInitialized = () => {
|
||||||
resolve(window.Module);
|
log('info', 'ffmpeg-core initialized');
|
||||||
|
resolve(window.Module);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
script.src = corePath;
|
||||||
script.src = corePath;
|
script.type = 'text/javascript';
|
||||||
script.type = 'text/javascript';
|
script.addEventListener('load', eventHandler);
|
||||||
script.addEventListener('load', eventHandler);
|
document.getElementsByTagName('head')[0].appendChild(script);
|
||||||
document.getElementsByTagName('head')[0].appendChild(script);
|
});
|
||||||
} else {
|
|
||||||
log('info', 'ffmpeg-core is loaded already');
|
|
||||||
resolve(window.Module);
|
|
||||||
}
|
}
|
||||||
});
|
log('info', 'ffmpeg-core is loaded already');
|
||||||
|
return Promise.resolve(window.Module);
|
||||||
|
};
|
||||||
|
@ -2,7 +2,7 @@ const TIMEOUT = 60000;
|
|||||||
const BASE_URL = 'http://localhost:3000/tests/assets';
|
const BASE_URL = 'http://localhost:3000/tests/assets';
|
||||||
const IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
const IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
||||||
const OPTIONS = {
|
const OPTIONS = {
|
||||||
corePath: '../node_modules/@ffmpeg/core/ffmpeg-core.js',
|
corePath: 'http://localhost:3000/node_modules/@ffmpeg/core/ffmpeg-core.js',
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof module !== 'undefined') {
|
if (typeof module !== 'undefined') {
|
||||||
|
Loading…
Reference in New Issue
Block a user