[api-minor] Support loading the fake worker from GlobalWorkerOptions.workerSrc
in Node.js
There's no particularily good reason, as far as I can tell, to not support a custom worker path in Node.js environments (even if workers aren't supported). This patch thus make the Node.js fake worker loader code-path consistent with the fallback code-path used with *browser* fake worker loader. Finally, this patch also deprecates[1] the `fallbackWorkerSrc` functionality, except in Node.js, since the user should *always* provide correct worker options since the fallback is nothing more than a best-effort solution. --- [1] Although it probably shouldn't be removed until the next major version.
This commit is contained in:
parent
591e754831
commit
a5485e1ef7
@ -27,7 +27,7 @@ import {
|
||||
unreachable, warn
|
||||
} from '../shared/util';
|
||||
import {
|
||||
DOMCanvasFactory, DOMCMapReaderFactory, loadScript, PageViewport,
|
||||
deprecated, DOMCanvasFactory, DOMCMapReaderFactory, loadScript, PageViewport,
|
||||
releaseImageResources, RenderingCancelledException, StatTimer
|
||||
} from './display_utils';
|
||||
import { FontFaceObject, FontLoader } from './font_loader';
|
||||
@ -43,7 +43,6 @@ import { WebGLContext } from './webgl';
|
||||
const DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
|
||||
const RENDERING_CANCELLED_TIMEOUT = 100; // ms
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {function} IPDFStreamFactory
|
||||
* @param {DocumentInitParameters} params The document initialization
|
||||
@ -1477,15 +1476,15 @@ const PDFWorker = (function PDFWorkerClosure() {
|
||||
// Workers aren't supported in Node.js, force-disabling them there.
|
||||
isWorkerDisabled = true;
|
||||
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('LIB')) {
|
||||
fallbackWorkerSrc = '../pdf.worker.js';
|
||||
} else {
|
||||
fallbackWorkerSrc = './pdf.worker.js';
|
||||
}
|
||||
fakeWorkerFilesLoader = function() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
try {
|
||||
let worker;
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('LIB')) {
|
||||
worker = __non_webpack_require__('../pdf.worker.js');
|
||||
} else {
|
||||
worker = __non_webpack_require__('./pdf.worker.js');
|
||||
}
|
||||
const worker = __non_webpack_require__(getWorkerSrc());
|
||||
resolve(worker.WorkerMessageHandler);
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
@ -1507,6 +1506,9 @@ const PDFWorker = (function PDFWorkerClosure() {
|
||||
return GlobalWorkerOptions.workerSrc;
|
||||
}
|
||||
if (typeof fallbackWorkerSrc !== 'undefined') {
|
||||
if (!isNodeJS) {
|
||||
deprecated('No "GlobalWorkerOptions.workerSrc" specified.');
|
||||
}
|
||||
return fallbackWorkerSrc;
|
||||
}
|
||||
throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
|
||||
|
Loading…
Reference in New Issue
Block a user