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'); const { devDependencies } = require('../../package.json');
/* /*
@ -6,6 +5,6 @@ const { devDependencies } = require('../../package.json');
*/ */
module.exports = { module.exports = {
corePath: typeof process !== 'undefined' && process.env.NODE_ENV === 'development' 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`, : `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) => ( const readFromBlobOrFile = (blob) => (
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const fileReader = new FileReader(); const fileReader = new FileReader();
@ -27,7 +25,7 @@ module.exports = async (_data) => {
.map((c) => c.charCodeAt(0)); .map((c) => c.charCodeAt(0));
/* From remote server/URL */ /* From remote server/URL */
} else { } else {
const res = await fetch(resolveURL(_data)); const res = await fetch(new URL(_data, import.meta.url).href);
data = await res.arrayBuffer(); data = await res.arrayBuffer();
} }
/* From Blob or File */ /* From Blob or File */

View File

@ -1,5 +1,4 @@
/* eslint-disable no-undef */ /* eslint-disable no-undef */
const resolveURL = require('resolve-url');
const { log } = require('../utils/log'); const { log } = require('../utils/log');
const { const {
CREATE_FFMPEG_CORE_IS_NOT_DEFINED, CREATE_FFMPEG_CORE_IS_NOT_DEFINED,
@ -19,11 +18,54 @@ const toBlobURL = async (url, mimeType) => {
return blobURL; return blobURL;
}; };
if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
// in Web Worker context
module.exports = async ({ corePath: _corePath }) => { module.exports = async ({ corePath: _corePath }) => {
if (typeof _corePath !== 'string') { if (typeof _corePath !== 'string') {
throw Error('corePath should be a string!'); throw Error('corePath should be a string!');
} }
const coreRemotePath = resolveURL(_corePath); 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,
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( const corePath = await toBlobURL(
coreRemotePath, coreRemotePath,
'application/javascript', 'application/javascript',
@ -66,3 +108,5 @@ module.exports = async ({ corePath: _corePath }) => {
workerPath, workerPath,
}); });
}; };
}