Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional argument to PDFWorker for custom/bundled workers #7683

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1168,15 +1168,15 @@ var PDFWorker = (function PDFWorkerClosure() {
return URL.createObjectURL(new Blob([wrapper]));
}

function PDFWorker(name) {
function PDFWorker(name, customWorker) {
this.name = name;
this.destroyed = false;

this._readyCapability = createPromiseCapability();
this._port = null;
this._webWorker = null;
this._messageHandler = null;
this._initialize();
this._initialize(customWorker);
}

PDFWorker.prototype = /** @lends PDFWorker.prototype */ {
Expand All @@ -1192,7 +1192,7 @@ var PDFWorker = (function PDFWorkerClosure() {
return this._messageHandler;
},

_initialize: function PDFWorker_initialize() {
_initialize: function PDFWorker_initialize(customWorker) {
// If worker support isn't disabled explicit and the browser has worker
// support, create a new web worker and test if it/the browser fulfills
// all requirements to run parts of pdf.js in a web worker.
Expand All @@ -1214,7 +1214,12 @@ var PDFWorker = (function PDFWorkerClosure() {
//#endif
// Some versions of FF can't create a worker on localhost, see:
// https://bugzilla.mozilla.org/show_bug.cgi?id=683280
var worker = new Worker(workerSrc);
var worker;
if (customWorker) {
worker = customWorker;
} else {
worker = new Worker(workerSrc);
}
var messageHandler = new MessageHandler('main', 'worker', worker);
var terminateEarly = function() {
worker.removeEventListener('error', onWorkerError);
Expand Down