pdfjs-dist 2.1.266 → 2.5.207
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 +8382 -18492
- 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 +20417 -29816
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25688 -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 +58239 -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 +403 -0
- package/es5/web/pdf_viewer.js +7742 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1475 -4897
- 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 +750 -899
- package/lib/core/arithmetic_decoder.js +81 -97
- package/lib/core/bidi.js +54 -46
- package/lib/core/ccitt.js +88 -81
- package/lib/core/ccitt_stream.js +15 -14
- package/lib/core/cff_parser.js +235 -183
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +447 -542
- package/lib/core/cmap.js +222 -264
- package/lib/core/colorspace.js +699 -863
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +379 -437
- package/lib/core/document.js +573 -660
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +1103 -868
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +570 -491
- package/lib/core/function.js +291 -288
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +145 -149
- package/lib/core/image_utils.js +170 -0
- package/lib/core/jbig2.js +325 -316
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +21 -26
- package/lib/core/jpg.js +284 -232
- package/lib/core/jpx.js +161 -143
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2929 -2929
- package/lib/core/murmurhash3.js +90 -101
- package/lib/core/obj.js +1183 -1157
- package/lib/core/operator_list.js +99 -67
- package/lib/core/parser.js +972 -911
- package/lib/core/pattern.js +87 -70
- package/lib/core/pdf_manager.js +150 -315
- package/lib/core/primitives.js +83 -56
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +94 -74
- package/lib/core/type1_parser.js +87 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +193 -390
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +741 -972
- package/lib/display/api.js +1500 -1791
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +165 -165
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +515 -0
- package/lib/display/fetch_stream.js +183 -298
- package/lib/display/font_loader.js +273 -413
- package/lib/display/metadata.js +86 -98
- package/lib/display/network.js +266 -359
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +285 -458
- package/lib/display/pattern_helper.js +113 -65
- package/lib/display/svg.js +1166 -901
- package/lib/display/text_layer.js +156 -132
- package/lib/display/transport_stream.js +262 -278
- package/lib/display/webgl.js +70 -83
- package/lib/display/worker_options.js +3 -3
- package/lib/display/xml_parser.js +303 -392
- package/lib/examples/node/domstubs.js +40 -37
- package/lib/pdf.js +226 -59
- package/lib/pdf.worker.js +14 -6
- package/lib/shared/compatibility.js +3 -246
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +327 -332
- package/lib/shared/util.js +266 -416
- package/lib/test/unit/annotation_spec.js +1555 -701
- package/lib/test/unit/api_spec.js +802 -604
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +84 -69
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +74 -76
- package/lib/test/unit/colorspace_spec.js +166 -161
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +181 -181
- package/lib/test/unit/custom_spec.js +20 -22
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +16 -21
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +83 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +46 -30
- package/lib/test/unit/message_handler_spec.js +173 -159
- package/lib/test/unit/metadata_spec.js +69 -69
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +13 -61
- package/lib/test/unit/network_utils_spec.js +183 -119
- package/lib/test/unit/node_stream_spec.js +78 -92
- package/lib/test/unit/parser_spec.js +172 -114
- package/lib/test/unit/pdf_find_controller_spec.js +55 -86
- package/lib/test/unit/pdf_find_utils_spec.js +32 -32
- package/lib/test/unit/pdf_history_spec.js +32 -32
- package/lib/test/unit/primitives_spec.js +140 -125
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +131 -143
- package/lib/test/unit/testreporter.js +19 -19
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +297 -459
- package/lib/test/unit/unicode_spec.js +38 -38
- package/lib/test/unit/util_spec.js +121 -305
- package/lib/web/annotation_layer_builder.js +66 -103
- package/lib/web/app.js +1328 -1214
- package/lib/web/app_options.js +105 -107
- package/lib/web/base_viewer.js +824 -838
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +39 -55
- package/lib/web/firefox_print_service.js +37 -27
- package/lib/web/firefoxcom.js +212 -363
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +32 -30
- package/lib/web/interfaces.js +80 -254
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +113 -131
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +221 -306
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +491 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +140 -175
- package/lib/web/pdf_page_view.js +452 -523
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +90 -104
- package/lib/web/pdf_rendering_queue.js +84 -108
- package/lib/web/pdf_sidebar.js +276 -306
- package/lib/web/pdf_sidebar_resizer.js +92 -119
- package/lib/web/pdf_single_page_viewer.js +77 -126
- package/lib/web/pdf_thumbnail_view.js +276 -297
- package/lib/web/pdf_thumbnail_viewer.js +186 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +82 -286
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +282 -339
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +267 -420
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +35 -25
- package/web/pdf_viewer.js +3489 -4855
- 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 -494
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- package/lib/test/unit/dom_utils_spec.js +0 -89
@@ -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.
|
@@ -24,307 +24,249 @@
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
exports.MessageHandler =
|
28
|
-
|
29
|
-
var
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
/*#__PURE__*/
|
48
|
-
_regenerator.default.mark(function _callee(fn, args) {
|
49
|
-
var thisArg,
|
50
|
-
_args = arguments;
|
51
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
52
|
-
while (1) {
|
53
|
-
switch (_context.prev = _context.next) {
|
54
|
-
case 0:
|
55
|
-
thisArg = _args.length > 2 && _args[2] !== undefined ? _args[2] : null;
|
56
|
-
|
57
|
-
if (fn) {
|
58
|
-
_context.next = 3;
|
59
|
-
break;
|
60
|
-
}
|
61
|
-
|
62
|
-
return _context.abrupt("return");
|
63
|
-
|
64
|
-
case 3:
|
65
|
-
return _context.abrupt("return", fn.apply(thisArg, args));
|
66
|
-
|
67
|
-
case 4:
|
68
|
-
case "end":
|
69
|
-
return _context.stop();
|
70
|
-
}
|
71
|
-
}
|
72
|
-
}, _callee, this);
|
73
|
-
}));
|
74
|
-
return _resolveCall.apply(this, arguments);
|
75
|
-
}
|
27
|
+
exports.MessageHandler = void 0;
|
28
|
+
|
29
|
+
var _util = require("./util.js");
|
30
|
+
|
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
|
+
};
|
76
47
|
|
77
48
|
function wrapReason(reason) {
|
78
|
-
if (
|
49
|
+
if (typeof reason !== "object" || reason === null) {
|
79
50
|
return reason;
|
80
51
|
}
|
81
52
|
|
82
53
|
switch (reason.name) {
|
83
|
-
case
|
54
|
+
case "AbortException":
|
84
55
|
return new _util.AbortException(reason.message);
|
85
56
|
|
86
|
-
case
|
57
|
+
case "MissingPDFException":
|
87
58
|
return new _util.MissingPDFException(reason.message);
|
88
59
|
|
89
|
-
case
|
60
|
+
case "UnexpectedResponseException":
|
90
61
|
return new _util.UnexpectedResponseException(reason.message, reason.status);
|
91
62
|
|
92
|
-
|
63
|
+
case "UnknownErrorException":
|
93
64
|
return new _util.UnknownErrorException(reason.message, reason.details);
|
94
|
-
}
|
95
|
-
}
|
96
65
|
|
97
|
-
|
98
|
-
|
99
|
-
return reason;
|
66
|
+
default:
|
67
|
+
return new _util.UnknownErrorException(reason.message, reason.toString());
|
100
68
|
}
|
101
|
-
|
102
|
-
return new _util.UnknownErrorException(reason.message, reason.toString());
|
103
69
|
}
|
104
70
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
+
}
|
112
90
|
|
113
|
-
|
114
|
-
|
115
|
-
}
|
91
|
+
if (data.stream) {
|
92
|
+
this._processStreamMessage(data);
|
116
93
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
this.sourceName = sourceName;
|
121
|
-
this.targetName = targetName;
|
122
|
-
this.comObj = comObj;
|
123
|
-
this.callbackId = 1;
|
124
|
-
this.streamId = 1;
|
125
|
-
this.postMessageTransfers = true;
|
126
|
-
this.streamSinks = Object.create(null);
|
127
|
-
this.streamControllers = Object.create(null);
|
128
|
-
var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
|
129
|
-
var ah = this.actionHandler = Object.create(null);
|
130
|
-
|
131
|
-
this._onComObjOnMessage = function (event) {
|
132
|
-
var data = event.data;
|
133
|
-
|
134
|
-
if (data.targetName !== _this.sourceName) {
|
135
|
-
return;
|
136
|
-
}
|
94
|
+
return;
|
95
|
+
}
|
137
96
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
var callbackId = data.callbackId;
|
97
|
+
if (data.callback) {
|
98
|
+
const callbackId = data.callbackId;
|
99
|
+
const capability = this.callbackCapabilities[callbackId];
|
142
100
|
|
143
|
-
|
144
|
-
|
145
|
-
|
101
|
+
if (!capability) {
|
102
|
+
throw new Error(`Cannot resolve callback ${callbackId}`);
|
103
|
+
}
|
146
104
|
|
147
|
-
|
148
|
-
|
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));
|
149
111
|
} else {
|
150
|
-
callback
|
112
|
+
throw new Error("Unexpected callback case");
|
151
113
|
}
|
152
|
-
|
153
|
-
|
114
|
+
|
115
|
+
return;
|
116
|
+
}
|
117
|
+
|
118
|
+
const action = this.actionHandler[data.action];
|
119
|
+
|
120
|
+
if (!action) {
|
121
|
+
throw new Error(`Unknown action from worker: ${data.action}`);
|
154
122
|
}
|
155
|
-
} else if (data.action in ah) {
|
156
|
-
var action = ah[data.action];
|
157
123
|
|
158
124
|
if (data.callbackId) {
|
159
|
-
|
160
|
-
|
161
|
-
Promise
|
162
|
-
|
125
|
+
const cbSourceName = this.sourceName;
|
126
|
+
const cbTargetName = data.sourceName;
|
127
|
+
new Promise(function (resolve) {
|
128
|
+
resolve(action(data.data));
|
163
129
|
}).then(function (result) {
|
164
130
|
comObj.postMessage({
|
165
|
-
sourceName:
|
166
|
-
targetName:
|
167
|
-
|
131
|
+
sourceName: cbSourceName,
|
132
|
+
targetName: cbTargetName,
|
133
|
+
callback: CallbackKind.DATA,
|
168
134
|
callbackId: data.callbackId,
|
169
135
|
data: result
|
170
136
|
});
|
171
137
|
}, function (reason) {
|
172
138
|
comObj.postMessage({
|
173
|
-
sourceName:
|
174
|
-
targetName:
|
175
|
-
|
139
|
+
sourceName: cbSourceName,
|
140
|
+
targetName: cbTargetName,
|
141
|
+
callback: CallbackKind.ERROR,
|
176
142
|
callbackId: data.callbackId,
|
177
|
-
|
143
|
+
reason: wrapReason(reason)
|
178
144
|
});
|
179
145
|
});
|
180
|
-
|
181
|
-
_this._createStreamSink(data);
|
182
|
-
} else {
|
183
|
-
action[0].call(action[1], data.data);
|
146
|
+
return;
|
184
147
|
}
|
185
|
-
} else {
|
186
|
-
throw new Error("Unknown action from worker: ".concat(data.action));
|
187
|
-
}
|
188
|
-
};
|
189
148
|
|
190
|
-
|
191
|
-
|
149
|
+
if (data.streamId) {
|
150
|
+
this._createStreamSink(data);
|
151
|
+
|
152
|
+
return;
|
153
|
+
}
|
154
|
+
|
155
|
+
action(data.data);
|
156
|
+
};
|
192
157
|
|
193
|
-
|
194
|
-
|
195
|
-
|
158
|
+
comObj.addEventListener("message", this._onComObjOnMessage);
|
159
|
+
}
|
160
|
+
|
161
|
+
on(actionName, handler) {
|
162
|
+
const ah = this.actionHandler;
|
196
163
|
|
197
164
|
if (ah[actionName]) {
|
198
|
-
throw new Error(
|
165
|
+
throw new Error(`There is already an actionName called "${actionName}"`);
|
199
166
|
}
|
200
167
|
|
201
|
-
ah[actionName] =
|
202
|
-
}
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
targetName: this.targetName,
|
207
|
-
action: actionName,
|
208
|
-
data: data
|
209
|
-
};
|
210
|
-
this.postMessage(message, transfers);
|
211
|
-
},
|
212
|
-
sendWithPromise: function sendWithPromise(actionName, data, transfers) {
|
213
|
-
var callbackId = this.callbackId++;
|
214
|
-
var message = {
|
168
|
+
ah[actionName] = handler;
|
169
|
+
}
|
170
|
+
|
171
|
+
send(actionName, data, transfers) {
|
172
|
+
this._postMessage({
|
215
173
|
sourceName: this.sourceName,
|
216
174
|
targetName: this.targetName,
|
217
175
|
action: actionName,
|
218
|
-
data
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
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;
|
223
184
|
|
224
185
|
try {
|
225
|
-
this.
|
226
|
-
|
227
|
-
|
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);
|
228
195
|
}
|
229
196
|
|
230
197
|
return capability.promise;
|
231
|
-
}
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
return new
|
239
|
-
start:
|
240
|
-
|
241
|
-
|
242
|
-
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,
|
243
210
|
startCall: startCapability,
|
211
|
+
pullCall: null,
|
212
|
+
cancelCall: null,
|
244
213
|
isClosed: false
|
245
214
|
};
|
246
215
|
|
247
|
-
|
248
|
-
sourceName
|
249
|
-
targetName
|
216
|
+
this._postMessage({
|
217
|
+
sourceName,
|
218
|
+
targetName,
|
250
219
|
action: actionName,
|
251
|
-
streamId
|
252
|
-
data
|
220
|
+
streamId,
|
221
|
+
data,
|
253
222
|
desiredSize: controller.desiredSize
|
254
|
-
});
|
223
|
+
}, transfers);
|
255
224
|
|
256
225
|
return startCapability.promise;
|
257
226
|
},
|
258
|
-
pull:
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
streamId: 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,
|
267
235
|
desiredSize: controller.desiredSize
|
268
236
|
});
|
269
|
-
|
270
237
|
return pullCapability.promise;
|
271
238
|
},
|
272
|
-
cancel:
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
sourceName
|
279
|
-
targetName
|
280
|
-
stream:
|
281
|
-
|
282
|
-
|
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)
|
283
250
|
});
|
284
|
-
|
285
251
|
return cancelCapability.promise;
|
286
252
|
}
|
287
253
|
}, queueingStrategy);
|
288
|
-
}
|
289
|
-
_createStreamSink: function _createStreamSink(data) {
|
290
|
-
var _this3 = this;
|
291
|
-
|
292
|
-
var self = this;
|
293
|
-
var action = this.actionHandler[data.action];
|
294
|
-
var streamId = data.streamId;
|
295
|
-
var desiredSize = data.desiredSize;
|
296
|
-
var sourceName = this.sourceName;
|
297
|
-
var targetName = data.sourceName;
|
298
|
-
var capability = (0, _util.createPromiseCapability)();
|
299
|
-
|
300
|
-
var sendStreamRequest = function sendStreamRequest(_ref) {
|
301
|
-
var stream = _ref.stream,
|
302
|
-
chunk = _ref.chunk,
|
303
|
-
transfers = _ref.transfers,
|
304
|
-
success = _ref.success,
|
305
|
-
reason = _ref.reason;
|
306
|
-
|
307
|
-
_this3.postMessage({
|
308
|
-
sourceName: sourceName,
|
309
|
-
targetName: targetName,
|
310
|
-
stream: stream,
|
311
|
-
streamId: streamId,
|
312
|
-
chunk: chunk,
|
313
|
-
success: success,
|
314
|
-
reason: reason
|
315
|
-
}, transfers);
|
316
|
-
};
|
317
|
-
|
318
|
-
var streamSink = {
|
319
|
-
enqueue: function enqueue(chunk) {
|
320
|
-
var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
321
|
-
var transfers = arguments.length > 2 ? arguments[2] : undefined;
|
254
|
+
}
|
322
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) {
|
323
265
|
if (this.isCancelled) {
|
324
266
|
return;
|
325
267
|
}
|
326
268
|
|
327
|
-
|
269
|
+
const lastDesiredSize = this.desiredSize;
|
328
270
|
this.desiredSize -= size;
|
329
271
|
|
330
272
|
if (lastDesiredSize > 0 && this.desiredSize <= 0) {
|
@@ -332,190 +274,243 @@ MessageHandler.prototype = {
|
|
332
274
|
this.ready = this.sinkCapability.promise;
|
333
275
|
}
|
334
276
|
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
277
|
+
self._postMessage({
|
278
|
+
sourceName,
|
279
|
+
targetName,
|
280
|
+
stream: StreamKind.ENQUEUE,
|
281
|
+
streamId,
|
282
|
+
chunk
|
283
|
+
}, transfers);
|
340
284
|
},
|
341
|
-
|
285
|
+
|
286
|
+
close() {
|
342
287
|
if (this.isCancelled) {
|
343
288
|
return;
|
344
289
|
}
|
345
290
|
|
346
291
|
this.isCancelled = true;
|
347
|
-
|
348
|
-
|
292
|
+
comObj.postMessage({
|
293
|
+
sourceName,
|
294
|
+
targetName,
|
295
|
+
stream: StreamKind.CLOSE,
|
296
|
+
streamId
|
349
297
|
});
|
350
298
|
delete self.streamSinks[streamId];
|
351
299
|
},
|
352
|
-
|
300
|
+
|
301
|
+
error(reason) {
|
302
|
+
(0, _util.assert)(reason instanceof Error, "error must have a valid reason");
|
303
|
+
|
353
304
|
if (this.isCancelled) {
|
354
305
|
return;
|
355
306
|
}
|
356
307
|
|
357
308
|
this.isCancelled = true;
|
358
|
-
|
359
|
-
|
360
|
-
|
309
|
+
comObj.postMessage({
|
310
|
+
sourceName,
|
311
|
+
targetName,
|
312
|
+
stream: StreamKind.ERROR,
|
313
|
+
streamId,
|
314
|
+
reason: wrapReason(reason)
|
361
315
|
});
|
362
316
|
},
|
363
|
-
|
317
|
+
|
318
|
+
sinkCapability: (0, _util.createPromiseCapability)(),
|
364
319
|
onPull: null,
|
365
320
|
onCancel: null,
|
366
321
|
isCancelled: false,
|
367
|
-
desiredSize: desiredSize,
|
322
|
+
desiredSize: data.desiredSize,
|
368
323
|
ready: null
|
369
324
|
};
|
370
325
|
streamSink.sinkCapability.resolve();
|
371
326
|
streamSink.ready = streamSink.sinkCapability.promise;
|
372
327
|
this.streamSinks[streamId] = streamSink;
|
373
|
-
|
374
|
-
|
375
|
-
|
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,
|
376
336
|
success: true
|
377
337
|
});
|
378
338
|
}, function (reason) {
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
339
|
+
comObj.postMessage({
|
340
|
+
sourceName,
|
341
|
+
targetName,
|
342
|
+
stream: StreamKind.START_COMPLETE,
|
343
|
+
streamId,
|
344
|
+
reason: wrapReason(reason)
|
383
345
|
});
|
384
346
|
});
|
385
|
-
}
|
386
|
-
_processStreamMessage: function _processStreamMessage(data) {
|
387
|
-
var _this4 = this;
|
388
|
-
|
389
|
-
var sourceName = this.sourceName;
|
390
|
-
var targetName = data.sourceName;
|
391
|
-
var streamId = data.streamId;
|
392
|
-
|
393
|
-
var sendStreamResponse = function sendStreamResponse(_ref2) {
|
394
|
-
var stream = _ref2.stream,
|
395
|
-
success = _ref2.success,
|
396
|
-
reason = _ref2.reason;
|
397
|
-
|
398
|
-
_this4.comObj.postMessage({
|
399
|
-
sourceName: sourceName,
|
400
|
-
targetName: targetName,
|
401
|
-
stream: stream,
|
402
|
-
success: success,
|
403
|
-
streamId: streamId,
|
404
|
-
reason: reason
|
405
|
-
});
|
406
|
-
};
|
347
|
+
}
|
407
348
|
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
});
|
414
|
-
};
|
349
|
+
_processStreamMessage(data) {
|
350
|
+
const streamId = data.streamId;
|
351
|
+
const sourceName = this.sourceName;
|
352
|
+
const targetName = data.sourceName;
|
353
|
+
const comObj = this.comObj;
|
415
354
|
|
416
355
|
switch (data.stream) {
|
417
|
-
case
|
418
|
-
|
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
|
+
|
419
363
|
break;
|
420
364
|
|
421
|
-
case
|
422
|
-
|
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
|
+
|
423
372
|
break;
|
424
373
|
|
425
|
-
case
|
426
|
-
if (!this.streamSinks[
|
427
|
-
|
428
|
-
|
374
|
+
case StreamKind.PULL:
|
375
|
+
if (!this.streamSinks[streamId]) {
|
376
|
+
comObj.postMessage({
|
377
|
+
sourceName,
|
378
|
+
targetName,
|
379
|
+
stream: StreamKind.PULL_COMPLETE,
|
380
|
+
streamId,
|
429
381
|
success: true
|
430
382
|
});
|
431
383
|
break;
|
432
384
|
}
|
433
385
|
|
434
|
-
if (this.streamSinks[
|
435
|
-
this.streamSinks[
|
386
|
+
if (this.streamSinks[streamId].desiredSize <= 0 && data.desiredSize > 0) {
|
387
|
+
this.streamSinks[streamId].sinkCapability.resolve();
|
436
388
|
}
|
437
389
|
|
438
|
-
this.streamSinks[
|
439
|
-
|
440
|
-
|
441
|
-
|
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,
|
442
402
|
success: true
|
443
403
|
});
|
444
404
|
}, function (reason) {
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
405
|
+
comObj.postMessage({
|
406
|
+
sourceName,
|
407
|
+
targetName,
|
408
|
+
stream: StreamKind.PULL_COMPLETE,
|
409
|
+
streamId,
|
410
|
+
reason: wrapReason(reason)
|
449
411
|
});
|
450
412
|
});
|
451
413
|
break;
|
452
414
|
|
453
|
-
case
|
454
|
-
(0, _util.assert)(this.streamControllers[
|
415
|
+
case StreamKind.ENQUEUE:
|
416
|
+
(0, _util.assert)(this.streamControllers[streamId], "enqueue should have stream controller");
|
455
417
|
|
456
|
-
if (
|
457
|
-
|
418
|
+
if (this.streamControllers[streamId].isClosed) {
|
419
|
+
break;
|
458
420
|
}
|
459
421
|
|
422
|
+
this.streamControllers[streamId].controller.enqueue(data.chunk);
|
460
423
|
break;
|
461
424
|
|
462
|
-
case
|
463
|
-
(0, _util.assert)(this.streamControllers[
|
425
|
+
case StreamKind.CLOSE:
|
426
|
+
(0, _util.assert)(this.streamControllers[streamId], "close should have stream controller");
|
464
427
|
|
465
|
-
if (this.streamControllers[
|
428
|
+
if (this.streamControllers[streamId].isClosed) {
|
466
429
|
break;
|
467
430
|
}
|
468
431
|
|
469
|
-
this.streamControllers[
|
470
|
-
this.streamControllers[
|
471
|
-
|
432
|
+
this.streamControllers[streamId].isClosed = true;
|
433
|
+
this.streamControllers[streamId].controller.close();
|
434
|
+
|
435
|
+
this._deleteStreamController(streamId);
|
436
|
+
|
472
437
|
break;
|
473
438
|
|
474
|
-
case
|
475
|
-
(0, _util.assert)(this.streamControllers[
|
476
|
-
this.streamControllers[
|
477
|
-
|
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
|
+
|
478
445
|
break;
|
479
446
|
|
480
|
-
case
|
481
|
-
|
482
|
-
|
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
|
+
|
483
456
|
break;
|
484
457
|
|
485
|
-
case
|
486
|
-
if (!this.streamSinks[
|
458
|
+
case StreamKind.CANCEL:
|
459
|
+
if (!this.streamSinks[streamId]) {
|
487
460
|
break;
|
488
461
|
}
|
489
462
|
|
490
|
-
|
491
|
-
|
492
|
-
|
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,
|
493
474
|
success: true
|
494
475
|
});
|
495
476
|
}, function (reason) {
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
477
|
+
comObj.postMessage({
|
478
|
+
sourceName,
|
479
|
+
targetName,
|
480
|
+
stream: StreamKind.CANCEL_COMPLETE,
|
481
|
+
streamId,
|
482
|
+
reason: wrapReason(reason)
|
500
483
|
});
|
501
484
|
});
|
502
|
-
this.streamSinks[
|
503
|
-
this.streamSinks[
|
504
|
-
delete this.streamSinks[
|
485
|
+
this.streamSinks[streamId].sinkCapability.reject(wrapReason(data.reason));
|
486
|
+
this.streamSinks[streamId].isCancelled = true;
|
487
|
+
delete this.streamSinks[streamId];
|
505
488
|
break;
|
506
489
|
|
507
490
|
default:
|
508
|
-
throw new Error(
|
491
|
+
throw new Error("Unexpected stream case");
|
509
492
|
}
|
510
|
-
}
|
511
|
-
|
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) {
|
512
503
|
if (transfers && this.postMessageTransfers) {
|
513
504
|
this.comObj.postMessage(message, transfers);
|
514
505
|
} else {
|
515
506
|
this.comObj.postMessage(message);
|
516
507
|
}
|
517
|
-
},
|
518
|
-
destroy: function destroy() {
|
519
|
-
this.comObj.removeEventListener('message', this._onComObjOnMessage);
|
520
508
|
}
|
521
|
-
|
509
|
+
|
510
|
+
destroy() {
|
511
|
+
this.comObj.removeEventListener("message", this._onComObjOnMessage);
|
512
|
+
}
|
513
|
+
|
514
|
+
}
|
515
|
+
|
516
|
+
exports.MessageHandler = MessageHandler;
|