[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
|
unreachable, warn
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import {
|
import {
|
||||||
DOMCanvasFactory, DOMCMapReaderFactory, loadScript, PageViewport,
|
deprecated, DOMCanvasFactory, DOMCMapReaderFactory, loadScript, PageViewport,
|
||||||
releaseImageResources, RenderingCancelledException, StatTimer
|
releaseImageResources, RenderingCancelledException, StatTimer
|
||||||
} from './display_utils';
|
} from './display_utils';
|
||||||
import { FontFaceObject, FontLoader } from './font_loader';
|
import { FontFaceObject, FontLoader } from './font_loader';
|
||||||
@ -43,7 +43,6 @@ import { WebGLContext } from './webgl';
|
|||||||
const DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
|
const DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
|
||||||
const RENDERING_CANCELLED_TIMEOUT = 100; // ms
|
const RENDERING_CANCELLED_TIMEOUT = 100; // ms
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {function} IPDFStreamFactory
|
* @typedef {function} IPDFStreamFactory
|
||||||
* @param {DocumentInitParameters} params The document initialization
|
* @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.
|
// Workers aren't supported in Node.js, force-disabling them there.
|
||||||
isWorkerDisabled = true;
|
isWorkerDisabled = true;
|
||||||
|
|
||||||
|
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('LIB')) {
|
||||||
|
fallbackWorkerSrc = '../pdf.worker.js';
|
||||||
|
} else {
|
||||||
|
fallbackWorkerSrc = './pdf.worker.js';
|
||||||
|
}
|
||||||
fakeWorkerFilesLoader = function() {
|
fakeWorkerFilesLoader = function() {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
try {
|
try {
|
||||||
let worker;
|
const worker = __non_webpack_require__(getWorkerSrc());
|
||||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('LIB')) {
|
|
||||||
worker = __non_webpack_require__('../pdf.worker.js');
|
|
||||||
} else {
|
|
||||||
worker = __non_webpack_require__('./pdf.worker.js');
|
|
||||||
}
|
|
||||||
resolve(worker.WorkerMessageHandler);
|
resolve(worker.WorkerMessageHandler);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
reject(ex);
|
reject(ex);
|
||||||
@ -1507,6 +1506,9 @@ const PDFWorker = (function PDFWorkerClosure() {
|
|||||||
return GlobalWorkerOptions.workerSrc;
|
return GlobalWorkerOptions.workerSrc;
|
||||||
}
|
}
|
||||||
if (typeof fallbackWorkerSrc !== 'undefined') {
|
if (typeof fallbackWorkerSrc !== 'undefined') {
|
||||||
|
if (!isNodeJS) {
|
||||||
|
deprecated('No "GlobalWorkerOptions.workerSrc" specified.');
|
||||||
|
}
|
||||||
return fallbackWorkerSrc;
|
return fallbackWorkerSrc;
|
||||||
}
|
}
|
||||||
throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
|
throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
|
||||||
|
Loading…
Reference in New Issue
Block a user