request-iframe 0.1.0 → 0.2.0
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 +302 -54
- package/README.md +281 -36
- 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 +19735 -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 +31 -22
- package/esm/api/endpoint.js +229 -0
- package/esm/api/server.js +19 -9
- package/esm/constants/debug.js +17 -0
- package/esm/constants/index.js +115 -66
- package/esm/constants/log.js +11 -0
- package/esm/constants/messages.js +6 -1
- 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 +243 -320
- package/esm/{core → impl}/response.js +120 -154
- 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 +92 -5
- package/esm/message/dispatcher.js +149 -98
- package/esm/stream/error.js +22 -0
- package/esm/stream/index.js +3 -1
- package/esm/stream/readable-stream.js +101 -26
- package/esm/stream/stream-core.js +121 -3
- package/esm/stream/writable-stream.js +368 -43
- package/esm/utils/ack.js +36 -0
- 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 +157 -180
- 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 +12 -162
- package/esm/utils/is.js +3 -0
- package/esm/utils/logger.js +55 -0
- package/esm/utils/origin.js +3 -1
- 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 +32 -23
- 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 +19 -9
- 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 +58 -7
- package/library/constants/index.d.ts.map +1 -1
- package/library/constants/index.js +143 -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 +6 -1
- package/library/constants/messages.d.ts.map +1 -1
- package/library/constants/messages.js +6 -1
- 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 +254 -333
- package/library/{core → impl}/request.d.ts.map +1 -1
- package/library/{core → impl}/response.d.ts +7 -12
- package/library/impl/response.d.ts.map +1 -0
- package/library/{core → impl}/response.js +120 -154
- package/library/{core → impl}/server.d.ts +26 -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 +96 -9
- package/library/message/dispatcher.d.ts +17 -0
- package/library/message/dispatcher.d.ts.map +1 -1
- package/library/message/dispatcher.js +149 -98
- 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 +102 -27
- package/library/stream/stream-core.d.ts +22 -1
- package/library/stream/stream-core.d.ts.map +1 -1
- package/library/stream/stream-core.js +120 -2
- package/library/stream/types.d.ts +115 -2
- package/library/stream/types.d.ts.map +1 -1
- package/library/stream/writable-stream.d.ts +20 -2
- package/library/stream/writable-stream.d.ts.map +1 -1
- package/library/stream/writable-stream.js +366 -41
- package/library/types/index.d.ts +17 -22
- package/library/types/index.d.ts.map +1 -1
- package/library/utils/ack.d.ts +2 -0
- package/library/utils/ack.d.ts.map +1 -0
- package/library/utils/ack.js +44 -0
- 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 +156 -178
- 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 -193
- 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/origin.d.ts.map +1 -1
- package/library/utils/origin.js +2 -1
- 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 -329
- package/esm/core/server.js +0 -767
- package/esm/utils/ack-meta.js +0 -53
- package/library/core/client-server.d.ts +0 -106
- package/library/core/client-server.d.ts.map +0 -1
- package/library/core/client-server.js +0 -336
- 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 -772
- package/library/utils/ack-meta.d.ts +0 -2
- package/library/utils/ack-meta.d.ts.map +0 -1
- package/library/utils/ack-meta.js +0 -59
- /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
|
@@ -12,24 +12,24 @@ import "core-js/modules/es.array.filter.js";
|
|
|
12
12
|
import "core-js/modules/es.array.from.js";
|
|
13
13
|
import "core-js/modules/es.array.iterator.js";
|
|
14
14
|
import "core-js/modules/es.array.slice.js";
|
|
15
|
-
import "core-js/modules/es.map.js";
|
|
16
15
|
import "core-js/modules/es.object.entries.js";
|
|
17
|
-
import "core-js/modules/es.promise.js";
|
|
18
16
|
import "core-js/modules/es.object.get-own-property-descriptors.js";
|
|
17
|
+
import "core-js/modules/es.promise.js";
|
|
19
18
|
import "core-js/modules/es.regexp.exec.js";
|
|
20
19
|
import "core-js/modules/es.regexp.to-string.js";
|
|
21
|
-
import "core-js/modules/es.string.match.js";
|
|
22
|
-
import "core-js/modules/es.string.replace.js";
|
|
23
|
-
import "core-js/modules/es.string.starts-with.js";
|
|
24
20
|
import "core-js/modules/web.dom-collections.for-each.js";
|
|
25
21
|
import "core-js/modules/web.dom-collections.iterator.js";
|
|
26
|
-
import { RequestIframeError } from '../utils';
|
|
27
|
-
import {
|
|
28
|
-
import { detectContentType
|
|
29
|
-
import {
|
|
22
|
+
import { RequestIframeError } from '../utils/error';
|
|
23
|
+
import { isExpectedAckMatch } from '../endpoint';
|
|
24
|
+
import { detectContentType } from '../utils/content-type';
|
|
25
|
+
import { isWindowAvailable } from '../utils/window';
|
|
26
|
+
import { generateRequestId, generateInstanceId } from '../utils/id';
|
|
27
|
+
import { CookieStore } from '../utils/cookie';
|
|
30
28
|
import { RequestInterceptorManager, ResponseInterceptorManager, runRequestInterceptors, runResponseInterceptors } from '../interceptors';
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
29
|
+
import { RequestIframeEndpointFacade, createReadableStreamFromStart } from '../endpoint';
|
|
30
|
+
import { autoResolveIframeFileReadableStream } from '../endpoint';
|
|
31
|
+
import { DefaultTimeout, ErrorCode, MessageType, MessageRole, HttpStatus, HttpStatusText, HttpHeader, Messages, formatMessage, StreamType as StreamTypeConstant } from '../constants';
|
|
32
|
+
import { isFunction } from '../utils/is';
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Client configuration options
|
|
@@ -44,7 +44,14 @@ export class RequestIframeClientImpl {
|
|
|
44
44
|
* When a response is received, we remember the server's creatorId as the targetId for future requests
|
|
45
45
|
*/
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
rememberTargetServerId(serverId) {
|
|
48
|
+
if (!serverId) return;
|
|
49
|
+
if (!this._targetServerId) {
|
|
50
|
+
this._targetServerId = serverId;
|
|
51
|
+
this.outbox.setDefaultTargetId(serverId);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
constructor(targetWindow, targetOrigin, options, instanceId) {
|
|
48
55
|
var _options$ackTimeout, _options$timeout, _options$asyncTimeout, _options$returnData;
|
|
49
56
|
/** Unique instance ID */
|
|
50
57
|
_defineProperty(this, "interceptors", {
|
|
@@ -57,28 +64,43 @@ export class RequestIframeClientImpl {
|
|
|
57
64
|
* - Automatically parses Set-Cookie and saves when receiving response
|
|
58
65
|
*/
|
|
59
66
|
_defineProperty(this, "_cookieStore", new CookieStore());
|
|
60
|
-
/**
|
|
61
|
-
* Stream message handler map
|
|
62
|
-
* key: streamId
|
|
63
|
-
* value: stream message handler function
|
|
64
|
-
*/
|
|
65
|
-
_defineProperty(this, "streamHandlers", new Map());
|
|
66
67
|
this.id = instanceId || generateInstanceId();
|
|
67
68
|
this.targetWindow = targetWindow;
|
|
68
69
|
this.targetOrigin = targetOrigin;
|
|
69
|
-
this.server = server;
|
|
70
70
|
this.secretKey = options === null || options === void 0 ? void 0 : options.secretKey;
|
|
71
|
+
var endpoint = new RequestIframeEndpointFacade({
|
|
72
|
+
role: MessageRole.CLIENT,
|
|
73
|
+
instanceId: this.id,
|
|
74
|
+
secretKey: options === null || options === void 0 ? void 0 : options.secretKey,
|
|
75
|
+
autoAckMaxMetaLength: options === null || options === void 0 ? void 0 : options.autoAckMaxMetaLength,
|
|
76
|
+
autoAckMaxIdLength: options === null || options === void 0 ? void 0 : options.autoAckMaxIdLength,
|
|
77
|
+
inbox: {},
|
|
78
|
+
streamDispatcher: {
|
|
79
|
+
handledBy: this.id
|
|
80
|
+
},
|
|
81
|
+
originValidator: {
|
|
82
|
+
allowedOrigins: options === null || options === void 0 ? void 0 : options.allowedOrigins,
|
|
83
|
+
validateOrigin: options === null || options === void 0 ? void 0 : options.validateOrigin
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
this.endpoint = endpoint;
|
|
87
|
+
/** Core/routers shared composition */
|
|
88
|
+
this.hub = endpoint.hub;
|
|
89
|
+
this.streamDispatcher = endpoint.streamDispatcher;
|
|
90
|
+
this.inbox = endpoint.inbox;
|
|
91
|
+
this.originValidator = endpoint.originValidator;
|
|
92
|
+
|
|
93
|
+
/** Create a fixed-peer sender (built-in client) */
|
|
94
|
+
this.outbox = this.hub.createOutbox(this.targetWindow, this.targetOrigin);
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Register base message infra + response handlers via facade.
|
|
98
|
+
* These hooks will run when client.open() is called.
|
|
99
|
+
*/
|
|
100
|
+
this.endpoint.onOpen(() => this.inbox.registerHandlers());
|
|
71
101
|
|
|
72
102
|
// Provide fallback target for auto-ack (useful when MessageEvent.source is missing in tests)
|
|
73
|
-
this.
|
|
74
|
-
|
|
75
|
-
// Build origin validator (incoming messages)
|
|
76
|
-
if (options !== null && options !== void 0 && options.validateOrigin) {
|
|
77
|
-
this.originValidator = (origin, data, context) => options.validateOrigin(origin, data, context);
|
|
78
|
-
} else if (options !== null && options !== void 0 && options.allowedOrigins) {
|
|
79
|
-
var matcher = options.allowedOrigins;
|
|
80
|
-
this.originValidator = origin => matchOrigin(origin, matcher);
|
|
81
|
-
}
|
|
103
|
+
this.hub.setFallbackTarget(this.outbox.targetWindow, this.outbox.targetOrigin);
|
|
82
104
|
|
|
83
105
|
// Set default timeout configuration
|
|
84
106
|
this.defaultAckTimeout = (_options$ackTimeout = options === null || options === void 0 ? void 0 : options.ackTimeout) !== null && _options$ackTimeout !== void 0 ? _options$ackTimeout : DefaultTimeout.ACK;
|
|
@@ -91,73 +113,58 @@ export class RequestIframeClientImpl {
|
|
|
91
113
|
// Save initial headers configuration
|
|
92
114
|
this.initialHeaders = options === null || options === void 0 ? void 0 : options.headers;
|
|
93
115
|
|
|
94
|
-
//
|
|
95
|
-
this.
|
|
96
|
-
this.
|
|
116
|
+
// Stream dispatching is owned by facade (pluggable stream infra)
|
|
117
|
+
this.endpoint.enableStreamDispatcherCallback({
|
|
118
|
+
isOriginAllowed: (d, ctx) => this.hub.isOriginAllowedBy(ctx.origin, d, ctx, this.targetOrigin, this.originValidator)
|
|
97
119
|
});
|
|
120
|
+
this.endpoint.registerClientStreamCallbackHandlers({
|
|
121
|
+
handlerOptions: this.hub.createHandlerOptions(() => {
|
|
122
|
+
/** ignore version errors for stream frames */
|
|
123
|
+
})
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
/** Auto-open by default (unless explicitly set to false) */
|
|
127
|
+
if ((options === null || options === void 0 ? void 0 : options.autoOpen) !== false) {
|
|
128
|
+
this.open();
|
|
129
|
+
}
|
|
98
130
|
}
|
|
99
131
|
|
|
100
132
|
/**
|
|
101
133
|
* Register stream message handler (StreamMessageHandler interface implementation)
|
|
102
134
|
*/
|
|
103
135
|
registerStreamHandler(streamId, handler) {
|
|
104
|
-
this.
|
|
136
|
+
this.streamDispatcher.register(streamId, handler);
|
|
105
137
|
}
|
|
106
138
|
|
|
107
139
|
/**
|
|
108
140
|
* Unregister stream message handler (StreamMessageHandler interface implementation)
|
|
109
141
|
*/
|
|
110
142
|
unregisterStreamHandler(streamId) {
|
|
111
|
-
this.
|
|
143
|
+
this.streamDispatcher.unregister(streamId);
|
|
112
144
|
}
|
|
113
145
|
|
|
114
146
|
/*
|
|
115
147
|
Send message (StreamMessageHandler interface implementation)
|
|
116
148
|
*/
|
|
117
149
|
postMessage(message) {
|
|
118
|
-
|
|
119
|
-
this.server.messageDispatcher.send(this.targetWindow, message, this.targetOrigin);
|
|
150
|
+
this.sendRaw(message);
|
|
120
151
|
}
|
|
121
152
|
|
|
122
153
|
/**
|
|
123
|
-
*
|
|
154
|
+
* Send raw framework message (advanced).
|
|
155
|
+
*
|
|
156
|
+
* Note: streams call `postMessage` via StreamMessageHandler, which delegates here.
|
|
124
157
|
*/
|
|
125
|
-
|
|
126
|
-
//
|
|
127
|
-
|
|
128
|
-
if (this.originValidator) {
|
|
129
|
-
try {
|
|
130
|
-
if (!this.originValidator(context.origin, data, context)) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
} catch (_unused) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
} else if (this.targetOrigin !== '*' && context.origin !== this.targetOrigin) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
var body = data.body;
|
|
141
|
-
if (!body || !body.streamId) return;
|
|
142
|
-
var handler = this.streamHandlers.get(body.streamId);
|
|
143
|
-
if (handler) {
|
|
144
|
-
if (context && !context.handledBy) {
|
|
145
|
-
context.accepted = true;
|
|
146
|
-
context.handledBy = this.id;
|
|
147
|
-
}
|
|
148
|
-
// Extract message type (remove stream_ prefix)
|
|
149
|
-
var messageType = data.type.replace('stream_', '');
|
|
150
|
-
handler(_objectSpread(_objectSpread({}, body), {}, {
|
|
151
|
-
type: messageType
|
|
152
|
-
}));
|
|
153
|
-
}
|
|
158
|
+
sendRaw(message) {
|
|
159
|
+
// Window check is handled in MessageDispatcher
|
|
160
|
+
this.outbox.sendRaw(message);
|
|
154
161
|
}
|
|
155
162
|
|
|
156
163
|
/**
|
|
157
164
|
* Resolve header value (handle function type headers)
|
|
158
165
|
*/
|
|
159
166
|
resolveHeaderValue(value, config) {
|
|
160
|
-
if (
|
|
167
|
+
if (isFunction(value)) {
|
|
161
168
|
return value(config);
|
|
162
169
|
}
|
|
163
170
|
return value;
|
|
@@ -222,60 +229,27 @@ export class RequestIframeClientImpl {
|
|
|
222
229
|
* Check if server is reachable
|
|
223
230
|
*/
|
|
224
231
|
isConnect() {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
requestId
|
|
241
|
-
}));
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
this.server._registerPendingRequest(requestId, data => {
|
|
245
|
-
if (done) return;
|
|
246
|
-
if (data.type === MessageType.ACK || data.type === MessageType.PONG) {
|
|
247
|
-
// Remember server's creatorId as target server ID for future requests
|
|
248
|
-
if (data.creatorId && !this._targetServerId) {
|
|
249
|
-
this._targetServerId = data.creatorId;
|
|
250
|
-
}
|
|
251
|
-
done = true;
|
|
252
|
-
cleanup();
|
|
253
|
-
resolve(true);
|
|
254
|
-
}
|
|
255
|
-
}, () => {
|
|
256
|
-
if (done) return;
|
|
257
|
-
done = true;
|
|
258
|
-
cleanup();
|
|
259
|
-
resolve(false);
|
|
260
|
-
}, this.targetOrigin, this.originValidator);
|
|
261
|
-
timeoutId = setTimeout(() => {
|
|
262
|
-
if (done) return;
|
|
263
|
-
done = true;
|
|
264
|
-
cleanup();
|
|
265
|
-
resolve(false);
|
|
266
|
-
}, this.defaultAckTimeout);
|
|
267
|
-
|
|
268
|
-
// Send ping via MessageDispatcher
|
|
269
|
-
this.server.messageDispatcher.sendMessage(this.targetWindow, this.targetOrigin, MessageType.PING, requestId, {
|
|
270
|
-
requireAck: true,
|
|
271
|
-
targetId: this._targetServerId
|
|
272
|
-
});
|
|
232
|
+
// Check if target window is still available before sending ping
|
|
233
|
+
if (!isWindowAvailable(this.targetWindow)) {
|
|
234
|
+
return Promise.reject(new RequestIframeError({
|
|
235
|
+
message: Messages.TARGET_WINDOW_CLOSED,
|
|
236
|
+
code: ErrorCode.TARGET_WINDOW_CLOSED,
|
|
237
|
+
config: undefined,
|
|
238
|
+
requestId: `ping_${Date.now()}`
|
|
239
|
+
}));
|
|
240
|
+
}
|
|
241
|
+
return this.endpoint.pingIsConnect({
|
|
242
|
+
peer: this.outbox,
|
|
243
|
+
timeoutMs: this.defaultAckTimeout,
|
|
244
|
+
targetOrigin: this.targetOrigin,
|
|
245
|
+
targetId: this._targetServerId,
|
|
246
|
+
onPeerId: serverId => this.rememberTargetServerId(serverId)
|
|
273
247
|
});
|
|
274
248
|
}
|
|
275
249
|
send(path, body, options) {
|
|
276
250
|
var _this = this;
|
|
277
251
|
return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
278
|
-
var config, processedConfig, processedBody
|
|
252
|
+
var config, processedConfig, processedBody;
|
|
279
253
|
return _regeneratorRuntime.wrap(function (_context) {
|
|
280
254
|
while (1) switch (_context.prev = _context.next) {
|
|
281
255
|
case 0:
|
|
@@ -287,25 +261,28 @@ export class RequestIframeClientImpl {
|
|
|
287
261
|
return runRequestInterceptors(_this.interceptors.request, config);
|
|
288
262
|
case 1:
|
|
289
263
|
processedConfig = _context.sent;
|
|
290
|
-
processedBody = processedConfig.body;
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
264
|
+
processedBody = processedConfig.body;
|
|
265
|
+
return _context.abrupt("return", _this.outbox.send({
|
|
266
|
+
data: processedBody,
|
|
267
|
+
onFileOrBlob: () => {
|
|
268
|
+
return _this.sendFile(path, processedBody, options);
|
|
269
|
+
},
|
|
270
|
+
onStream: () => {
|
|
271
|
+
return _this.sendStream(path, processedBody, options);
|
|
272
|
+
},
|
|
273
|
+
onOther: () => {
|
|
274
|
+
// Merge and resolve headers (initial headers + request headers)
|
|
275
|
+
var mergedHeaders = _this.mergeHeaders(processedConfig, processedBody);
|
|
276
|
+
var processedPath = processedConfig.path,
|
|
277
|
+
processedCookies = processedConfig.cookies,
|
|
278
|
+
userTargetId = processedConfig.targetId,
|
|
279
|
+
_processedConfig$requ = processedConfig.requestId,
|
|
280
|
+
requestId = _processedConfig$requ === void 0 ? generateRequestId() : _processedConfig$requ;
|
|
281
|
+
var targetId = userTargetId || _this._targetServerId;
|
|
282
|
+
return _this._sendRequest(processedPath, processedBody, mergedHeaders, processedCookies, processedConfig, requestId, targetId);
|
|
283
|
+
}
|
|
284
|
+
}));
|
|
296
285
|
case 2:
|
|
297
|
-
if (!isIframeWritableStream(processedBody)) {
|
|
298
|
-
_context.next = 3;
|
|
299
|
-
break;
|
|
300
|
-
}
|
|
301
|
-
return _context.abrupt("return", _this.sendStream(path, processedBody, options));
|
|
302
|
-
case 3:
|
|
303
|
-
// Merge and resolve headers (initial headers + request headers)
|
|
304
|
-
mergedHeaders = _this.mergeHeaders(processedConfig, processedBody);
|
|
305
|
-
processedPath = processedConfig.path, processedCookies = processedConfig.cookies, userTargetId = processedConfig.targetId, _processedConfig$requ = processedConfig.requestId, requestId = _processedConfig$requ === void 0 ? generateRequestId() : _processedConfig$requ;
|
|
306
|
-
targetId = userTargetId || _this._targetServerId;
|
|
307
|
-
return _context.abrupt("return", _this._sendRequest(processedPath, processedBody, mergedHeaders, processedCookies, processedConfig, requestId, targetId));
|
|
308
|
-
case 4:
|
|
309
286
|
case "end":
|
|
310
287
|
return _context.stop();
|
|
311
288
|
}
|
|
@@ -318,67 +295,61 @@ export class RequestIframeClientImpl {
|
|
|
318
295
|
*/
|
|
319
296
|
sendFile(path, content, options) {
|
|
320
297
|
var _this2 = this;
|
|
321
|
-
return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
322
|
-
var _options$autoResolve;
|
|
323
|
-
var
|
|
324
|
-
return _regeneratorRuntime.wrap(function (
|
|
325
|
-
while (1) switch (
|
|
298
|
+
return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
299
|
+
var _processedConfig$requ2, _processedConfig$targ, _options$autoResolve;
|
|
300
|
+
var config, processedConfig, requestId, targetId, processedPath, mergedHeaders, pathMatchedCookies, mergedCookies, streamConfig;
|
|
301
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
302
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
326
303
|
case 0:
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
304
|
+
config = _objectSpread({
|
|
305
|
+
path,
|
|
306
|
+
body: undefined
|
|
307
|
+
}, options);
|
|
308
|
+
_context2.next = 1;
|
|
309
|
+
return runRequestInterceptors(_this2.interceptors.request, config);
|
|
332
310
|
case 1:
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
311
|
+
processedConfig = _context2.sent;
|
|
312
|
+
requestId = (_processedConfig$requ2 = processedConfig.requestId) !== null && _processedConfig$requ2 !== void 0 ? _processedConfig$requ2 : generateRequestId();
|
|
313
|
+
targetId = (_processedConfig$targ = processedConfig.targetId) !== null && _processedConfig$targ !== void 0 ? _processedConfig$targ : _this2._targetServerId;
|
|
314
|
+
processedPath = processedConfig.path;
|
|
315
|
+
mergedHeaders = _this2.mergeHeaders(processedConfig, undefined);
|
|
316
|
+
pathMatchedCookies = _this2._cookieStore.getForPath(processedPath);
|
|
317
|
+
mergedCookies = _objectSpread(_objectSpread({}, pathMatchedCookies), processedConfig.cookies);
|
|
318
|
+
streamConfig = _objectSpread(_objectSpread({}, processedConfig), {}, {
|
|
319
|
+
requestId
|
|
320
|
+
});
|
|
321
|
+
return _context2.abrupt("return", _this2.outbox.sendFile({
|
|
322
|
+
content,
|
|
323
|
+
fileName: options === null || options === void 0 ? void 0 : options.fileName,
|
|
324
|
+
mimeType: options === null || options === void 0 ? void 0 : options.mimeType,
|
|
338
325
|
chunked: false,
|
|
339
|
-
autoResolve:
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
case 3:
|
|
359
|
-
data = _t;
|
|
360
|
-
return _context2.abrupt("return", {
|
|
361
|
-
data,
|
|
362
|
-
done: true
|
|
363
|
-
});
|
|
364
|
-
case 4:
|
|
365
|
-
case "end":
|
|
366
|
-
return _context2.stop();
|
|
367
|
-
}
|
|
368
|
-
}, _callee2);
|
|
369
|
-
}));
|
|
370
|
-
function next() {
|
|
371
|
-
return _next.apply(this, arguments);
|
|
326
|
+
autoResolve: (_options$autoResolve = options === null || options === void 0 ? void 0 : options.autoResolve) !== null && _options$autoResolve !== void 0 ? _options$autoResolve : true,
|
|
327
|
+
defaultFileName: typeof File !== 'undefined' && content instanceof File ? content.name : 'file',
|
|
328
|
+
defaultMimeType: 'application/octet-stream',
|
|
329
|
+
stream: {
|
|
330
|
+
bind: {
|
|
331
|
+
requestId,
|
|
332
|
+
registerStreamHandler: _this2.registerStreamHandler.bind(_this2),
|
|
333
|
+
unregisterStreamHandler: _this2.unregisterStreamHandler.bind(_this2),
|
|
334
|
+
heartbeat: () => _this2.isConnect(),
|
|
335
|
+
clientId: _this2.id,
|
|
336
|
+
targetId
|
|
337
|
+
},
|
|
338
|
+
awaitStart: false,
|
|
339
|
+
beforeStart: ({
|
|
340
|
+
stream
|
|
341
|
+
}) => {
|
|
342
|
+
return _this2._sendRequest(processedPath, undefined, mergedHeaders, mergedCookies, streamConfig, requestId, targetId, {
|
|
343
|
+
streamId: stream.streamId
|
|
344
|
+
});
|
|
372
345
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
});
|
|
376
|
-
return _context3.abrupt("return", _this2.sendStream(path, fileStream, options));
|
|
346
|
+
}
|
|
347
|
+
}));
|
|
377
348
|
case 2:
|
|
378
349
|
case "end":
|
|
379
|
-
return
|
|
350
|
+
return _context2.stop();
|
|
380
351
|
}
|
|
381
|
-
},
|
|
352
|
+
}, _callee2);
|
|
382
353
|
}))();
|
|
383
354
|
}
|
|
384
355
|
|
|
@@ -388,52 +359,53 @@ export class RequestIframeClientImpl {
|
|
|
388
359
|
*/
|
|
389
360
|
sendStream(path, stream, options) {
|
|
390
361
|
var _this3 = this;
|
|
391
|
-
return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
392
|
-
var _processedConfig$
|
|
393
|
-
var config, processedConfig, requestId, targetId, processedPath, mergedHeaders, pathMatchedCookies, mergedCookies, streamConfig
|
|
394
|
-
return _regeneratorRuntime.wrap(function (
|
|
395
|
-
while (1) switch (
|
|
362
|
+
return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
363
|
+
var _processedConfig$requ3, _processedConfig$targ2;
|
|
364
|
+
var config, processedConfig, requestId, targetId, processedPath, mergedHeaders, pathMatchedCookies, mergedCookies, streamConfig;
|
|
365
|
+
return _regeneratorRuntime.wrap(function (_context3) {
|
|
366
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
396
367
|
case 0:
|
|
397
368
|
config = _objectSpread({
|
|
398
369
|
path,
|
|
399
370
|
body: undefined
|
|
400
371
|
}, options);
|
|
401
|
-
|
|
372
|
+
_context3.next = 1;
|
|
402
373
|
return runRequestInterceptors(_this3.interceptors.request, config);
|
|
403
374
|
case 1:
|
|
404
|
-
processedConfig =
|
|
405
|
-
requestId = (_processedConfig$
|
|
406
|
-
targetId = (_processedConfig$
|
|
375
|
+
processedConfig = _context3.sent;
|
|
376
|
+
requestId = (_processedConfig$requ3 = processedConfig.requestId) !== null && _processedConfig$requ3 !== void 0 ? _processedConfig$requ3 : generateRequestId();
|
|
377
|
+
targetId = (_processedConfig$targ2 = processedConfig.targetId) !== null && _processedConfig$targ2 !== void 0 ? _processedConfig$targ2 : _this3._targetServerId;
|
|
407
378
|
processedPath = processedConfig.path;
|
|
408
|
-
stream._bind({
|
|
409
|
-
requestId,
|
|
410
|
-
targetWindow: _this3.targetWindow,
|
|
411
|
-
targetOrigin: _this3.targetOrigin,
|
|
412
|
-
secretKey: _this3.secretKey,
|
|
413
|
-
channel: _this3.server.messageDispatcher.getChannel(),
|
|
414
|
-
registerStreamHandler: _this3.registerStreamHandler.bind(_this3),
|
|
415
|
-
unregisterStreamHandler: _this3.unregisterStreamHandler.bind(_this3),
|
|
416
|
-
heartbeat: () => _this3.isConnect(),
|
|
417
|
-
clientId: _this3.id,
|
|
418
|
-
targetId
|
|
419
|
-
});
|
|
420
379
|
mergedHeaders = _this3.mergeHeaders(processedConfig, undefined);
|
|
421
380
|
pathMatchedCookies = _this3._cookieStore.getForPath(processedPath);
|
|
422
381
|
mergedCookies = _objectSpread(_objectSpread({}, pathMatchedCookies), processedConfig.cookies);
|
|
423
382
|
streamConfig = _objectSpread(_objectSpread({}, processedConfig), {}, {
|
|
424
383
|
requestId
|
|
425
384
|
});
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
385
|
+
return _context3.abrupt("return", _this3.outbox.sendStream({
|
|
386
|
+
stream: stream,
|
|
387
|
+
bind: {
|
|
388
|
+
requestId,
|
|
389
|
+
registerStreamHandler: _this3.registerStreamHandler.bind(_this3),
|
|
390
|
+
unregisterStreamHandler: _this3.unregisterStreamHandler.bind(_this3),
|
|
391
|
+
heartbeat: () => _this3.isConnect(),
|
|
392
|
+
clientId: _this3.id,
|
|
393
|
+
targetId
|
|
394
|
+
},
|
|
395
|
+
awaitStart: false,
|
|
396
|
+
beforeStart: ({
|
|
397
|
+
stream: s
|
|
398
|
+
}) => {
|
|
399
|
+
return _this3._sendRequest(processedPath, undefined, mergedHeaders, mergedCookies, streamConfig, requestId, targetId, {
|
|
400
|
+
streamId: s.streamId
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
}));
|
|
432
404
|
case 2:
|
|
433
405
|
case "end":
|
|
434
|
-
return
|
|
406
|
+
return _context3.stop();
|
|
435
407
|
}
|
|
436
|
-
},
|
|
408
|
+
}, _callee3);
|
|
437
409
|
}))();
|
|
438
410
|
}
|
|
439
411
|
|
|
@@ -447,10 +419,10 @@ export class RequestIframeClientImpl {
|
|
|
447
419
|
timeout = _processedConfig$time === void 0 ? this.defaultTimeout : _processedConfig$time,
|
|
448
420
|
_processedConfig$asyn = processedConfig.asyncTimeout,
|
|
449
421
|
asyncTimeout = _processedConfig$asyn === void 0 ? this.defaultAsyncTimeout : _processedConfig$asyn,
|
|
450
|
-
_processedConfig$
|
|
451
|
-
requireAck = _processedConfig$
|
|
422
|
+
_processedConfig$requ4 = processedConfig.requireAck,
|
|
423
|
+
requireAck = _processedConfig$requ4 === void 0 ? true : _processedConfig$requ4,
|
|
452
424
|
streamTimeout = processedConfig.streamTimeout,
|
|
453
|
-
|
|
425
|
+
ack = processedConfig.ack,
|
|
454
426
|
_processedConfig$retu = processedConfig.returnData,
|
|
455
427
|
returnData = _processedConfig$retu === void 0 ? this.defaultReturnData : _processedConfig$retu;
|
|
456
428
|
return new Promise((resolve, reject) => {
|
|
@@ -458,7 +430,7 @@ export class RequestIframeClientImpl {
|
|
|
458
430
|
var timeoutId = null;
|
|
459
431
|
var cleanup = () => {
|
|
460
432
|
if (timeoutId) clearTimeout(timeoutId);
|
|
461
|
-
this.
|
|
433
|
+
this.inbox.unregisterPendingRequest(requestId);
|
|
462
434
|
};
|
|
463
435
|
var fail = error => {
|
|
464
436
|
if (done) return;
|
|
@@ -519,19 +491,17 @@ export class RequestIframeClientImpl {
|
|
|
519
491
|
};
|
|
520
492
|
|
|
521
493
|
// Register to server's pending requests
|
|
522
|
-
this.
|
|
494
|
+
this.inbox.registerPendingRequest(requestId, data => {
|
|
523
495
|
if (done) return;
|
|
524
496
|
|
|
525
497
|
// Received ACK: server has received request
|
|
526
498
|
if (data.type === MessageType.ACK) {
|
|
527
|
-
// Optional
|
|
528
|
-
if (
|
|
499
|
+
// Optional ack match (ignore mismatched ACK)
|
|
500
|
+
if (!isExpectedAckMatch(ack, data.ack)) {
|
|
529
501
|
return;
|
|
530
502
|
}
|
|
531
503
|
// Remember server's creatorId as target server ID for future requests
|
|
532
|
-
|
|
533
|
-
this._targetServerId = data.creatorId;
|
|
534
|
-
}
|
|
504
|
+
this.rememberTargetServerId(data.creatorId);
|
|
535
505
|
// Switch to request timeout
|
|
536
506
|
setRequestTimeout();
|
|
537
507
|
return;
|
|
@@ -540,9 +510,7 @@ export class RequestIframeClientImpl {
|
|
|
540
510
|
// Received ASYNC notification: this is an async task
|
|
541
511
|
if (data.type === MessageType.ASYNC) {
|
|
542
512
|
// Remember server's creatorId as target server ID for future requests
|
|
543
|
-
|
|
544
|
-
this._targetServerId = data.creatorId;
|
|
545
|
-
}
|
|
513
|
+
this.rememberTargetServerId(data.creatorId);
|
|
546
514
|
// Switch to async timeout
|
|
547
515
|
setAsyncTimeout();
|
|
548
516
|
return;
|
|
@@ -550,50 +518,40 @@ export class RequestIframeClientImpl {
|
|
|
550
518
|
|
|
551
519
|
// Received stream start message
|
|
552
520
|
if (data.type === MessageType.STREAM_START) {
|
|
553
|
-
var _streamBody$chunked, _streamBody$autoResol;
|
|
554
521
|
done = true;
|
|
555
522
|
cleanup();
|
|
556
|
-
var streamBody = data.body;
|
|
557
|
-
var streamId = streamBody.streamId;
|
|
558
|
-
var streamType = streamBody.type || StreamTypeConstant.DATA;
|
|
559
|
-
var streamMode = streamBody.mode;
|
|
560
|
-
var streamChunked = (_streamBody$chunked = streamBody.chunked) !== null && _streamBody$chunked !== void 0 ? _streamBody$chunked : true;
|
|
561
|
-
var streamMetadata = streamBody.metadata;
|
|
562
|
-
var autoResolve = (_streamBody$autoResol = streamBody.autoResolve) !== null && _streamBody$autoResol !== void 0 ? _streamBody$autoResol : false;
|
|
563
|
-
|
|
564
|
-
// Create corresponding readable stream based on stream type
|
|
565
|
-
if (streamType === StreamTypeConstant.FILE) {
|
|
566
|
-
var _readableStream = new IframeFileReadableStream(streamId, requestId, this, {
|
|
567
|
-
chunked: streamChunked,
|
|
568
|
-
metadata: streamMetadata,
|
|
569
|
-
secretKey: this.secretKey,
|
|
570
|
-
idleTimeout: streamTimeout,
|
|
571
|
-
heartbeat: () => this.isConnect(),
|
|
572
|
-
mode: streamMode,
|
|
573
|
-
filename: streamMetadata === null || streamMetadata === void 0 ? void 0 : streamMetadata.filename,
|
|
574
|
-
mimeType: streamMetadata === null || streamMetadata === void 0 ? void 0 : streamMetadata.mimeType,
|
|
575
|
-
size: streamMetadata === null || streamMetadata === void 0 ? void 0 : streamMetadata.size
|
|
576
|
-
});
|
|
577
|
-
|
|
578
|
-
// If autoResolve is enabled, automatically read and convert to File/Blob
|
|
579
|
-
if (autoResolve) {
|
|
580
|
-
var _data$headers;
|
|
581
|
-
// Extract fileName from headers if available
|
|
582
|
-
var contentDisposition = (_data$headers = data.headers) === null || _data$headers === void 0 ? void 0 : _data$headers[HttpHeader.CONTENT_DISPOSITION];
|
|
583
|
-
var fileName;
|
|
584
|
-
if (contentDisposition) {
|
|
585
|
-
var disposition = typeof contentDisposition === 'string' ? contentDisposition : contentDisposition[0];
|
|
586
|
-
var filenameMatch = disposition.match(/filename="?([^"]+)"?/i);
|
|
587
|
-
if (filenameMatch) {
|
|
588
|
-
fileName = filenameMatch[1];
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
// Fallback to stream metadata if not found in headers
|
|
592
|
-
fileName = fileName || (streamMetadata === null || streamMetadata === void 0 ? void 0 : streamMetadata.filename) || _readableStream.filename;
|
|
593
523
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
524
|
+
// Remember server's creatorId as target server ID for future requests
|
|
525
|
+
this.rememberTargetServerId(data.creatorId);
|
|
526
|
+
var created = createReadableStreamFromStart({
|
|
527
|
+
requestId,
|
|
528
|
+
data,
|
|
529
|
+
handler: this,
|
|
530
|
+
secretKey: this.secretKey,
|
|
531
|
+
idleTimeout: streamTimeout,
|
|
532
|
+
heartbeat: () => this.isConnect()
|
|
533
|
+
});
|
|
534
|
+
if (!created) {
|
|
535
|
+
fail(new RequestIframeError({
|
|
536
|
+
message: formatMessage(Messages.STREAM_ERROR, 'invalid stream_start'),
|
|
537
|
+
code: ErrorCode.STREAM_ERROR,
|
|
538
|
+
config: processedConfig,
|
|
539
|
+
requestId
|
|
540
|
+
}));
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
var readableStream = created.stream,
|
|
544
|
+
info = created.info;
|
|
545
|
+
|
|
546
|
+
// File stream: optional auto-resolve to File/Blob
|
|
547
|
+
if (info.type === StreamTypeConstant.FILE) {
|
|
548
|
+
var fileStream = readableStream;
|
|
549
|
+
if (info.autoResolve) {
|
|
550
|
+
autoResolveIframeFileReadableStream({
|
|
551
|
+
fileStream,
|
|
552
|
+
info,
|
|
553
|
+
headers: data.headers
|
|
554
|
+
}).then(fileData => {
|
|
597
555
|
var resp = {
|
|
598
556
|
data: fileData,
|
|
599
557
|
status: data.status || HttpStatus.OK,
|
|
@@ -607,32 +565,7 @@ export class RequestIframeClientImpl {
|
|
|
607
565
|
}).catch(reject);
|
|
608
566
|
return;
|
|
609
567
|
}
|
|
610
|
-
|
|
611
|
-
// Non-autoResolve: return file stream directly
|
|
612
|
-
var _resp = {
|
|
613
|
-
data: undefined,
|
|
614
|
-
status: data.status || HttpStatus.OK,
|
|
615
|
-
statusText: data.statusText || HttpStatusText[HttpStatus.OK],
|
|
616
|
-
requestId,
|
|
617
|
-
headers: data.headers,
|
|
618
|
-
stream: _readableStream
|
|
619
|
-
};
|
|
620
|
-
runResponseInterceptors(this.interceptors.response, _resp).then(response => {
|
|
621
|
-
resolve(returnData ? response.data : response);
|
|
622
|
-
}).catch(reject);
|
|
623
|
-
return;
|
|
624
568
|
}
|
|
625
|
-
|
|
626
|
-
// Non-file stream: create regular readable stream
|
|
627
|
-
var readableStream = new IframeReadableStream(streamId, requestId, this, {
|
|
628
|
-
type: streamType,
|
|
629
|
-
mode: streamMode,
|
|
630
|
-
chunked: streamChunked,
|
|
631
|
-
metadata: streamMetadata,
|
|
632
|
-
secretKey: this.secretKey,
|
|
633
|
-
idleTimeout: streamTimeout,
|
|
634
|
-
heartbeat: () => this.isConnect()
|
|
635
|
-
});
|
|
636
569
|
var resp = {
|
|
637
570
|
data: undefined,
|
|
638
571
|
status: data.status || HttpStatus.OK,
|
|
@@ -647,21 +580,13 @@ export class RequestIframeClientImpl {
|
|
|
647
580
|
return;
|
|
648
581
|
}
|
|
649
582
|
|
|
650
|
-
// Received stream data/end/error/cancel message - dispatch to stream handler
|
|
651
|
-
if (data.type.startsWith('stream_')) {
|
|
652
|
-
this.dispatchStreamMessage(data);
|
|
653
|
-
return;
|
|
654
|
-
}
|
|
655
|
-
|
|
656
583
|
// Received response
|
|
657
584
|
if (data.type === MessageType.RESPONSE) {
|
|
658
585
|
done = true;
|
|
659
586
|
cleanup();
|
|
660
587
|
|
|
661
588
|
// Remember server's creatorId as target server ID for future requests
|
|
662
|
-
|
|
663
|
-
this._targetServerId = data.creatorId;
|
|
664
|
-
}
|
|
589
|
+
this.rememberTargetServerId(data.creatorId);
|
|
665
590
|
|
|
666
591
|
// Parse and save server-set cookies (from Set-Cookie header)
|
|
667
592
|
if (data.headers && data.headers[HttpHeader.SET_COOKIE]) {
|
|
@@ -680,14 +605,14 @@ export class RequestIframeClientImpl {
|
|
|
680
605
|
_iterator.f();
|
|
681
606
|
}
|
|
682
607
|
}
|
|
683
|
-
var
|
|
608
|
+
var _resp = {
|
|
684
609
|
data: data.data,
|
|
685
610
|
status: data.status || HttpStatus.OK,
|
|
686
611
|
statusText: data.statusText || HttpStatusText[HttpStatus.OK],
|
|
687
612
|
requestId,
|
|
688
613
|
headers: data.headers
|
|
689
614
|
};
|
|
690
|
-
runResponseInterceptors(this.interceptors.response,
|
|
615
|
+
runResponseInterceptors(this.interceptors.response, _resp).then(response => {
|
|
691
616
|
resolve(returnData ? response.data : response);
|
|
692
617
|
}).catch(reject);
|
|
693
618
|
return;
|
|
@@ -697,9 +622,7 @@ export class RequestIframeClientImpl {
|
|
|
697
622
|
if (data.type === MessageType.ERROR) {
|
|
698
623
|
var _data$error, _data$error2;
|
|
699
624
|
// Remember server's creatorId as target server ID for future requests
|
|
700
|
-
|
|
701
|
-
this._targetServerId = data.creatorId;
|
|
702
|
-
}
|
|
625
|
+
this.rememberTargetServerId(data.creatorId);
|
|
703
626
|
fail(new RequestIframeError({
|
|
704
627
|
message: ((_data$error = data.error) === null || _data$error === void 0 ? void 0 : _data$error.message) || Messages.REQUEST_FAILED,
|
|
705
628
|
code: ((_data$error2 = data.error) === null || _data$error2 === void 0 ? void 0 : _data$error2.code) || ErrorCode.REQUEST_ERROR,
|
|
@@ -740,7 +663,7 @@ export class RequestIframeClientImpl {
|
|
|
740
663
|
cookies: mergedCookies,
|
|
741
664
|
targetId,
|
|
742
665
|
requireAck,
|
|
743
|
-
|
|
666
|
+
ack
|
|
744
667
|
};
|
|
745
668
|
if (extraPayload !== null && extraPayload !== void 0 && extraPayload.streamId) {
|
|
746
669
|
payload.streamId = extraPayload.streamId;
|
|
@@ -756,21 +679,21 @@ export class RequestIframeClientImpl {
|
|
|
756
679
|
}));
|
|
757
680
|
return;
|
|
758
681
|
}
|
|
759
|
-
this.
|
|
682
|
+
this.outbox.sendMessage(MessageType.REQUEST, requestId, payload);
|
|
760
683
|
});
|
|
761
684
|
}
|
|
762
685
|
/**
|
|
763
|
-
* Get internal
|
|
686
|
+
* Get internal hub instance (for debugging)
|
|
764
687
|
*/
|
|
765
|
-
|
|
766
|
-
return this.
|
|
688
|
+
getHub() {
|
|
689
|
+
return this.hub;
|
|
767
690
|
}
|
|
768
691
|
|
|
769
692
|
/**
|
|
770
693
|
* Whether message handling is enabled
|
|
771
694
|
*/
|
|
772
695
|
get isOpen() {
|
|
773
|
-
return this.
|
|
696
|
+
return this.hub.isOpen;
|
|
774
697
|
}
|
|
775
698
|
|
|
776
699
|
/**
|
|
@@ -785,14 +708,14 @@ export class RequestIframeClientImpl {
|
|
|
785
708
|
* Enable message handling (register message handlers)
|
|
786
709
|
*/
|
|
787
710
|
open() {
|
|
788
|
-
this.
|
|
711
|
+
this.hub.open();
|
|
789
712
|
}
|
|
790
713
|
|
|
791
714
|
/**
|
|
792
715
|
* Disable message handling (unregister message handlers, but don't release resources)
|
|
793
716
|
*/
|
|
794
717
|
close() {
|
|
795
|
-
this.
|
|
718
|
+
this.hub.close();
|
|
796
719
|
}
|
|
797
720
|
|
|
798
721
|
/**
|
|
@@ -803,14 +726,14 @@ export class RequestIframeClientImpl {
|
|
|
803
726
|
this._cookieStore.clear();
|
|
804
727
|
|
|
805
728
|
// Clear stream handlers
|
|
806
|
-
this.
|
|
729
|
+
this.streamDispatcher.clear();
|
|
807
730
|
|
|
808
731
|
// Clear interceptors
|
|
809
732
|
this.interceptors.request.clear();
|
|
810
733
|
this.interceptors.response.clear();
|
|
811
734
|
|
|
812
|
-
// Destroy
|
|
813
|
-
this.
|
|
735
|
+
// Destroy core (this will also release the message channel)
|
|
736
|
+
this.hub.destroy();
|
|
814
737
|
}
|
|
815
738
|
|
|
816
739
|
/**
|