Removed references to resolveURL

This commit is contained in:
Nathan Johnson 2022-04-04 21:37:57 -05:00
parent 8d45d585b2
commit 6e99e5f96f
3 changed files with 83 additions and 42 deletions

View File

@ -1,4 +1,3 @@
const resolveURL = require('resolve-url');
const { devDependencies } = require('../../package.json');
/*
@ -6,6 +5,6 @@ const { devDependencies } = require('../../package.json');
*/
module.exports = {
corePath: typeof process !== 'undefined' && process.env.NODE_ENV === 'development'
? resolveURL('/node_modules/@ffmpeg/core/dist/ffmpeg-core.js')
? new URL('/node_modules/@ffmpeg/core/dist/ffmpeg-core.js', import.meta.url).href
: `https://unpkg.com/@ffmpeg/core@${devDependencies['@ffmpeg/core'].substring(1)}/dist/ffmpeg-core.js`,
};

View File

@ -1,5 +1,3 @@
const resolveURL = require('resolve-url');
const readFromBlobOrFile = (blob) => (
new Promise((resolve, reject) => {
const fileReader = new FileReader();
@ -27,7 +25,7 @@ module.exports = async (_data) => {
.map((c) => c.charCodeAt(0));
/* From remote server/URL */
} else {
const res = await fetch(resolveURL(_data));
const res = await fetch(new URL(_data, import.meta.url).href);
data = await res.arrayBuffer();
}
/* From Blob or File */

View File

@ -1,5 +1,4 @@
/* eslint-disable no-undef */
const resolveURL = require('resolve-url');
const { log } = require('../utils/log');
const {
CREATE_FFMPEG_CORE_IS_NOT_DEFINED,
@ -19,31 +18,31 @@ const toBlobURL = async (url, mimeType) => {
return blobURL;
};
module.exports = async ({ corePath: _corePath }) => {
if (typeof _corePath !== 'string') {
throw Error('corePath should be a string!');
}
const coreRemotePath = resolveURL(_corePath);
const corePath = await toBlobURL(
coreRemotePath,
'application/javascript',
);
const wasmPath = await toBlobURL(
coreRemotePath.replace('ffmpeg-core.js', 'ffmpeg-core.wasm'),
'application/wasm',
);
const workerPath = await toBlobURL(
coreRemotePath.replace('ffmpeg-core.js', 'ffmpeg-core.worker.js'),
'application/javascript',
);
if (typeof createFFmpegCore === 'undefined') {
return new Promise((resolve) => {
const script = document.createElement('script');
const eventHandler = () => {
script.removeEventListener('load', eventHandler);
if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
// in Web Worker context
module.exports = async ({ corePath: _corePath }) => {
if (typeof _corePath !== 'string') {
throw Error('corePath should be a string!');
}
const coreRemotePath = new URL(_corePath, import.meta.url).href;
const corePath = await toBlobURL(
coreRemotePath,
'application/javascript',
);
const wasmPath = await toBlobURL(
coreRemotePath.replace('ffmpeg-core.js', 'ffmpeg-core.wasm'),
'application/wasm',
);
const workerPath = await toBlobURL(
coreRemotePath.replace('ffmpeg-core.js', 'ffmpeg-core.worker.js'),
'application/javascript',
);
if (typeof createFFmpegCore === 'undefined') {
return new Promise((resolve) => {
if (typeof createFFmpegCore === 'undefined') {
throw Error(CREATE_FFMPEG_CORE_IS_NOT_DEFINED(coreRemotePath));
}
importScripts(corePath);
log('info', 'ffmpeg-core.js script loaded');
resolve({
createFFmpegCore,
@ -51,18 +50,63 @@ module.exports = async ({ corePath: _corePath }) => {
wasmPath,
workerPath,
});
};
script.src = corePath;
script.type = 'text/javascript';
script.addEventListener('load', eventHandler);
document.getElementsByTagName('head')[0].appendChild(script);
});
}
log('info', 'ffmpeg-core.js script is loaded already');
return Promise.resolve({
createFFmpegCore,
corePath,
wasmPath,
workerPath,
});
}
log('info', 'ffmpeg-core.js script is loaded already');
return Promise.resolve({
createFFmpegCore,
corePath,
wasmPath,
workerPath,
});
};
};
} else {
module.exports = async ({ corePath: _corePath }) => {
if (typeof _corePath !== 'string') {
throw Error('corePath should be a string!');
}
const coreRemotePath = new URL(_corePath, import.meta.url).href;
const corePath = await toBlobURL(
coreRemotePath,
'application/javascript',
);
const wasmPath = await toBlobURL(
coreRemotePath.replace('ffmpeg-core.js', 'ffmpeg-core.wasm'),
'application/wasm',
);
const workerPath = await toBlobURL(
coreRemotePath.replace('ffmpeg-core.js', 'ffmpeg-core.worker.js'),
'application/javascript',
);
if (typeof createFFmpegCore === 'undefined') {
return new Promise((resolve) => {
const script = document.createElement('script');
const eventHandler = () => {
script.removeEventListener('load', eventHandler);
if (typeof createFFmpegCore === 'undefined') {
throw Error(CREATE_FFMPEG_CORE_IS_NOT_DEFINED(coreRemotePath));
}
log('info', 'ffmpeg-core.js script loaded');
resolve({
createFFmpegCore,
corePath,
wasmPath,
workerPath,
});
};
script.src = corePath;
script.type = 'text/javascript';
script.addEventListener('load', eventHandler);
document.getElementsByTagName('head')[0].appendChild(script);
});
}
log('info', 'ffmpeg-core.js script is loaded already');
return Promise.resolve({
createFFmpegCore,
corePath,
wasmPath,
workerPath,
});
};
}