pdfjs-dist 2.0.943 → 2.4.456
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/CODE_OF_CONDUCT.md +15 -0
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8286 -14230
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +25500 -26628
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25473 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +57878 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +407 -0
- package/es5/web/pdf_viewer.js +7757 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +2887 -4094
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +855 -778
- package/lib/core/arithmetic_decoder.js +325 -311
- package/lib/core/bidi.js +117 -50
- package/lib/core/ccitt.js +251 -89
- package/lib/core/ccitt_stream.js +26 -16
- package/lib/core/cff_parser.js +525 -197
- package/lib/core/charsets.js +6 -5
- package/lib/core/chunked_stream.js +541 -406
- package/lib/core/cmap.js +368 -253
- package/lib/core/colorspace.js +781 -800
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +609 -422
- package/lib/core/document.js +649 -481
- package/lib/core/encodings.js +33 -24
- package/lib/core/evaluator.js +1471 -736
- package/lib/core/font_renderer.js +289 -149
- package/lib/core/fonts.js +1067 -413
- package/lib/core/function.js +517 -287
- package/lib/core/glyphlist.js +4529 -4527
- package/lib/core/image.js +232 -114
- package/lib/core/image_utils.js +94 -0
- package/lib/core/jbig2.js +711 -342
- package/lib/core/jbig2_stream.js +31 -19
- package/lib/core/jpeg_stream.js +151 -26
- package/lib/core/jpg.js +433 -181
- package/lib/core/jpx.js +551 -143
- package/lib/core/jpx_stream.js +40 -28
- package/lib/core/metrics.js +2931 -2931
- package/lib/core/murmurhash3.js +104 -97
- package/lib/core/obj.js +1561 -1053
- package/lib/core/operator_list.js +192 -64
- package/lib/core/parser.js +1162 -864
- package/lib/core/pattern.js +224 -75
- package/lib/core/pdf_manager.js +154 -285
- package/lib/core/primitives.js +145 -69
- package/lib/core/ps_parser.js +212 -162
- package/lib/core/standard_fonts.js +245 -244
- package/lib/core/stream.js +353 -81
- package/lib/core/type1_parser.js +218 -68
- package/lib/core/unicode.js +1682 -1655
- package/lib/core/worker.js +233 -302
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +808 -862
- package/lib/display/api.js +1778 -1462
- package/lib/display/api_compatibility.js +14 -9
- package/lib/display/canvas.js +463 -140
- package/lib/display/content_disposition.js +86 -58
- package/lib/display/display_utils.js +524 -0
- package/lib/display/fetch_stream.js +202 -274
- package/lib/display/font_loader.js +311 -333
- package/lib/display/metadata.js +98 -88
- package/lib/display/network.js +343 -347
- package/lib/display/network_utils.js +46 -26
- package/lib/display/node_stream.js +326 -404
- package/lib/display/pattern_helper.js +168 -69
- package/lib/display/svg.js +1296 -885
- package/lib/display/text_layer.js +229 -103
- package/lib/display/transport_stream.js +290 -250
- package/lib/display/webgl.js +116 -83
- package/lib/display/worker_options.js +6 -5
- package/lib/display/xml_parser.js +358 -337
- package/lib/examples/node/domstubs.js +95 -39
- package/lib/pdf.js +49 -31
- package/lib/pdf.worker.js +7 -5
- package/lib/shared/compatibility.js +3 -145
- package/lib/shared/is_node.js +8 -7
- package/lib/shared/message_handler.js +367 -314
- package/lib/shared/util.js +421 -415
- package/lib/test/unit/annotation_spec.js +1570 -690
- package/lib/test/unit/api_spec.js +855 -493
- package/lib/test/unit/bidi_spec.js +12 -12
- package/lib/test/unit/cff_parser_spec.js +88 -61
- package/lib/test/unit/clitests_helper.js +9 -12
- package/lib/test/unit/cmap_spec.js +140 -88
- package/lib/test/unit/colorspace_spec.js +204 -152
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +194 -182
- package/lib/test/unit/custom_spec.js +50 -64
- package/lib/test/unit/display_svg_spec.js +53 -38
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +17 -22
- package/lib/test/unit/encodings_spec.js +15 -57
- package/lib/test/unit/evaluator_spec.js +90 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +219 -205
- package/lib/test/unit/jasmine-boot.js +68 -39
- package/lib/test/unit/message_handler_spec.js +187 -160
- package/lib/test/unit/metadata_spec.js +87 -34
- package/lib/test/unit/murmurhash3_spec.js +13 -13
- package/lib/test/unit/network_spec.js +26 -59
- package/lib/test/unit/network_utils_spec.js +187 -121
- package/lib/test/unit/node_stream_spec.js +98 -90
- package/lib/test/unit/parser_spec.js +173 -131
- package/lib/test/unit/pdf_find_controller_spec.js +148 -67
- package/lib/test/unit/pdf_find_utils_spec.js +35 -34
- package/lib/test/unit/pdf_history_spec.js +45 -33
- package/lib/test/unit/primitives_spec.js +161 -126
- package/lib/test/unit/stream_spec.js +22 -15
- package/lib/test/unit/test_utils.js +149 -98
- package/lib/test/unit/testreporter.js +36 -18
- package/lib/test/unit/type1_parser_spec.js +46 -44
- package/lib/test/unit/ui_utils_spec.js +388 -372
- package/lib/test/unit/unicode_spec.js +49 -46
- package/lib/test/unit/util_spec.js +144 -248
- package/lib/web/annotation_layer_builder.js +75 -95
- package/lib/web/app.js +1538 -1147
- package/lib/web/app_options.js +116 -104
- package/lib/web/base_viewer.js +950 -775
- package/lib/web/chromecom.js +217 -225
- package/lib/web/debugger.js +236 -148
- package/lib/web/download_manager.js +50 -50
- package/lib/web/firefox_print_service.js +51 -33
- package/lib/web/firefoxcom.js +225 -352
- package/lib/web/genericcom.js +30 -93
- package/lib/web/genericl10n.js +26 -143
- package/lib/web/grab_to_pan.js +57 -33
- package/lib/web/interfaces.js +105 -232
- package/lib/web/overlay_manager.js +73 -227
- package/lib/web/password_prompt.js +44 -62
- package/lib/web/pdf_attachment_viewer.js +118 -123
- package/lib/web/pdf_cursor_tools.js +89 -93
- package/lib/web/pdf_document_properties.js +242 -281
- package/lib/web/pdf_find_bar.js +157 -163
- package/lib/web/pdf_find_controller.js +598 -454
- package/lib/web/pdf_find_utils.js +32 -16
- package/lib/web/pdf_history.js +481 -355
- package/lib/web/pdf_link_service.js +355 -323
- package/lib/web/pdf_outline_viewer.js +167 -152
- package/lib/web/pdf_page_view.js +511 -457
- package/lib/web/pdf_presentation_mode.js +347 -335
- package/lib/web/pdf_print_service.js +133 -103
- package/lib/web/pdf_rendering_queue.js +98 -100
- package/lib/web/pdf_sidebar.js +323 -299
- package/lib/web/pdf_sidebar_resizer.js +107 -108
- package/lib/web/pdf_single_page_viewer.js +94 -146
- package/lib/web/pdf_thumbnail_view.js +319 -269
- package/lib/web/pdf_thumbnail_viewer.js +219 -199
- package/lib/web/pdf_viewer.component.js +111 -32
- package/lib/web/pdf_viewer.js +61 -101
- package/lib/web/preferences.js +87 -272
- package/lib/web/secondary_toolbar.js +207 -220
- package/lib/web/text_layer_builder.js +322 -322
- package/lib/web/toolbar.js +227 -180
- package/lib/web/ui_utils.js +476 -421
- package/lib/web/view_history.js +59 -208
- package/lib/web/viewer_compatibility.js +9 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +36 -22
- package/web/pdf_viewer.js +4407 -4516
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/display/dom_utils.js +0 -441
- package/lib/shared/streams_polyfill.js +0 -39
- package/lib/shared/url_polyfill.js +0 -50
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/web/dom_events.js +0 -140
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2020 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -19,445 +19,498 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
exports.MessageHandler =
|
27
|
+
exports.MessageHandler = void 0;
|
28
28
|
|
29
|
-
var
|
29
|
+
var _util = require("./util.js");
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
return _context.abrupt('return');
|
48
|
-
|
49
|
-
case 2:
|
50
|
-
return _context.abrupt('return', fn.apply(thisArg, args));
|
51
|
-
|
52
|
-
case 3:
|
53
|
-
case 'end':
|
54
|
-
return _context.stop();
|
55
|
-
}
|
56
|
-
}
|
57
|
-
}, _callee, this);
|
58
|
-
}));
|
59
|
-
|
60
|
-
return function resolveCall(_x2, _x3) {
|
61
|
-
return _ref.apply(this, arguments);
|
62
|
-
};
|
63
|
-
}();
|
64
|
-
|
65
|
-
var _util = require('./util');
|
66
|
-
|
67
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
68
|
-
|
69
|
-
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
|
31
|
+
const CallbackKind = {
|
32
|
+
UNKNOWN: 0,
|
33
|
+
DATA: 1,
|
34
|
+
ERROR: 2
|
35
|
+
};
|
36
|
+
const StreamKind = {
|
37
|
+
UNKNOWN: 0,
|
38
|
+
CANCEL: 1,
|
39
|
+
CANCEL_COMPLETE: 2,
|
40
|
+
CLOSE: 3,
|
41
|
+
ENQUEUE: 4,
|
42
|
+
ERROR: 5,
|
43
|
+
PULL: 6,
|
44
|
+
PULL_COMPLETE: 7,
|
45
|
+
START_COMPLETE: 8
|
46
|
+
};
|
70
47
|
|
71
48
|
function wrapReason(reason) {
|
72
|
-
if (
|
49
|
+
if (typeof reason !== "object" || reason === null) {
|
73
50
|
return reason;
|
74
51
|
}
|
52
|
+
|
75
53
|
switch (reason.name) {
|
76
|
-
case
|
54
|
+
case "AbortException":
|
77
55
|
return new _util.AbortException(reason.message);
|
78
|
-
|
56
|
+
|
57
|
+
case "MissingPDFException":
|
79
58
|
return new _util.MissingPDFException(reason.message);
|
80
|
-
|
59
|
+
|
60
|
+
case "UnexpectedResponseException":
|
81
61
|
return new _util.UnexpectedResponseException(reason.message, reason.status);
|
82
|
-
|
62
|
+
|
63
|
+
case "UnknownErrorException":
|
83
64
|
return new _util.UnknownErrorException(reason.message, reason.details);
|
65
|
+
|
66
|
+
default:
|
67
|
+
return new _util.UnknownErrorException(reason.message, reason.toString());
|
84
68
|
}
|
85
69
|
}
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
if ('error' in data) {
|
128
|
-
callback.reject(wrapReason(data.error));
|
70
|
+
|
71
|
+
class MessageHandler {
|
72
|
+
constructor(sourceName, targetName, comObj) {
|
73
|
+
this.sourceName = sourceName;
|
74
|
+
this.targetName = targetName;
|
75
|
+
this.comObj = comObj;
|
76
|
+
this.callbackId = 1;
|
77
|
+
this.streamId = 1;
|
78
|
+
this.postMessageTransfers = true;
|
79
|
+
this.streamSinks = Object.create(null);
|
80
|
+
this.streamControllers = Object.create(null);
|
81
|
+
this.callbackCapabilities = Object.create(null);
|
82
|
+
this.actionHandler = Object.create(null);
|
83
|
+
|
84
|
+
this._onComObjOnMessage = event => {
|
85
|
+
const data = event.data;
|
86
|
+
|
87
|
+
if (data.targetName !== this.sourceName) {
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
|
91
|
+
if (data.stream) {
|
92
|
+
this._processStreamMessage(data);
|
93
|
+
|
94
|
+
return;
|
95
|
+
}
|
96
|
+
|
97
|
+
if (data.callback) {
|
98
|
+
const callbackId = data.callbackId;
|
99
|
+
const capability = this.callbackCapabilities[callbackId];
|
100
|
+
|
101
|
+
if (!capability) {
|
102
|
+
throw new Error(`Cannot resolve callback ${callbackId}`);
|
103
|
+
}
|
104
|
+
|
105
|
+
delete this.callbackCapabilities[callbackId];
|
106
|
+
|
107
|
+
if (data.callback === CallbackKind.DATA) {
|
108
|
+
capability.resolve(data.data);
|
109
|
+
} else if (data.callback === CallbackKind.ERROR) {
|
110
|
+
capability.reject(wrapReason(data.reason));
|
129
111
|
} else {
|
130
|
-
callback
|
112
|
+
throw new Error("Unexpected callback case");
|
131
113
|
}
|
132
|
-
|
133
|
-
|
114
|
+
|
115
|
+
return;
|
134
116
|
}
|
135
|
-
|
136
|
-
|
117
|
+
|
118
|
+
const action = this.actionHandler[data.action];
|
119
|
+
|
120
|
+
if (!action) {
|
121
|
+
throw new Error(`Unknown action from worker: ${data.action}`);
|
122
|
+
}
|
123
|
+
|
137
124
|
if (data.callbackId) {
|
138
|
-
|
139
|
-
|
140
|
-
Promise
|
141
|
-
|
125
|
+
const sourceName = this.sourceName;
|
126
|
+
const targetName = data.sourceName;
|
127
|
+
new Promise(function (resolve) {
|
128
|
+
resolve(action(data.data));
|
142
129
|
}).then(function (result) {
|
143
130
|
comObj.postMessage({
|
144
|
-
sourceName
|
145
|
-
targetName
|
146
|
-
|
131
|
+
sourceName,
|
132
|
+
targetName,
|
133
|
+
callback: CallbackKind.DATA,
|
147
134
|
callbackId: data.callbackId,
|
148
135
|
data: result
|
149
136
|
});
|
150
137
|
}, function (reason) {
|
151
138
|
comObj.postMessage({
|
152
|
-
sourceName
|
153
|
-
targetName
|
154
|
-
|
139
|
+
sourceName,
|
140
|
+
targetName,
|
141
|
+
callback: CallbackKind.ERROR,
|
155
142
|
callbackId: data.callbackId,
|
156
|
-
|
143
|
+
reason: wrapReason(reason)
|
157
144
|
});
|
158
145
|
});
|
159
|
-
|
160
|
-
_this._createStreamSink(data);
|
161
|
-
} else {
|
162
|
-
action[0].call(action[1], data.data);
|
146
|
+
return;
|
163
147
|
}
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
}
|
170
|
-
|
171
|
-
|
172
|
-
|
148
|
+
|
149
|
+
if (data.streamId) {
|
150
|
+
this._createStreamSink(data);
|
151
|
+
|
152
|
+
return;
|
153
|
+
}
|
154
|
+
|
155
|
+
action(data.data);
|
156
|
+
};
|
157
|
+
|
158
|
+
comObj.addEventListener("message", this._onComObjOnMessage);
|
159
|
+
}
|
160
|
+
|
161
|
+
on(actionName, handler) {
|
162
|
+
const ah = this.actionHandler;
|
163
|
+
|
173
164
|
if (ah[actionName]) {
|
174
|
-
throw new Error(
|
165
|
+
throw new Error(`There is already an actionName called "${actionName}"`);
|
175
166
|
}
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
action: actionName,
|
183
|
-
data: data
|
184
|
-
};
|
185
|
-
this.postMessage(message, transfers);
|
186
|
-
},
|
187
|
-
sendWithPromise: function sendWithPromise(actionName, data, transfers) {
|
188
|
-
var callbackId = this.callbackId++;
|
189
|
-
var message = {
|
167
|
+
|
168
|
+
ah[actionName] = handler;
|
169
|
+
}
|
170
|
+
|
171
|
+
send(actionName, data, transfers) {
|
172
|
+
this._postMessage({
|
190
173
|
sourceName: this.sourceName,
|
191
174
|
targetName: this.targetName,
|
192
175
|
action: actionName,
|
193
|
-
data
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
176
|
+
data
|
177
|
+
}, transfers);
|
178
|
+
}
|
179
|
+
|
180
|
+
sendWithPromise(actionName, data, transfers) {
|
181
|
+
const callbackId = this.callbackId++;
|
182
|
+
const capability = (0, _util.createPromiseCapability)();
|
183
|
+
this.callbackCapabilities[callbackId] = capability;
|
184
|
+
|
198
185
|
try {
|
199
|
-
this.
|
200
|
-
|
201
|
-
|
186
|
+
this._postMessage({
|
187
|
+
sourceName: this.sourceName,
|
188
|
+
targetName: this.targetName,
|
189
|
+
action: actionName,
|
190
|
+
callbackId,
|
191
|
+
data
|
192
|
+
}, transfers);
|
193
|
+
} catch (ex) {
|
194
|
+
capability.reject(ex);
|
202
195
|
}
|
196
|
+
|
203
197
|
return capability.promise;
|
204
|
-
}
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
return new
|
212
|
-
start:
|
213
|
-
|
214
|
-
|
215
|
-
controller
|
198
|
+
}
|
199
|
+
|
200
|
+
sendWithStream(actionName, data, queueingStrategy, transfers) {
|
201
|
+
const streamId = this.streamId++;
|
202
|
+
const sourceName = this.sourceName;
|
203
|
+
const targetName = this.targetName;
|
204
|
+
const comObj = this.comObj;
|
205
|
+
return new ReadableStream({
|
206
|
+
start: controller => {
|
207
|
+
const startCapability = (0, _util.createPromiseCapability)();
|
208
|
+
this.streamControllers[streamId] = {
|
209
|
+
controller,
|
216
210
|
startCall: startCapability,
|
211
|
+
pullCall: null,
|
212
|
+
cancelCall: null,
|
217
213
|
isClosed: false
|
218
214
|
};
|
219
|
-
|
220
|
-
|
221
|
-
|
215
|
+
|
216
|
+
this._postMessage({
|
217
|
+
sourceName,
|
218
|
+
targetName,
|
222
219
|
action: actionName,
|
223
|
-
streamId
|
224
|
-
data
|
220
|
+
streamId,
|
221
|
+
data,
|
225
222
|
desiredSize: controller.desiredSize
|
226
|
-
});
|
223
|
+
}, transfers);
|
224
|
+
|
227
225
|
return startCapability.promise;
|
228
226
|
},
|
229
|
-
pull:
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
sourceName
|
234
|
-
targetName
|
235
|
-
stream:
|
236
|
-
streamId
|
227
|
+
pull: controller => {
|
228
|
+
const pullCapability = (0, _util.createPromiseCapability)();
|
229
|
+
this.streamControllers[streamId].pullCall = pullCapability;
|
230
|
+
comObj.postMessage({
|
231
|
+
sourceName,
|
232
|
+
targetName,
|
233
|
+
stream: StreamKind.PULL,
|
234
|
+
streamId,
|
237
235
|
desiredSize: controller.desiredSize
|
238
236
|
});
|
239
237
|
return pullCapability.promise;
|
240
238
|
},
|
241
|
-
cancel:
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
streamId
|
239
|
+
cancel: reason => {
|
240
|
+
(0, _util.assert)(reason instanceof Error, "cancel must have a valid reason");
|
241
|
+
const cancelCapability = (0, _util.createPromiseCapability)();
|
242
|
+
this.streamControllers[streamId].cancelCall = cancelCapability;
|
243
|
+
this.streamControllers[streamId].isClosed = true;
|
244
|
+
comObj.postMessage({
|
245
|
+
sourceName,
|
246
|
+
targetName,
|
247
|
+
stream: StreamKind.CANCEL,
|
248
|
+
streamId,
|
249
|
+
reason: wrapReason(reason)
|
251
250
|
});
|
252
251
|
return cancelCapability.promise;
|
253
252
|
}
|
254
253
|
}, queueingStrategy);
|
255
|
-
}
|
256
|
-
_createStreamSink: function _createStreamSink(data) {
|
257
|
-
var _this3 = this;
|
258
|
-
|
259
|
-
var self = this;
|
260
|
-
var action = this.actionHandler[data.action];
|
261
|
-
var streamId = data.streamId;
|
262
|
-
var desiredSize = data.desiredSize;
|
263
|
-
var sourceName = this.sourceName;
|
264
|
-
var targetName = data.sourceName;
|
265
|
-
var capability = (0, _util.createPromiseCapability)();
|
266
|
-
var sendStreamRequest = function sendStreamRequest(_ref2) {
|
267
|
-
var stream = _ref2.stream,
|
268
|
-
chunk = _ref2.chunk,
|
269
|
-
transfers = _ref2.transfers,
|
270
|
-
success = _ref2.success,
|
271
|
-
reason = _ref2.reason;
|
272
|
-
|
273
|
-
_this3.postMessage({
|
274
|
-
sourceName: sourceName,
|
275
|
-
targetName: targetName,
|
276
|
-
stream: stream,
|
277
|
-
streamId: streamId,
|
278
|
-
chunk: chunk,
|
279
|
-
success: success,
|
280
|
-
reason: reason
|
281
|
-
}, transfers);
|
282
|
-
};
|
283
|
-
var streamSink = {
|
284
|
-
enqueue: function enqueue(chunk) {
|
285
|
-
var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
286
|
-
var transfers = arguments[2];
|
254
|
+
}
|
287
255
|
|
256
|
+
_createStreamSink(data) {
|
257
|
+
const self = this;
|
258
|
+
const action = this.actionHandler[data.action];
|
259
|
+
const streamId = data.streamId;
|
260
|
+
const sourceName = this.sourceName;
|
261
|
+
const targetName = data.sourceName;
|
262
|
+
const comObj = this.comObj;
|
263
|
+
const streamSink = {
|
264
|
+
enqueue(chunk, size = 1, transfers) {
|
288
265
|
if (this.isCancelled) {
|
289
266
|
return;
|
290
267
|
}
|
291
|
-
|
268
|
+
|
269
|
+
const lastDesiredSize = this.desiredSize;
|
292
270
|
this.desiredSize -= size;
|
271
|
+
|
293
272
|
if (lastDesiredSize > 0 && this.desiredSize <= 0) {
|
294
273
|
this.sinkCapability = (0, _util.createPromiseCapability)();
|
295
274
|
this.ready = this.sinkCapability.promise;
|
296
275
|
}
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
276
|
+
|
277
|
+
self._postMessage({
|
278
|
+
sourceName,
|
279
|
+
targetName,
|
280
|
+
stream: StreamKind.ENQUEUE,
|
281
|
+
streamId,
|
282
|
+
chunk
|
283
|
+
}, transfers);
|
302
284
|
},
|
303
|
-
|
285
|
+
|
286
|
+
close() {
|
304
287
|
if (this.isCancelled) {
|
305
288
|
return;
|
306
289
|
}
|
290
|
+
|
307
291
|
this.isCancelled = true;
|
308
|
-
|
292
|
+
comObj.postMessage({
|
293
|
+
sourceName,
|
294
|
+
targetName,
|
295
|
+
stream: StreamKind.CLOSE,
|
296
|
+
streamId
|
297
|
+
});
|
309
298
|
delete self.streamSinks[streamId];
|
310
299
|
},
|
311
|
-
|
300
|
+
|
301
|
+
error(reason) {
|
302
|
+
(0, _util.assert)(reason instanceof Error, "error must have a valid reason");
|
303
|
+
|
312
304
|
if (this.isCancelled) {
|
313
305
|
return;
|
314
306
|
}
|
307
|
+
|
315
308
|
this.isCancelled = true;
|
316
|
-
|
317
|
-
|
318
|
-
|
309
|
+
comObj.postMessage({
|
310
|
+
sourceName,
|
311
|
+
targetName,
|
312
|
+
stream: StreamKind.ERROR,
|
313
|
+
streamId,
|
314
|
+
reason: wrapReason(reason)
|
319
315
|
});
|
320
316
|
},
|
321
317
|
|
322
|
-
sinkCapability:
|
318
|
+
sinkCapability: (0, _util.createPromiseCapability)(),
|
323
319
|
onPull: null,
|
324
320
|
onCancel: null,
|
325
321
|
isCancelled: false,
|
326
|
-
desiredSize: desiredSize,
|
322
|
+
desiredSize: data.desiredSize,
|
327
323
|
ready: null
|
328
324
|
};
|
329
325
|
streamSink.sinkCapability.resolve();
|
330
326
|
streamSink.ready = streamSink.sinkCapability.promise;
|
331
327
|
this.streamSinks[streamId] = streamSink;
|
332
|
-
|
333
|
-
|
334
|
-
|
328
|
+
new Promise(function (resolve) {
|
329
|
+
resolve(action(data.data, streamSink));
|
330
|
+
}).then(function () {
|
331
|
+
comObj.postMessage({
|
332
|
+
sourceName,
|
333
|
+
targetName,
|
334
|
+
stream: StreamKind.START_COMPLETE,
|
335
|
+
streamId,
|
335
336
|
success: true
|
336
337
|
});
|
337
338
|
}, function (reason) {
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
339
|
+
comObj.postMessage({
|
340
|
+
sourceName,
|
341
|
+
targetName,
|
342
|
+
stream: StreamKind.START_COMPLETE,
|
343
|
+
streamId,
|
344
|
+
reason: wrapReason(reason)
|
342
345
|
});
|
343
346
|
});
|
344
|
-
}
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
var stream = _ref3.stream,
|
353
|
-
success = _ref3.success,
|
354
|
-
reason = _ref3.reason;
|
355
|
-
|
356
|
-
_this4.comObj.postMessage({
|
357
|
-
sourceName: sourceName,
|
358
|
-
targetName: targetName,
|
359
|
-
stream: stream,
|
360
|
-
success: success,
|
361
|
-
streamId: streamId,
|
362
|
-
reason: reason
|
363
|
-
});
|
364
|
-
};
|
365
|
-
var deleteStreamController = function deleteStreamController() {
|
366
|
-
Promise.all([_this4.streamControllers[data.streamId].startCall, _this4.streamControllers[data.streamId].pullCall, _this4.streamControllers[data.streamId].cancelCall].map(function (capability) {
|
367
|
-
return capability && finalize(capability.promise);
|
368
|
-
})).then(function () {
|
369
|
-
delete _this4.streamControllers[data.streamId];
|
370
|
-
});
|
371
|
-
};
|
347
|
+
}
|
348
|
+
|
349
|
+
_processStreamMessage(data) {
|
350
|
+
const streamId = data.streamId;
|
351
|
+
const sourceName = this.sourceName;
|
352
|
+
const targetName = data.sourceName;
|
353
|
+
const comObj = this.comObj;
|
354
|
+
|
372
355
|
switch (data.stream) {
|
373
|
-
case
|
374
|
-
|
356
|
+
case StreamKind.START_COMPLETE:
|
357
|
+
if (data.success) {
|
358
|
+
this.streamControllers[streamId].startCall.resolve();
|
359
|
+
} else {
|
360
|
+
this.streamControllers[streamId].startCall.reject(wrapReason(data.reason));
|
361
|
+
}
|
362
|
+
|
375
363
|
break;
|
376
|
-
|
377
|
-
|
364
|
+
|
365
|
+
case StreamKind.PULL_COMPLETE:
|
366
|
+
if (data.success) {
|
367
|
+
this.streamControllers[streamId].pullCall.resolve();
|
368
|
+
} else {
|
369
|
+
this.streamControllers[streamId].pullCall.reject(wrapReason(data.reason));
|
370
|
+
}
|
371
|
+
|
378
372
|
break;
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
373
|
+
|
374
|
+
case StreamKind.PULL:
|
375
|
+
if (!this.streamSinks[streamId]) {
|
376
|
+
comObj.postMessage({
|
377
|
+
sourceName,
|
378
|
+
targetName,
|
379
|
+
stream: StreamKind.PULL_COMPLETE,
|
380
|
+
streamId,
|
383
381
|
success: true
|
384
382
|
});
|
385
383
|
break;
|
386
384
|
}
|
387
|
-
|
388
|
-
|
385
|
+
|
386
|
+
if (this.streamSinks[streamId].desiredSize <= 0 && data.desiredSize > 0) {
|
387
|
+
this.streamSinks[streamId].sinkCapability.resolve();
|
389
388
|
}
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
389
|
+
|
390
|
+
this.streamSinks[streamId].desiredSize = data.desiredSize;
|
391
|
+
const {
|
392
|
+
onPull
|
393
|
+
} = this.streamSinks[data.streamId];
|
394
|
+
new Promise(function (resolve) {
|
395
|
+
resolve(onPull && onPull());
|
396
|
+
}).then(function () {
|
397
|
+
comObj.postMessage({
|
398
|
+
sourceName,
|
399
|
+
targetName,
|
400
|
+
stream: StreamKind.PULL_COMPLETE,
|
401
|
+
streamId,
|
394
402
|
success: true
|
395
403
|
});
|
396
404
|
}, function (reason) {
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
405
|
+
comObj.postMessage({
|
406
|
+
sourceName,
|
407
|
+
targetName,
|
408
|
+
stream: StreamKind.PULL_COMPLETE,
|
409
|
+
streamId,
|
410
|
+
reason: wrapReason(reason)
|
401
411
|
});
|
402
412
|
});
|
403
413
|
break;
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
414
|
+
|
415
|
+
case StreamKind.ENQUEUE:
|
416
|
+
(0, _util.assert)(this.streamControllers[streamId], "enqueue should have stream controller");
|
417
|
+
|
418
|
+
if (this.streamControllers[streamId].isClosed) {
|
419
|
+
break;
|
408
420
|
}
|
421
|
+
|
422
|
+
this.streamControllers[streamId].controller.enqueue(data.chunk);
|
409
423
|
break;
|
410
|
-
|
411
|
-
|
412
|
-
|
424
|
+
|
425
|
+
case StreamKind.CLOSE:
|
426
|
+
(0, _util.assert)(this.streamControllers[streamId], "close should have stream controller");
|
427
|
+
|
428
|
+
if (this.streamControllers[streamId].isClosed) {
|
413
429
|
break;
|
414
430
|
}
|
415
|
-
|
416
|
-
this.streamControllers[
|
417
|
-
|
431
|
+
|
432
|
+
this.streamControllers[streamId].isClosed = true;
|
433
|
+
this.streamControllers[streamId].controller.close();
|
434
|
+
|
435
|
+
this._deleteStreamController(streamId);
|
436
|
+
|
418
437
|
break;
|
419
|
-
|
420
|
-
|
421
|
-
this.streamControllers[
|
422
|
-
|
438
|
+
|
439
|
+
case StreamKind.ERROR:
|
440
|
+
(0, _util.assert)(this.streamControllers[streamId], "error should have stream controller");
|
441
|
+
this.streamControllers[streamId].controller.error(wrapReason(data.reason));
|
442
|
+
|
443
|
+
this._deleteStreamController(streamId);
|
444
|
+
|
423
445
|
break;
|
424
|
-
|
425
|
-
|
426
|
-
|
446
|
+
|
447
|
+
case StreamKind.CANCEL_COMPLETE:
|
448
|
+
if (data.success) {
|
449
|
+
this.streamControllers[streamId].cancelCall.resolve();
|
450
|
+
} else {
|
451
|
+
this.streamControllers[streamId].cancelCall.reject(wrapReason(data.reason));
|
452
|
+
}
|
453
|
+
|
454
|
+
this._deleteStreamController(streamId);
|
455
|
+
|
427
456
|
break;
|
428
|
-
|
429
|
-
|
457
|
+
|
458
|
+
case StreamKind.CANCEL:
|
459
|
+
if (!this.streamSinks[streamId]) {
|
430
460
|
break;
|
431
461
|
}
|
432
|
-
|
433
|
-
|
434
|
-
|
462
|
+
|
463
|
+
const {
|
464
|
+
onCancel
|
465
|
+
} = this.streamSinks[data.streamId];
|
466
|
+
new Promise(function (resolve) {
|
467
|
+
resolve(onCancel && onCancel(wrapReason(data.reason)));
|
468
|
+
}).then(function () {
|
469
|
+
comObj.postMessage({
|
470
|
+
sourceName,
|
471
|
+
targetName,
|
472
|
+
stream: StreamKind.CANCEL_COMPLETE,
|
473
|
+
streamId,
|
435
474
|
success: true
|
436
475
|
});
|
437
476
|
}, function (reason) {
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
477
|
+
comObj.postMessage({
|
478
|
+
sourceName,
|
479
|
+
targetName,
|
480
|
+
stream: StreamKind.CANCEL_COMPLETE,
|
481
|
+
streamId,
|
482
|
+
reason: wrapReason(reason)
|
442
483
|
});
|
443
484
|
});
|
444
|
-
this.streamSinks[
|
445
|
-
this.streamSinks[
|
446
|
-
delete this.streamSinks[
|
485
|
+
this.streamSinks[streamId].sinkCapability.reject(wrapReason(data.reason));
|
486
|
+
this.streamSinks[streamId].isCancelled = true;
|
487
|
+
delete this.streamSinks[streamId];
|
447
488
|
break;
|
489
|
+
|
448
490
|
default:
|
449
|
-
throw new Error(
|
491
|
+
throw new Error("Unexpected stream case");
|
450
492
|
}
|
451
|
-
}
|
452
|
-
|
493
|
+
}
|
494
|
+
|
495
|
+
async _deleteStreamController(streamId) {
|
496
|
+
await Promise.allSettled([this.streamControllers[streamId].startCall, this.streamControllers[streamId].pullCall, this.streamControllers[streamId].cancelCall].map(function (capability) {
|
497
|
+
return capability && capability.promise;
|
498
|
+
}));
|
499
|
+
delete this.streamControllers[streamId];
|
500
|
+
}
|
501
|
+
|
502
|
+
_postMessage(message, transfers) {
|
453
503
|
if (transfers && this.postMessageTransfers) {
|
454
504
|
this.comObj.postMessage(message, transfers);
|
455
505
|
} else {
|
456
506
|
this.comObj.postMessage(message);
|
457
507
|
}
|
458
|
-
},
|
459
|
-
destroy: function destroy() {
|
460
|
-
this.comObj.removeEventListener('message', this._onComObjOnMessage);
|
461
508
|
}
|
462
|
-
|
509
|
+
|
510
|
+
destroy() {
|
511
|
+
this.comObj.removeEventListener("message", this._onComObjOnMessage);
|
512
|
+
}
|
513
|
+
|
514
|
+
}
|
515
|
+
|
463
516
|
exports.MessageHandler = MessageHandler;
|