Skip to content

Commit ff9c27e

Browse files
committed
Removed references to resolveURL
1 parent 821f52a commit ff9c27e

File tree

3 files changed

+83
-42
lines changed

3 files changed

+83
-42
lines changed

src/browser/defaultOptions.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
const resolveURL = require('resolve-url');
21
const { devDependencies } = require('../../package.json');
32

43
/*
54
* Default options for browser environment
65
*/
76
module.exports = {
87
corePath: typeof process !== 'undefined' && process.env.NODE_ENV === 'development'
9-
? resolveURL('/node_modules/@ffmpeg/core/dist/ffmpeg-core.js')
8+
? new URL('/node_modules/@ffmpeg/core/dist/ffmpeg-core.js', import.meta.url).href
109
: `https://unpkg.com/@ffmpeg/core@${devDependencies['@ffmpeg/core'].substring(1)}/dist/ffmpeg-core.js`,
1110
};

src/browser/fetchFile.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const resolveURL = require('resolve-url');
2-
31
const readFromBlobOrFile = (blob) => (
42
new Promise((resolve, reject) => {
53
const fileReader = new FileReader();
@@ -27,7 +25,7 @@ module.exports = async (_data) => {
2725
.map((c) => c.charCodeAt(0));
2826
/* From remote server/URL */
2927
} else {
30-
const res = await fetch(resolveURL(_data));
28+
const res = await fetch(new URL(_data, import.meta.url).href);
3129
data = await res.arrayBuffer();
3230
}
3331
/* From Blob or File */

src/browser/getCreateFFmpegCore.js

Lines changed: 81 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable no-undef */
2-
const resolveURL = require('resolve-url');
32
const { log } = require('../utils/log');
43
const {
54
CREATE_FFMPEG_CORE_IS_NOT_DEFINED,
@@ -19,50 +18,95 @@ const toBlobURL = async (url, mimeType) => {
1918
return blobURL;
2019
};
2120

22-
module.exports = async ({ corePath: _corePath }) => {
23-
if (typeof _corePath !== 'string') {
24-
throw Error('corePath should be a string!');
25-
}
26-
const coreRemotePath = resolveURL(_corePath);
27-
const corePath = await toBlobURL(
28-
coreRemotePath,
29-
'application/javascript',
30-
);
31-
const wasmPath = await toBlobURL(
32-
coreRemotePath.replace('ffmpeg-core.js', 'ffmpeg-core.wasm'),
33-
'application/wasm',
34-
);
35-
const workerPath = await toBlobURL(
36-
coreRemotePath.replace('ffmpeg-core.js', 'ffmpeg-core.worker.js'),
37-
'application/javascript',
38-
);
39-
if (typeof createFFmpegCore === 'undefined') {
40-
return new Promise((resolve) => {
41-
const script = document.createElement('script');
42-
const eventHandler = () => {
43-
script.removeEventListener('load', eventHandler);
21+
if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
22+
// in Web Worker context
23+
module.exports = async ({ corePath: _corePath }) => {
24+
if (typeof _corePath !== 'string') {
25+
throw Error('corePath should be a string!');
26+
}
27+
const coreRemotePath = new URL(_corePath, import.meta.url).href;
28+
const corePath = await toBlobURL(
29+
coreRemotePath,
30+
'application/javascript',
31+
);
32+
const wasmPath = await toBlobURL(
33+
coreRemotePath.replace('ffmpeg-core.js', 'ffmpeg-core.wasm'),
34+
'application/wasm',
35+
);
36+
const workerPath = await toBlobURL(
37+
coreRemotePath.replace('ffmpeg-core.js', 'ffmpeg-core.worker.js'),
38+
'application/javascript',
39+
);
40+
if (typeof createFFmpegCore === 'undefined') {
41+
return new Promise((resolve) => {
4442
if (typeof createFFmpegCore === 'undefined') {
4543
throw Error(CREATE_FFMPEG_CORE_IS_NOT_DEFINED(coreRemotePath));
4644
}
45+
importScripts(corePath);
4746
log('info', 'ffmpeg-core.js script loaded');
4847
resolve({
4948
createFFmpegCore,
5049
corePath,
5150
wasmPath,
5251
workerPath,
5352
});
54-
};
55-
script.src = corePath;
56-
script.type = 'text/javascript';
57-
script.addEventListener('load', eventHandler);
58-
document.getElementsByTagName('head')[0].appendChild(script);
53+
});
54+
}
55+
log('info', 'ffmpeg-core.js script is loaded already');
56+
return Promise.resolve({
57+
createFFmpegCore,
58+
corePath,
59+
wasmPath,
60+
workerPath,
5961
});
60-
}
61-
log('info', 'ffmpeg-core.js script is loaded already');
62-
return Promise.resolve({
63-
createFFmpegCore,
64-
corePath,
65-
wasmPath,
66-
workerPath,
67-
});
68-
};
62+
};
63+
} else {
64+
module.exports = async ({ corePath: _corePath }) => {
65+
if (typeof _corePath !== 'string') {
66+
throw Error('corePath should be a string!');
67+
}
68+
const coreRemotePath = new URL(_corePath, import.meta.url).href;
69+
const corePath = await toBlobURL(
70+
coreRemotePath,
71+
'application/javascript',
72+
);
73+
const wasmPath = await toBlobURL(
74+
coreRemotePath.replace('ffmpeg-core.js', 'ffmpeg-core.wasm'),
75+
'application/wasm',
76+
);
77+
const workerPath = await toBlobURL(
78+
coreRemotePath.replace('ffmpeg-core.js', 'ffmpeg-core.worker.js'),
79+
'application/javascript',
80+
);
81+
if (typeof createFFmpegCore === 'undefined') {
82+
return new Promise((resolve) => {
83+
const script = document.createElement('script');
84+
const eventHandler = () => {
85+
script.removeEventListener('load', eventHandler);
86+
if (typeof createFFmpegCore === 'undefined') {
87+
throw Error(CREATE_FFMPEG_CORE_IS_NOT_DEFINED(coreRemotePath));
88+
}
89+
log('info', 'ffmpeg-core.js script loaded');
90+
resolve({
91+
createFFmpegCore,
92+
corePath,
93+
wasmPath,
94+
workerPath,
95+
});
96+
};
97+
script.src = corePath;
98+
script.type = 'text/javascript';
99+
script.addEventListener('load', eventHandler);
100+
document.getElementsByTagName('head')[0].appendChild(script);
101+
});
102+
}
103+
log('info', 'ffmpeg-core.js script is loaded already');
104+
return Promise.resolve({
105+
createFFmpegCore,
106+
corePath,
107+
wasmPath,
108+
workerPath,
109+
});
110+
};
111+
}
112+

0 commit comments

Comments
 (0)