request-iframe 0.1.1 → 0.2.1
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.
- package/QUICKSTART.CN.md +4 -2
- package/QUICKSTART.md +4 -2
- package/README.CN.md +129 -33
- package/README.md +116 -15
- package/cdn/request-iframe-react.umd.js +3354 -0
- package/cdn/request-iframe-react.umd.js.map +1 -0
- package/cdn/request-iframe-react.umd.min.js +2 -0
- package/cdn/request-iframe-react.umd.min.js.map +1 -0
- package/cdn/request-iframe.umd.js +19761 -0
- package/cdn/request-iframe.umd.js.map +1 -0
- package/cdn/request-iframe.umd.min.js +4 -0
- package/cdn/request-iframe.umd.min.js.map +1 -0
- package/esm/api/client.js +29 -21
- package/esm/api/endpoint.js +229 -0
- package/esm/api/server.js +16 -8
- package/esm/constants/debug.js +17 -0
- package/esm/constants/index.js +84 -67
- package/esm/constants/log.js +11 -0
- package/esm/constants/messages.js +3 -0
- package/esm/constants/warn-once.js +15 -0
- package/esm/endpoint/facade.js +390 -0
- package/esm/endpoint/heartbeat/heartbeat.js +60 -0
- package/esm/endpoint/heartbeat/ping.js +20 -0
- package/esm/endpoint/index.js +13 -0
- package/esm/endpoint/infra/hub.js +316 -0
- package/esm/endpoint/infra/inbox.js +232 -0
- package/esm/endpoint/infra/outbox.js +408 -0
- package/esm/endpoint/stream/dispatcher.js +58 -0
- package/esm/endpoint/stream/errors.js +27 -0
- package/esm/endpoint/stream/factory.js +76 -0
- package/esm/endpoint/stream/file-auto-resolve.js +34 -0
- package/esm/endpoint/stream/file-writable.js +105 -0
- package/esm/endpoint/stream/handler.js +26 -0
- package/esm/{core → impl}/client.js +240 -317
- package/esm/{core → impl}/response.js +113 -155
- package/esm/impl/server.js +568 -0
- package/esm/index.js +13 -6
- package/esm/message/ack.js +27 -0
- package/esm/message/channel-cache.js +108 -0
- package/esm/message/channel.js +90 -4
- package/esm/message/dispatcher.js +115 -75
- package/esm/stream/error.js +22 -0
- package/esm/stream/index.js +3 -1
- package/esm/stream/readable-stream.js +45 -9
- package/esm/stream/stream-core.js +7 -2
- package/esm/stream/writable-stream.js +97 -26
- package/esm/utils/blob.js +16 -0
- package/esm/utils/cache.js +25 -76
- package/esm/utils/content-type.js +81 -0
- package/esm/utils/debug.js +156 -179
- package/esm/utils/hooks.js +130 -0
- package/esm/utils/id.js +14 -0
- package/esm/utils/iframe.js +20 -0
- package/esm/utils/index.js +11 -163
- package/esm/utils/is.js +3 -0
- package/esm/utils/logger.js +55 -0
- package/esm/utils/promise.js +3 -0
- package/esm/utils/window.js +31 -0
- package/library/api/client.d.ts.map +1 -1
- package/library/api/client.js +30 -22
- package/library/api/endpoint.d.ts +23 -0
- package/library/api/endpoint.d.ts.map +1 -0
- package/library/api/endpoint.js +235 -0
- package/library/api/server.d.ts +4 -1
- package/library/api/server.d.ts.map +1 -1
- package/library/api/server.js +16 -8
- package/library/constants/debug.d.ts +18 -0
- package/library/constants/debug.d.ts.map +1 -0
- package/library/constants/debug.js +23 -0
- package/library/constants/index.d.ts +22 -2
- package/library/constants/index.d.ts.map +1 -1
- package/library/constants/index.js +110 -67
- package/library/constants/log.d.ts +12 -0
- package/library/constants/log.d.ts.map +1 -0
- package/library/constants/log.js +17 -0
- package/library/constants/messages.d.ts +3 -0
- package/library/constants/messages.d.ts.map +1 -1
- package/library/constants/messages.js +3 -0
- package/library/constants/warn-once.d.ts +12 -0
- package/library/constants/warn-once.d.ts.map +1 -0
- package/library/constants/warn-once.js +22 -0
- package/library/endpoint/facade.d.ts +238 -0
- package/library/endpoint/facade.d.ts.map +1 -0
- package/library/endpoint/facade.js +398 -0
- package/library/endpoint/heartbeat/heartbeat.d.ts +34 -0
- package/library/endpoint/heartbeat/heartbeat.d.ts.map +1 -0
- package/library/endpoint/heartbeat/heartbeat.js +67 -0
- package/library/endpoint/heartbeat/ping.d.ts +18 -0
- package/library/endpoint/heartbeat/ping.d.ts.map +1 -0
- package/library/endpoint/heartbeat/ping.js +26 -0
- package/library/endpoint/index.d.ts +16 -0
- package/library/endpoint/index.d.ts.map +1 -0
- package/library/endpoint/index.js +114 -0
- package/library/endpoint/infra/hub.d.ts +170 -0
- package/library/endpoint/infra/hub.d.ts.map +1 -0
- package/library/endpoint/infra/hub.js +323 -0
- package/library/endpoint/infra/inbox.d.ts +73 -0
- package/library/endpoint/infra/inbox.d.ts.map +1 -0
- package/library/endpoint/infra/inbox.js +239 -0
- package/library/endpoint/infra/outbox.d.ts +149 -0
- package/library/endpoint/infra/outbox.d.ts.map +1 -0
- package/library/endpoint/infra/outbox.js +415 -0
- package/library/endpoint/stream/dispatcher.d.ts +33 -0
- package/library/endpoint/stream/dispatcher.d.ts.map +1 -0
- package/library/endpoint/stream/dispatcher.js +66 -0
- package/library/endpoint/stream/errors.d.ts +20 -0
- package/library/endpoint/stream/errors.d.ts.map +1 -0
- package/library/endpoint/stream/errors.js +32 -0
- package/library/endpoint/stream/factory.d.ts +44 -0
- package/library/endpoint/stream/factory.d.ts.map +1 -0
- package/library/endpoint/stream/factory.js +82 -0
- package/library/endpoint/stream/file-auto-resolve.d.ts +26 -0
- package/library/endpoint/stream/file-auto-resolve.d.ts.map +1 -0
- package/library/endpoint/stream/file-auto-resolve.js +41 -0
- package/library/endpoint/stream/file-writable.d.ts +33 -0
- package/library/endpoint/stream/file-writable.d.ts.map +1 -0
- package/library/endpoint/stream/file-writable.js +115 -0
- package/library/endpoint/stream/handler.d.ts +20 -0
- package/library/endpoint/stream/handler.d.ts.map +1 -0
- package/library/endpoint/stream/handler.js +32 -0
- package/library/{core → impl}/client.d.ts +16 -13
- package/library/impl/client.d.ts.map +1 -0
- package/library/{core → impl}/client.js +251 -330
- package/library/{core → impl}/request.d.ts.map +1 -1
- package/library/{core → impl}/response.d.ts +5 -10
- package/library/impl/response.d.ts.map +1 -0
- package/library/{core → impl}/response.js +113 -155
- package/library/{core → impl}/server.d.ts +22 -55
- package/library/impl/server.d.ts.map +1 -0
- package/library/impl/server.js +575 -0
- package/library/index.d.ts +13 -6
- package/library/index.d.ts.map +1 -1
- package/library/index.js +16 -16
- package/library/message/ack.d.ts +15 -0
- package/library/message/ack.d.ts.map +1 -0
- package/library/message/ack.js +33 -0
- package/library/message/channel-cache.d.ts +26 -0
- package/library/message/channel-cache.d.ts.map +1 -0
- package/library/message/channel-cache.js +115 -0
- package/library/message/channel.d.ts +53 -6
- package/library/message/channel.d.ts.map +1 -1
- package/library/message/channel.js +94 -8
- package/library/message/dispatcher.d.ts +7 -0
- package/library/message/dispatcher.d.ts.map +1 -1
- package/library/message/dispatcher.js +116 -76
- package/library/stream/error.d.ts +24 -0
- package/library/stream/error.d.ts.map +1 -0
- package/library/stream/error.js +29 -0
- package/library/stream/index.d.ts +4 -1
- package/library/stream/index.d.ts.map +1 -1
- package/library/stream/index.js +7 -4
- package/library/stream/readable-stream.d.ts.map +1 -1
- package/library/stream/readable-stream.js +46 -10
- package/library/stream/stream-core.d.ts.map +1 -1
- package/library/stream/stream-core.js +6 -1
- package/library/stream/writable-stream.d.ts.map +1 -1
- package/library/stream/writable-stream.js +99 -28
- package/library/types/index.d.ts +15 -19
- package/library/types/index.d.ts.map +1 -1
- package/library/utils/blob.d.ts +3 -0
- package/library/utils/blob.d.ts.map +1 -0
- package/library/utils/blob.js +22 -0
- package/library/utils/cache.d.ts +10 -20
- package/library/utils/cache.d.ts.map +1 -1
- package/library/utils/cache.js +25 -79
- package/library/utils/content-type.d.ts +13 -0
- package/library/utils/content-type.d.ts.map +1 -0
- package/library/utils/content-type.js +87 -0
- package/library/utils/debug.d.ts.map +1 -1
- package/library/utils/debug.js +155 -177
- package/library/utils/hooks.d.ts +30 -0
- package/library/utils/hooks.d.ts.map +1 -0
- package/library/utils/hooks.js +139 -0
- package/library/utils/id.d.ts +9 -0
- package/library/utils/id.d.ts.map +1 -0
- package/library/utils/id.js +21 -0
- package/library/utils/iframe.d.ts +5 -0
- package/library/utils/iframe.d.ts.map +1 -0
- package/library/utils/iframe.js +25 -0
- package/library/utils/index.d.ts +7 -34
- package/library/utils/index.d.ts.map +1 -1
- package/library/utils/index.js +58 -194
- package/library/utils/is.d.ts +2 -0
- package/library/utils/is.d.ts.map +1 -0
- package/library/utils/is.js +9 -0
- package/library/utils/logger.d.ts +13 -0
- package/library/utils/logger.d.ts.map +1 -0
- package/library/utils/logger.js +63 -0
- package/library/utils/promise.d.ts +2 -0
- package/library/utils/promise.d.ts.map +1 -0
- package/library/utils/promise.js +9 -0
- package/library/utils/window.d.ts +2 -0
- package/library/utils/window.d.ts.map +1 -0
- package/library/utils/window.js +38 -0
- package/package.json +49 -2
- package/react/package.json +2 -1
- package/esm/core/client-server.js +0 -294
- package/esm/core/server.js +0 -776
- package/library/core/client-server.d.ts +0 -97
- package/library/core/client-server.d.ts.map +0 -1
- package/library/core/client-server.js +0 -301
- package/library/core/client.d.ts.map +0 -1
- package/library/core/response.d.ts.map +0 -1
- package/library/core/server.d.ts.map +0 -1
- package/library/core/server.js +0 -781
- /package/esm/{core → impl}/request.js +0 -0
- /package/library/{core → impl}/request.d.ts +0 -0
- /package/library/{core → impl}/request.js +0 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
6
|
+
import "core-js/modules/es.array.filter.js";
|
|
7
|
+
import "core-js/modules/es.object.get-own-property-descriptors.js";
|
|
8
|
+
import "core-js/modules/es.promise.js";
|
|
9
|
+
import "core-js/modules/es.promise.finally.js";
|
|
10
|
+
import "core-js/modules/web.dom-collections.for-each.js";
|
|
11
|
+
import { isIframeWritableStream } from '../../stream';
|
|
12
|
+
import { createIframeFileWritableStreamFromContent } from '../stream/file-writable';
|
|
13
|
+
import { SyncHook } from '../../utils/hooks';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Outbox hooks for send pipelines.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Stream send pipeline params.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* File send pipeline params.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Universal send pipeline params.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
function safeIsFile(data) {
|
|
32
|
+
try {
|
|
33
|
+
return typeof File !== 'undefined' && data instanceof File;
|
|
34
|
+
} catch (_unused) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function safeIsBlob(data) {
|
|
39
|
+
try {
|
|
40
|
+
return typeof Blob !== 'undefined' && data instanceof Blob;
|
|
41
|
+
} catch (_unused2) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* RequestIframeEndpointOutbox
|
|
48
|
+
*
|
|
49
|
+
* A lightweight "built-in sender" bound to a fixed peer (targetWindow/targetOrigin).
|
|
50
|
+
* Used by request/response-side objects to send messages without repeatedly passing
|
|
51
|
+
* targetWindow/targetOrigin.
|
|
52
|
+
*/
|
|
53
|
+
export class RequestIframeEndpointOutbox {
|
|
54
|
+
constructor(dispatcher, targetWindow, targetOrigin, defaultTargetId) {
|
|
55
|
+
_defineProperty(this, "hooks", {
|
|
56
|
+
beforeSendRaw: new SyncHook(),
|
|
57
|
+
afterSendRaw: new SyncHook(),
|
|
58
|
+
sendRawError: new SyncHook(),
|
|
59
|
+
beforeSendMessage: new SyncHook(),
|
|
60
|
+
afterSendMessage: new SyncHook(),
|
|
61
|
+
sendMessageError: new SyncHook()
|
|
62
|
+
});
|
|
63
|
+
this.dispatcher = dispatcher;
|
|
64
|
+
this.targetWindow = targetWindow;
|
|
65
|
+
this.targetOrigin = targetOrigin;
|
|
66
|
+
this.defaultTargetId = defaultTargetId;
|
|
67
|
+
}
|
|
68
|
+
setDefaultTargetId(targetId) {
|
|
69
|
+
this.defaultTargetId = targetId;
|
|
70
|
+
}
|
|
71
|
+
get secretKey() {
|
|
72
|
+
return this.dispatcher.secretKey;
|
|
73
|
+
}
|
|
74
|
+
get channel() {
|
|
75
|
+
return this.dispatcher.getChannel();
|
|
76
|
+
}
|
|
77
|
+
runWithHooks(hooks, fn) {
|
|
78
|
+
return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
79
|
+
var result, _t;
|
|
80
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
81
|
+
while (1) switch (_context.prev = _context.next) {
|
|
82
|
+
case 0:
|
|
83
|
+
_context.prev = 0;
|
|
84
|
+
if (!hooks.before) {
|
|
85
|
+
_context.next = 1;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
_context.next = 1;
|
|
89
|
+
return hooks.before();
|
|
90
|
+
case 1:
|
|
91
|
+
_context.next = 2;
|
|
92
|
+
return fn();
|
|
93
|
+
case 2:
|
|
94
|
+
result = _context.sent;
|
|
95
|
+
if (!hooks.end) {
|
|
96
|
+
_context.next = 3;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
_context.next = 3;
|
|
100
|
+
return hooks.end(result);
|
|
101
|
+
case 3:
|
|
102
|
+
return _context.abrupt("return", result);
|
|
103
|
+
case 4:
|
|
104
|
+
_context.prev = 4;
|
|
105
|
+
_t = _context["catch"](0);
|
|
106
|
+
if (!hooks.error) {
|
|
107
|
+
_context.next = 6;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
_context.next = 5;
|
|
111
|
+
return hooks.error(_t);
|
|
112
|
+
case 5:
|
|
113
|
+
return _context.abrupt("return", _context.sent);
|
|
114
|
+
case 6:
|
|
115
|
+
throw _t;
|
|
116
|
+
case 7:
|
|
117
|
+
_context.prev = 7;
|
|
118
|
+
if (!hooks.finally) {
|
|
119
|
+
_context.next = 8;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
_context.next = 8;
|
|
123
|
+
return hooks.finally();
|
|
124
|
+
case 8:
|
|
125
|
+
return _context.finish(7);
|
|
126
|
+
case 9:
|
|
127
|
+
case "end":
|
|
128
|
+
return _context.stop();
|
|
129
|
+
}
|
|
130
|
+
}, _callee, null, [[0, 4, 7, 9]]);
|
|
131
|
+
}))();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Create a stream bind context using this peer's fixed target info.
|
|
136
|
+
*
|
|
137
|
+
* This helps unify the duplicated `_bind({ targetWindow, targetOrigin, secretKey, channel, ... })` logic
|
|
138
|
+
* across client/server response implementations.
|
|
139
|
+
*/
|
|
140
|
+
createStreamBindContext(params) {
|
|
141
|
+
var _params$targetId;
|
|
142
|
+
return {
|
|
143
|
+
requestId: params.requestId,
|
|
144
|
+
targetWindow: this.targetWindow,
|
|
145
|
+
targetOrigin: this.targetOrigin,
|
|
146
|
+
secretKey: this.secretKey,
|
|
147
|
+
channel: this.channel,
|
|
148
|
+
registerStreamHandler: params.registerStreamHandler,
|
|
149
|
+
unregisterStreamHandler: params.unregisterStreamHandler,
|
|
150
|
+
heartbeat: params.heartbeat,
|
|
151
|
+
serverId: params.serverId,
|
|
152
|
+
clientId: params.clientId,
|
|
153
|
+
targetId: (_params$targetId = params.targetId) !== null && _params$targetId !== void 0 ? _params$targetId : this.defaultTargetId
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Bind and start a writable stream to this peer.
|
|
159
|
+
*
|
|
160
|
+
* Note:
|
|
161
|
+
* - Client-side request-body streams may need to delay `start()` until after REQUEST is sent.
|
|
162
|
+
* For that case, prefer `createStreamBindContext()` + manual `stream.start()`.
|
|
163
|
+
*/
|
|
164
|
+
sendWritableStream(stream, params) {
|
|
165
|
+
var _this = this;
|
|
166
|
+
return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
167
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
168
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
169
|
+
case 0:
|
|
170
|
+
stream._bind(_this.createStreamBindContext(params));
|
|
171
|
+
_context2.next = 1;
|
|
172
|
+
return stream.start();
|
|
173
|
+
case 1:
|
|
174
|
+
case "end":
|
|
175
|
+
return _context2.stop();
|
|
176
|
+
}
|
|
177
|
+
}, _callee2);
|
|
178
|
+
}))();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Universal send - dispatch by data type, then call hooks to implement differences.
|
|
183
|
+
*/
|
|
184
|
+
send(params) {
|
|
185
|
+
var _this2 = this;
|
|
186
|
+
return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
187
|
+
return _regeneratorRuntime.wrap(function (_context4) {
|
|
188
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
189
|
+
case 0:
|
|
190
|
+
return _context4.abrupt("return", _this2.runWithHooks(params, /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
191
|
+
var data;
|
|
192
|
+
return _regeneratorRuntime.wrap(function (_context3) {
|
|
193
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
194
|
+
case 0:
|
|
195
|
+
data = params.data;
|
|
196
|
+
if (!isIframeWritableStream(data)) {
|
|
197
|
+
_context3.next = 4;
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
if (!params.onStream) {
|
|
201
|
+
_context3.next = 2;
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
_context3.next = 1;
|
|
205
|
+
return params.onStream(data);
|
|
206
|
+
case 1:
|
|
207
|
+
return _context3.abrupt("return", _context3.sent);
|
|
208
|
+
case 2:
|
|
209
|
+
_context3.next = 3;
|
|
210
|
+
return params.onOther(data);
|
|
211
|
+
case 3:
|
|
212
|
+
return _context3.abrupt("return", _context3.sent);
|
|
213
|
+
case 4:
|
|
214
|
+
if (!(safeIsFile(data) || safeIsBlob(data))) {
|
|
215
|
+
_context3.next = 8;
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
if (!params.onFileOrBlob) {
|
|
219
|
+
_context3.next = 6;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
_context3.next = 5;
|
|
223
|
+
return params.onFileOrBlob(data);
|
|
224
|
+
case 5:
|
|
225
|
+
return _context3.abrupt("return", _context3.sent);
|
|
226
|
+
case 6:
|
|
227
|
+
_context3.next = 7;
|
|
228
|
+
return params.onOther(data);
|
|
229
|
+
case 7:
|
|
230
|
+
return _context3.abrupt("return", _context3.sent);
|
|
231
|
+
case 8:
|
|
232
|
+
_context3.next = 9;
|
|
233
|
+
return params.onOther(data);
|
|
234
|
+
case 9:
|
|
235
|
+
return _context3.abrupt("return", _context3.sent);
|
|
236
|
+
case 10:
|
|
237
|
+
case "end":
|
|
238
|
+
return _context3.stop();
|
|
239
|
+
}
|
|
240
|
+
}, _callee3);
|
|
241
|
+
}))));
|
|
242
|
+
case 1:
|
|
243
|
+
case "end":
|
|
244
|
+
return _context4.stop();
|
|
245
|
+
}
|
|
246
|
+
}, _callee4);
|
|
247
|
+
}))();
|
|
248
|
+
}
|
|
249
|
+
runStreamSend(params) {
|
|
250
|
+
var _this3 = this;
|
|
251
|
+
return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
|
252
|
+
var resultPromise, result;
|
|
253
|
+
return _regeneratorRuntime.wrap(function (_context5) {
|
|
254
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
255
|
+
case 0:
|
|
256
|
+
params.stream._bind(_this3.createStreamBindContext(params.bind));
|
|
257
|
+
resultPromise = params.beforeStart ? params.beforeStart({
|
|
258
|
+
stream: params.stream
|
|
259
|
+
}) : undefined;
|
|
260
|
+
if (!(params.awaitStart === false)) {
|
|
261
|
+
_context5.next = 2;
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Fire-and-forget:
|
|
266
|
+
* - request-body stream must start after REQUEST is sent (beforeStart is expected to send REQUEST synchronously)
|
|
267
|
+
* - we must NOT await the response promise before starting stream, otherwise server will time out waiting stream_start
|
|
268
|
+
*/
|
|
269
|
+
void params.stream.start();
|
|
270
|
+
_context5.next = 1;
|
|
271
|
+
return resultPromise;
|
|
272
|
+
case 1:
|
|
273
|
+
return _context5.abrupt("return", _context5.sent);
|
|
274
|
+
case 2:
|
|
275
|
+
_context5.next = 3;
|
|
276
|
+
return resultPromise;
|
|
277
|
+
case 3:
|
|
278
|
+
result = _context5.sent;
|
|
279
|
+
_context5.next = 4;
|
|
280
|
+
return params.stream.start();
|
|
281
|
+
case 4:
|
|
282
|
+
return _context5.abrupt("return", result);
|
|
283
|
+
case 5:
|
|
284
|
+
case "end":
|
|
285
|
+
return _context5.stop();
|
|
286
|
+
}
|
|
287
|
+
}, _callee5);
|
|
288
|
+
}))();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Send writable stream via peer.
|
|
293
|
+
*/
|
|
294
|
+
sendStream(params) {
|
|
295
|
+
var _this4 = this;
|
|
296
|
+
return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
|
|
297
|
+
return _regeneratorRuntime.wrap(function (_context7) {
|
|
298
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
299
|
+
case 0:
|
|
300
|
+
return _context7.abrupt("return", _this4.runWithHooks(params, /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
|
|
301
|
+
return _regeneratorRuntime.wrap(function (_context6) {
|
|
302
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
303
|
+
case 0:
|
|
304
|
+
_context6.next = 1;
|
|
305
|
+
return _this4.runStreamSend(params);
|
|
306
|
+
case 1:
|
|
307
|
+
return _context6.abrupt("return", _context6.sent);
|
|
308
|
+
case 2:
|
|
309
|
+
case "end":
|
|
310
|
+
return _context6.stop();
|
|
311
|
+
}
|
|
312
|
+
}, _callee6);
|
|
313
|
+
}))));
|
|
314
|
+
case 1:
|
|
315
|
+
case "end":
|
|
316
|
+
return _context7.stop();
|
|
317
|
+
}
|
|
318
|
+
}, _callee7);
|
|
319
|
+
}))();
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Send File/Blob/string as a file stream via peer.
|
|
324
|
+
*/
|
|
325
|
+
sendFile(params) {
|
|
326
|
+
var _this5 = this;
|
|
327
|
+
return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
|
|
328
|
+
return _regeneratorRuntime.wrap(function (_context9) {
|
|
329
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
330
|
+
case 0:
|
|
331
|
+
return _context9.abrupt("return", _this5.runWithHooks(params, /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
|
|
332
|
+
var _params$onFileInfo;
|
|
333
|
+
var created;
|
|
334
|
+
return _regeneratorRuntime.wrap(function (_context8) {
|
|
335
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
336
|
+
case 0:
|
|
337
|
+
_context8.next = 1;
|
|
338
|
+
return createIframeFileWritableStreamFromContent({
|
|
339
|
+
content: params.content,
|
|
340
|
+
fileName: params.fileName,
|
|
341
|
+
mimeType: params.mimeType,
|
|
342
|
+
chunked: params.chunked,
|
|
343
|
+
autoResolve: params.autoResolve,
|
|
344
|
+
defaultFileName: params.defaultFileName,
|
|
345
|
+
defaultMimeType: params.defaultMimeType
|
|
346
|
+
});
|
|
347
|
+
case 1:
|
|
348
|
+
created = _context8.sent;
|
|
349
|
+
_context8.next = 2;
|
|
350
|
+
return (_params$onFileInfo = params.onFileInfo) === null || _params$onFileInfo === void 0 ? void 0 : _params$onFileInfo.call(params, {
|
|
351
|
+
fileName: created.fileName,
|
|
352
|
+
mimeType: created.mimeType
|
|
353
|
+
});
|
|
354
|
+
case 2:
|
|
355
|
+
_context8.next = 3;
|
|
356
|
+
return _this5.runStreamSend(_objectSpread(_objectSpread({}, params.stream), {}, {
|
|
357
|
+
stream: created.stream
|
|
358
|
+
}));
|
|
359
|
+
case 3:
|
|
360
|
+
return _context8.abrupt("return", _context8.sent);
|
|
361
|
+
case 4:
|
|
362
|
+
case "end":
|
|
363
|
+
return _context8.stop();
|
|
364
|
+
}
|
|
365
|
+
}, _callee8);
|
|
366
|
+
}))));
|
|
367
|
+
case 1:
|
|
368
|
+
case "end":
|
|
369
|
+
return _context9.stop();
|
|
370
|
+
}
|
|
371
|
+
}, _callee9);
|
|
372
|
+
}))();
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Send typed message with peer pre-bound.
|
|
377
|
+
*/
|
|
378
|
+
sendMessage(type, requestId, data) {
|
|
379
|
+
var payload = _objectSpread({}, data || {});
|
|
380
|
+
if (payload.targetId === undefined && this.defaultTargetId !== undefined) {
|
|
381
|
+
payload.targetId = this.defaultTargetId;
|
|
382
|
+
}
|
|
383
|
+
this.hooks.beforeSendMessage.call(type, requestId, payload);
|
|
384
|
+
try {
|
|
385
|
+
var _ok = this.dispatcher.sendMessage(this.targetWindow, this.targetOrigin, type, requestId, payload);
|
|
386
|
+
this.hooks.afterSendMessage.call(type, requestId, payload, _ok);
|
|
387
|
+
return _ok;
|
|
388
|
+
} catch (e) {
|
|
389
|
+
this.hooks.sendMessageError.call(type, requestId, payload, e);
|
|
390
|
+
throw e;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Send raw message with peer pre-bound.
|
|
396
|
+
*/
|
|
397
|
+
sendRaw(message) {
|
|
398
|
+
this.hooks.beforeSendRaw.call(message);
|
|
399
|
+
try {
|
|
400
|
+
var _ok2 = this.dispatcher.send(this.targetWindow, message, this.targetOrigin);
|
|
401
|
+
this.hooks.afterSendRaw.call(message, _ok2);
|
|
402
|
+
return _ok2;
|
|
403
|
+
} catch (e) {
|
|
404
|
+
this.hooks.sendRawError.call(message, e);
|
|
405
|
+
throw e;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
import "core-js/modules/es.array.filter.js";
|
|
5
|
+
import "core-js/modules/es.array.iterator.js";
|
|
6
|
+
import "core-js/modules/es.map.js";
|
|
7
|
+
import "core-js/modules/es.object.get-own-property-descriptors.js";
|
|
8
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
9
|
+
import "core-js/modules/es.string.replace.js";
|
|
10
|
+
import "core-js/modules/web.dom-collections.for-each.js";
|
|
11
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
12
|
+
/**
|
|
13
|
+
* Endpoint Stream integration layer (`src/endpoint/stream`)
|
|
14
|
+
*
|
|
15
|
+
* This directory integrates postMessage `stream_*` messages with the stream object system in `src/stream`:
|
|
16
|
+
* - Demultiplex `stream_*` frames by streamId to the bound handler
|
|
17
|
+
* - Does NOT implement the stream protocol itself (protocol lives in `src/stream`)
|
|
18
|
+
*
|
|
19
|
+
* RequestIframeStreamDispatcher
|
|
20
|
+
*
|
|
21
|
+
* - Maintains streamId -> handler mapping
|
|
22
|
+
* - Dispatches incoming `stream_*` PostMessageData to the mapped handler
|
|
23
|
+
*/
|
|
24
|
+
export class RequestIframeStreamDispatcher {
|
|
25
|
+
constructor(params) {
|
|
26
|
+
_defineProperty(this, "handlers", new Map());
|
|
27
|
+
this.handledBy = params.handledBy;
|
|
28
|
+
}
|
|
29
|
+
register(streamId, handler) {
|
|
30
|
+
this.handlers.set(streamId, handler);
|
|
31
|
+
}
|
|
32
|
+
unregister(streamId) {
|
|
33
|
+
this.handlers.delete(streamId);
|
|
34
|
+
}
|
|
35
|
+
clear() {
|
|
36
|
+
this.handlers.clear();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Dispatch a framework stream_* PostMessageData to its streamId handler.
|
|
41
|
+
*
|
|
42
|
+
* - If context is provided, dispatcher will mark accepted/handledBy when handler exists.
|
|
43
|
+
* - If context is omitted, dispatcher will skip marking (useful when origin was validated upstream).
|
|
44
|
+
*/
|
|
45
|
+
dispatch(data, context) {
|
|
46
|
+
var body = data.body;
|
|
47
|
+
if (!(body !== null && body !== void 0 && body.streamId)) return;
|
|
48
|
+
var handler = this.handlers.get(body.streamId);
|
|
49
|
+
if (!handler) return;
|
|
50
|
+
if (context) {
|
|
51
|
+
context.markAcceptedBy(this.handledBy);
|
|
52
|
+
}
|
|
53
|
+
var messageType = data.type.replace('stream_', '');
|
|
54
|
+
handler(_objectSpread(_objectSpread({}, body), {}, {
|
|
55
|
+
type: messageType
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ErrorCode, HttpStatus, HttpStatusText, Messages, formatMessage } from '../../constants';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Endpoint Stream integration layer (`src/endpoint/stream`)
|
|
5
|
+
*
|
|
6
|
+
* This directory integrates postMessage `stream_*` messages with the stream object system in `src/stream`:
|
|
7
|
+
* - Endpoint-side composition / protocol glue (e.g. stream_start timeout error payload)
|
|
8
|
+
* - Does NOT implement the stream protocol itself (protocol lives in `src/stream`)
|
|
9
|
+
*
|
|
10
|
+
* Build the ERROR payload for stream_start timeout.
|
|
11
|
+
*
|
|
12
|
+
* Used by server-side "request-body stream handshake" when the client fails to send stream_start in time.
|
|
13
|
+
*/
|
|
14
|
+
export function buildStreamStartTimeoutErrorPayload(params) {
|
|
15
|
+
return {
|
|
16
|
+
path: params.path,
|
|
17
|
+
error: {
|
|
18
|
+
message: formatMessage(Messages.STREAM_START_TIMEOUT, params.timeoutMs),
|
|
19
|
+
code: ErrorCode.STREAM_START_TIMEOUT
|
|
20
|
+
},
|
|
21
|
+
status: HttpStatus.REQUEST_TIMEOUT,
|
|
22
|
+
statusText: HttpStatusText[HttpStatus.REQUEST_TIMEOUT],
|
|
23
|
+
requireAck: params.requireAck,
|
|
24
|
+
ack: params.ack,
|
|
25
|
+
targetId: params.targetId
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { IframeReadableStream, IframeFileReadableStream } from '../../stream';
|
|
2
|
+
import { StreamType as StreamTypeConstant } from '../../constants';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Endpoint Stream integration layer (`src/endpoint/stream`)
|
|
6
|
+
*
|
|
7
|
+
* This directory integrates postMessage `stream_*` messages with the stream object system in `src/stream`:
|
|
8
|
+
* - Parses stream_start and creates the corresponding ReadableStream (data/file)
|
|
9
|
+
* - Does NOT implement the stream protocol itself (protocol lives in `src/stream`)
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Parsed stream_start body info.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Parse stream_start body with defaults.
|
|
18
|
+
*/
|
|
19
|
+
export function parseStreamStart(body) {
|
|
20
|
+
var _chunked, _autoResolve;
|
|
21
|
+
var b = body;
|
|
22
|
+
if (!(b !== null && b !== void 0 && b.streamId)) return null;
|
|
23
|
+
return {
|
|
24
|
+
streamId: b.streamId,
|
|
25
|
+
type: b.type || StreamTypeConstant.DATA,
|
|
26
|
+
mode: b.mode,
|
|
27
|
+
chunked: (_chunked = b.chunked) !== null && _chunked !== void 0 ? _chunked : true,
|
|
28
|
+
metadata: b.metadata,
|
|
29
|
+
autoResolve: (_autoResolve = b.autoResolve) !== null && _autoResolve !== void 0 ? _autoResolve : false
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Create a readable stream instance from a stream_start message/body.
|
|
35
|
+
*
|
|
36
|
+
* This is shared by:
|
|
37
|
+
* - client side: receiving response stream from server
|
|
38
|
+
* - server side: receiving request-body stream from client
|
|
39
|
+
*/
|
|
40
|
+
export function createReadableStreamFromStart(params) {
|
|
41
|
+
var _params$secretKey;
|
|
42
|
+
var info = parseStreamStart(params.data.body);
|
|
43
|
+
if (!info) return null;
|
|
44
|
+
var secretKey = (_params$secretKey = params.secretKey) !== null && _params$secretKey !== void 0 ? _params$secretKey : params.data.secretKey;
|
|
45
|
+
if (info.type === StreamTypeConstant.FILE) {
|
|
46
|
+
var _info$metadata, _info$metadata2, _info$metadata3;
|
|
47
|
+
var fileStream = new IframeFileReadableStream(info.streamId, params.requestId, params.handler, {
|
|
48
|
+
chunked: info.chunked,
|
|
49
|
+
metadata: info.metadata,
|
|
50
|
+
secretKey,
|
|
51
|
+
mode: info.mode,
|
|
52
|
+
idleTimeout: params.idleTimeout,
|
|
53
|
+
heartbeat: params.heartbeat,
|
|
54
|
+
filename: (_info$metadata = info.metadata) === null || _info$metadata === void 0 ? void 0 : _info$metadata.filename,
|
|
55
|
+
mimeType: (_info$metadata2 = info.metadata) === null || _info$metadata2 === void 0 ? void 0 : _info$metadata2.mimeType,
|
|
56
|
+
size: (_info$metadata3 = info.metadata) === null || _info$metadata3 === void 0 ? void 0 : _info$metadata3.size
|
|
57
|
+
});
|
|
58
|
+
return {
|
|
59
|
+
stream: fileStream,
|
|
60
|
+
info
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
var readableStream = new IframeReadableStream(info.streamId, params.requestId, params.handler, {
|
|
64
|
+
type: info.type,
|
|
65
|
+
mode: info.mode,
|
|
66
|
+
chunked: info.chunked,
|
|
67
|
+
metadata: info.metadata,
|
|
68
|
+
secretKey,
|
|
69
|
+
idleTimeout: params.idleTimeout,
|
|
70
|
+
heartbeat: params.heartbeat
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
stream: readableStream,
|
|
74
|
+
info
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
2
|
+
import "core-js/modules/es.string.match.js";
|
|
3
|
+
import { HttpHeader } from '../../constants';
|
|
4
|
+
/**
|
|
5
|
+
* Endpoint Stream integration layer (`src/endpoint/stream`)
|
|
6
|
+
*
|
|
7
|
+
* This directory integrates postMessage `stream_*` messages with the stream object system in `src/stream`:
|
|
8
|
+
* - Endpoint-side file stream utilities (e.g. choose filename from header/metadata and auto-resolve)
|
|
9
|
+
* - Does NOT implement the stream protocol itself (protocol lives in `src/stream`)
|
|
10
|
+
*
|
|
11
|
+
* Parse filename from Content-Disposition header.
|
|
12
|
+
*/
|
|
13
|
+
export function parseFilenameFromContentDisposition(value) {
|
|
14
|
+
if (!value) return undefined;
|
|
15
|
+
var disposition = typeof value === 'string' ? value : value[0];
|
|
16
|
+
if (!disposition) return undefined;
|
|
17
|
+
var match = disposition.match(/filename="?([^"]+)"?/i);
|
|
18
|
+
return match ? match[1] : undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Auto resolve a file readable stream to File/Blob.
|
|
23
|
+
*
|
|
24
|
+
* Filename priority:
|
|
25
|
+
* - Content-Disposition filename (if provided)
|
|
26
|
+
* - stream_start metadata filename (if provided)
|
|
27
|
+
* - stream.filename (if provided)
|
|
28
|
+
*/
|
|
29
|
+
export function autoResolveIframeFileReadableStream(params) {
|
|
30
|
+
var _params$headers, _params$info;
|
|
31
|
+
var headerFilename = parseFilenameFromContentDisposition((_params$headers = params.headers) === null || _params$headers === void 0 ? void 0 : _params$headers[HttpHeader.CONTENT_DISPOSITION]);
|
|
32
|
+
var fileName = headerFilename || ((_params$info = params.info) === null || _params$info === void 0 || (_params$info = _params$info.metadata) === null || _params$info === void 0 ? void 0 : _params$info.filename) || params.fileStream.filename;
|
|
33
|
+
return fileName ? params.fileStream.readAsFile(fileName) : params.fileStream.readAsBlob();
|
|
34
|
+
}
|