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,149 @@
|
|
|
1
|
+
import type { PostMessageData } from '../../types';
|
|
2
|
+
import { MessageDispatcher } from '../../message';
|
|
3
|
+
import type { IIframeWritableStream, StreamBindContext, StreamMessageData } from '../../stream/types';
|
|
4
|
+
import { SyncHook } from '../../utils/hooks';
|
|
5
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
6
|
+
/**
|
|
7
|
+
* Outbox hooks for send pipelines.
|
|
8
|
+
*/
|
|
9
|
+
export interface RequestIframeOutboxSendHooks<TResult> {
|
|
10
|
+
/**
|
|
11
|
+
* Runs before the actual operation.
|
|
12
|
+
*/
|
|
13
|
+
before?: () => MaybePromise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Runs on success (before finally).
|
|
16
|
+
*/
|
|
17
|
+
end?: (result: TResult) => MaybePromise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Runs on error.
|
|
20
|
+
* - If provided, its return value becomes the final result (and the error is swallowed).
|
|
21
|
+
* - If not provided, error will be thrown.
|
|
22
|
+
*/
|
|
23
|
+
error?: (err: any) => MaybePromise<TResult>;
|
|
24
|
+
/**
|
|
25
|
+
* Runs in finally (always).
|
|
26
|
+
*/
|
|
27
|
+
finally?: () => MaybePromise<void>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Stream send pipeline params.
|
|
31
|
+
*/
|
|
32
|
+
export interface RequestIframeOutboxSendStreamParams<TResult> extends RequestIframeOutboxSendHooks<TResult> {
|
|
33
|
+
stream: IIframeWritableStream;
|
|
34
|
+
bind: Parameters<RequestIframeEndpointOutbox['createStreamBindContext']>[0];
|
|
35
|
+
/**
|
|
36
|
+
* Default true. If false, stream.start() will be triggered but not awaited.
|
|
37
|
+
* (Used by client request-body streams: REQUEST must be sent first.)
|
|
38
|
+
*/
|
|
39
|
+
awaitStart?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Hook before start. Return value becomes sendStream's result.
|
|
42
|
+
* (Client uses it to send REQUEST and return the pending response promise.)
|
|
43
|
+
*/
|
|
44
|
+
beforeStart?: (ctx: {
|
|
45
|
+
stream: IIframeWritableStream;
|
|
46
|
+
}) => MaybePromise<TResult>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* File send pipeline params.
|
|
50
|
+
*/
|
|
51
|
+
export interface RequestIframeOutboxSendFileParams<TResult> extends RequestIframeOutboxSendHooks<TResult> {
|
|
52
|
+
content: string | Blob | File;
|
|
53
|
+
fileName?: string;
|
|
54
|
+
mimeType?: string;
|
|
55
|
+
chunked?: boolean;
|
|
56
|
+
autoResolve?: boolean;
|
|
57
|
+
defaultFileName?: string;
|
|
58
|
+
defaultMimeType?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Called after file stream is created (before stream start).
|
|
61
|
+
* Useful for response to set headers based on inferred fileName/mimeType.
|
|
62
|
+
*/
|
|
63
|
+
onFileInfo?: (info: {
|
|
64
|
+
fileName?: string;
|
|
65
|
+
mimeType: string;
|
|
66
|
+
}) => MaybePromise<void>;
|
|
67
|
+
stream: Omit<RequestIframeOutboxSendStreamParams<TResult>, 'stream'>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Universal send pipeline params.
|
|
71
|
+
*/
|
|
72
|
+
export interface RequestIframeOutboxSendParams<TResult> extends RequestIframeOutboxSendHooks<TResult> {
|
|
73
|
+
data: any;
|
|
74
|
+
onOther: (data: any) => MaybePromise<TResult>;
|
|
75
|
+
onStream?: (stream: IIframeWritableStream) => MaybePromise<TResult>;
|
|
76
|
+
onFileOrBlob?: (fileOrBlob: Blob | File) => MaybePromise<TResult>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* RequestIframeEndpointOutbox
|
|
80
|
+
*
|
|
81
|
+
* A lightweight "built-in sender" bound to a fixed peer (targetWindow/targetOrigin).
|
|
82
|
+
* Used by request/response-side objects to send messages without repeatedly passing
|
|
83
|
+
* targetWindow/targetOrigin.
|
|
84
|
+
*/
|
|
85
|
+
export declare class RequestIframeEndpointOutbox {
|
|
86
|
+
readonly hooks: {
|
|
87
|
+
beforeSendRaw: SyncHook<[message: PostMessageData]>;
|
|
88
|
+
afterSendRaw: SyncHook<[message: PostMessageData, ok: boolean]>;
|
|
89
|
+
sendRawError: SyncHook<[message: PostMessageData, error: any]>;
|
|
90
|
+
beforeSendMessage: SyncHook<[type: "error" | "request" | "ack" | "async" | "response" | "ping" | "pong" | "stream_start" | "stream_data" | "stream_end" | "stream_error" | "stream_cancel" | "stream_pull", requestId: string, payload: any]>;
|
|
91
|
+
afterSendMessage: SyncHook<[type: "error" | "request" | "ack" | "async" | "response" | "ping" | "pong" | "stream_start" | "stream_data" | "stream_end" | "stream_error" | "stream_cancel" | "stream_pull", requestId: string, payload: any, ok: boolean]>;
|
|
92
|
+
sendMessageError: SyncHook<[type: "error" | "request" | "ack" | "async" | "response" | "ping" | "pong" | "stream_start" | "stream_data" | "stream_end" | "stream_error" | "stream_cancel" | "stream_pull", requestId: string, payload: any, error: any]>;
|
|
93
|
+
};
|
|
94
|
+
readonly dispatcher: MessageDispatcher;
|
|
95
|
+
readonly targetWindow: Window;
|
|
96
|
+
readonly targetOrigin: string;
|
|
97
|
+
defaultTargetId?: string;
|
|
98
|
+
constructor(dispatcher: MessageDispatcher, targetWindow: Window, targetOrigin: string, defaultTargetId?: string);
|
|
99
|
+
setDefaultTargetId(targetId?: string): void;
|
|
100
|
+
get secretKey(): string | undefined;
|
|
101
|
+
get channel(): import("../../message").MessageChannel;
|
|
102
|
+
private runWithHooks;
|
|
103
|
+
/**
|
|
104
|
+
* Create a stream bind context using this peer's fixed target info.
|
|
105
|
+
*
|
|
106
|
+
* This helps unify the duplicated `_bind({ targetWindow, targetOrigin, secretKey, channel, ... })` logic
|
|
107
|
+
* across client/server response implementations.
|
|
108
|
+
*/
|
|
109
|
+
createStreamBindContext(params: {
|
|
110
|
+
requestId: string;
|
|
111
|
+
registerStreamHandler?: (streamId: string, handler: (data: StreamMessageData) => void) => void;
|
|
112
|
+
unregisterStreamHandler?: (streamId: string) => void;
|
|
113
|
+
heartbeat?: () => Promise<boolean>;
|
|
114
|
+
serverId?: string;
|
|
115
|
+
clientId?: string;
|
|
116
|
+
targetId?: string;
|
|
117
|
+
}): StreamBindContext;
|
|
118
|
+
/**
|
|
119
|
+
* Bind and start a writable stream to this peer.
|
|
120
|
+
*
|
|
121
|
+
* Note:
|
|
122
|
+
* - Client-side request-body streams may need to delay `start()` until after REQUEST is sent.
|
|
123
|
+
* For that case, prefer `createStreamBindContext()` + manual `stream.start()`.
|
|
124
|
+
*/
|
|
125
|
+
sendWritableStream(stream: IIframeWritableStream, params: Parameters<RequestIframeEndpointOutbox['createStreamBindContext']>[0]): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Universal send - dispatch by data type, then call hooks to implement differences.
|
|
128
|
+
*/
|
|
129
|
+
send<TResult>(params: RequestIframeOutboxSendParams<TResult>): Promise<TResult>;
|
|
130
|
+
private runStreamSend;
|
|
131
|
+
/**
|
|
132
|
+
* Send writable stream via peer.
|
|
133
|
+
*/
|
|
134
|
+
sendStream<TResult = void>(params: RequestIframeOutboxSendStreamParams<TResult>): Promise<TResult>;
|
|
135
|
+
/**
|
|
136
|
+
* Send File/Blob/string as a file stream via peer.
|
|
137
|
+
*/
|
|
138
|
+
sendFile<TResult>(params: RequestIframeOutboxSendFileParams<TResult>): Promise<TResult>;
|
|
139
|
+
/**
|
|
140
|
+
* Send typed message with peer pre-bound.
|
|
141
|
+
*/
|
|
142
|
+
sendMessage(type: PostMessageData['type'], requestId: string, data?: Partial<Omit<PostMessageData, '__requestIframe__' | 'type' | 'requestId' | 'timestamp' | 'role' | 'creatorId'>>): boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Send raw message with peer pre-bound.
|
|
145
|
+
*/
|
|
146
|
+
sendRaw(message: PostMessageData): boolean;
|
|
147
|
+
}
|
|
148
|
+
export {};
|
|
149
|
+
//# sourceMappingURL=outbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outbox.d.ts","sourceRoot":"","sources":["../../../src/endpoint/infra/outbox.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.array.filter.js");
|
|
4
|
+
require("core-js/modules/es.object.get-own-property-descriptors.js");
|
|
5
|
+
require("core-js/modules/web.dom-collections.for-each.js");
|
|
6
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.RequestIframeEndpointOutbox = void 0;
|
|
11
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
12
|
+
require("core-js/modules/es.promise.js");
|
|
13
|
+
require("core-js/modules/es.promise.finally.js");
|
|
14
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
|
+
var _stream = require("../../stream");
|
|
17
|
+
var _fileWritable = require("../stream/file-writable");
|
|
18
|
+
var _hooks = require("../../utils/hooks");
|
|
19
|
+
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; }
|
|
20
|
+
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) { (0, _defineProperty2.default)(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; }
|
|
21
|
+
/**
|
|
22
|
+
* Outbox hooks for send pipelines.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Stream send pipeline params.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* File send pipeline params.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Universal send pipeline params.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
function safeIsFile(data) {
|
|
38
|
+
try {
|
|
39
|
+
return typeof File !== 'undefined' && data instanceof File;
|
|
40
|
+
} catch (_unused) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function safeIsBlob(data) {
|
|
45
|
+
try {
|
|
46
|
+
return typeof Blob !== 'undefined' && data instanceof Blob;
|
|
47
|
+
} catch (_unused2) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* RequestIframeEndpointOutbox
|
|
54
|
+
*
|
|
55
|
+
* A lightweight "built-in sender" bound to a fixed peer (targetWindow/targetOrigin).
|
|
56
|
+
* Used by request/response-side objects to send messages without repeatedly passing
|
|
57
|
+
* targetWindow/targetOrigin.
|
|
58
|
+
*/
|
|
59
|
+
class RequestIframeEndpointOutbox {
|
|
60
|
+
constructor(dispatcher, targetWindow, targetOrigin, defaultTargetId) {
|
|
61
|
+
(0, _defineProperty2.default)(this, "hooks", {
|
|
62
|
+
beforeSendRaw: new _hooks.SyncHook(),
|
|
63
|
+
afterSendRaw: new _hooks.SyncHook(),
|
|
64
|
+
sendRawError: new _hooks.SyncHook(),
|
|
65
|
+
beforeSendMessage: new _hooks.SyncHook(),
|
|
66
|
+
afterSendMessage: new _hooks.SyncHook(),
|
|
67
|
+
sendMessageError: new _hooks.SyncHook()
|
|
68
|
+
});
|
|
69
|
+
this.dispatcher = dispatcher;
|
|
70
|
+
this.targetWindow = targetWindow;
|
|
71
|
+
this.targetOrigin = targetOrigin;
|
|
72
|
+
this.defaultTargetId = defaultTargetId;
|
|
73
|
+
}
|
|
74
|
+
setDefaultTargetId(targetId) {
|
|
75
|
+
this.defaultTargetId = targetId;
|
|
76
|
+
}
|
|
77
|
+
get secretKey() {
|
|
78
|
+
return this.dispatcher.secretKey;
|
|
79
|
+
}
|
|
80
|
+
get channel() {
|
|
81
|
+
return this.dispatcher.getChannel();
|
|
82
|
+
}
|
|
83
|
+
runWithHooks(hooks, fn) {
|
|
84
|
+
return (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
85
|
+
var result, _t;
|
|
86
|
+
return _regenerator.default.wrap(function (_context) {
|
|
87
|
+
while (1) switch (_context.prev = _context.next) {
|
|
88
|
+
case 0:
|
|
89
|
+
_context.prev = 0;
|
|
90
|
+
if (!hooks.before) {
|
|
91
|
+
_context.next = 1;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
_context.next = 1;
|
|
95
|
+
return hooks.before();
|
|
96
|
+
case 1:
|
|
97
|
+
_context.next = 2;
|
|
98
|
+
return fn();
|
|
99
|
+
case 2:
|
|
100
|
+
result = _context.sent;
|
|
101
|
+
if (!hooks.end) {
|
|
102
|
+
_context.next = 3;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
_context.next = 3;
|
|
106
|
+
return hooks.end(result);
|
|
107
|
+
case 3:
|
|
108
|
+
return _context.abrupt("return", result);
|
|
109
|
+
case 4:
|
|
110
|
+
_context.prev = 4;
|
|
111
|
+
_t = _context["catch"](0);
|
|
112
|
+
if (!hooks.error) {
|
|
113
|
+
_context.next = 6;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
_context.next = 5;
|
|
117
|
+
return hooks.error(_t);
|
|
118
|
+
case 5:
|
|
119
|
+
return _context.abrupt("return", _context.sent);
|
|
120
|
+
case 6:
|
|
121
|
+
throw _t;
|
|
122
|
+
case 7:
|
|
123
|
+
_context.prev = 7;
|
|
124
|
+
if (!hooks.finally) {
|
|
125
|
+
_context.next = 8;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
_context.next = 8;
|
|
129
|
+
return hooks.finally();
|
|
130
|
+
case 8:
|
|
131
|
+
return _context.finish(7);
|
|
132
|
+
case 9:
|
|
133
|
+
case "end":
|
|
134
|
+
return _context.stop();
|
|
135
|
+
}
|
|
136
|
+
}, _callee, null, [[0, 4, 7, 9]]);
|
|
137
|
+
}))();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Create a stream bind context using this peer's fixed target info.
|
|
142
|
+
*
|
|
143
|
+
* This helps unify the duplicated `_bind({ targetWindow, targetOrigin, secretKey, channel, ... })` logic
|
|
144
|
+
* across client/server response implementations.
|
|
145
|
+
*/
|
|
146
|
+
createStreamBindContext(params) {
|
|
147
|
+
var _params$targetId;
|
|
148
|
+
return {
|
|
149
|
+
requestId: params.requestId,
|
|
150
|
+
targetWindow: this.targetWindow,
|
|
151
|
+
targetOrigin: this.targetOrigin,
|
|
152
|
+
secretKey: this.secretKey,
|
|
153
|
+
channel: this.channel,
|
|
154
|
+
registerStreamHandler: params.registerStreamHandler,
|
|
155
|
+
unregisterStreamHandler: params.unregisterStreamHandler,
|
|
156
|
+
heartbeat: params.heartbeat,
|
|
157
|
+
serverId: params.serverId,
|
|
158
|
+
clientId: params.clientId,
|
|
159
|
+
targetId: (_params$targetId = params.targetId) !== null && _params$targetId !== void 0 ? _params$targetId : this.defaultTargetId
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Bind and start a writable stream to this peer.
|
|
165
|
+
*
|
|
166
|
+
* Note:
|
|
167
|
+
* - Client-side request-body streams may need to delay `start()` until after REQUEST is sent.
|
|
168
|
+
* For that case, prefer `createStreamBindContext()` + manual `stream.start()`.
|
|
169
|
+
*/
|
|
170
|
+
sendWritableStream(stream, params) {
|
|
171
|
+
var _this = this;
|
|
172
|
+
return (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2() {
|
|
173
|
+
return _regenerator.default.wrap(function (_context2) {
|
|
174
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
175
|
+
case 0:
|
|
176
|
+
stream._bind(_this.createStreamBindContext(params));
|
|
177
|
+
_context2.next = 1;
|
|
178
|
+
return stream.start();
|
|
179
|
+
case 1:
|
|
180
|
+
case "end":
|
|
181
|
+
return _context2.stop();
|
|
182
|
+
}
|
|
183
|
+
}, _callee2);
|
|
184
|
+
}))();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Universal send - dispatch by data type, then call hooks to implement differences.
|
|
189
|
+
*/
|
|
190
|
+
send(params) {
|
|
191
|
+
var _this2 = this;
|
|
192
|
+
return (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee4() {
|
|
193
|
+
return _regenerator.default.wrap(function (_context4) {
|
|
194
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
195
|
+
case 0:
|
|
196
|
+
return _context4.abrupt("return", _this2.runWithHooks(params, /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee3() {
|
|
197
|
+
var data;
|
|
198
|
+
return _regenerator.default.wrap(function (_context3) {
|
|
199
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
200
|
+
case 0:
|
|
201
|
+
data = params.data;
|
|
202
|
+
if (!(0, _stream.isIframeWritableStream)(data)) {
|
|
203
|
+
_context3.next = 4;
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
if (!params.onStream) {
|
|
207
|
+
_context3.next = 2;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
_context3.next = 1;
|
|
211
|
+
return params.onStream(data);
|
|
212
|
+
case 1:
|
|
213
|
+
return _context3.abrupt("return", _context3.sent);
|
|
214
|
+
case 2:
|
|
215
|
+
_context3.next = 3;
|
|
216
|
+
return params.onOther(data);
|
|
217
|
+
case 3:
|
|
218
|
+
return _context3.abrupt("return", _context3.sent);
|
|
219
|
+
case 4:
|
|
220
|
+
if (!(safeIsFile(data) || safeIsBlob(data))) {
|
|
221
|
+
_context3.next = 8;
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
if (!params.onFileOrBlob) {
|
|
225
|
+
_context3.next = 6;
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
_context3.next = 5;
|
|
229
|
+
return params.onFileOrBlob(data);
|
|
230
|
+
case 5:
|
|
231
|
+
return _context3.abrupt("return", _context3.sent);
|
|
232
|
+
case 6:
|
|
233
|
+
_context3.next = 7;
|
|
234
|
+
return params.onOther(data);
|
|
235
|
+
case 7:
|
|
236
|
+
return _context3.abrupt("return", _context3.sent);
|
|
237
|
+
case 8:
|
|
238
|
+
_context3.next = 9;
|
|
239
|
+
return params.onOther(data);
|
|
240
|
+
case 9:
|
|
241
|
+
return _context3.abrupt("return", _context3.sent);
|
|
242
|
+
case 10:
|
|
243
|
+
case "end":
|
|
244
|
+
return _context3.stop();
|
|
245
|
+
}
|
|
246
|
+
}, _callee3);
|
|
247
|
+
}))));
|
|
248
|
+
case 1:
|
|
249
|
+
case "end":
|
|
250
|
+
return _context4.stop();
|
|
251
|
+
}
|
|
252
|
+
}, _callee4);
|
|
253
|
+
}))();
|
|
254
|
+
}
|
|
255
|
+
runStreamSend(params) {
|
|
256
|
+
var _this3 = this;
|
|
257
|
+
return (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee5() {
|
|
258
|
+
var resultPromise, result;
|
|
259
|
+
return _regenerator.default.wrap(function (_context5) {
|
|
260
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
261
|
+
case 0:
|
|
262
|
+
params.stream._bind(_this3.createStreamBindContext(params.bind));
|
|
263
|
+
resultPromise = params.beforeStart ? params.beforeStart({
|
|
264
|
+
stream: params.stream
|
|
265
|
+
}) : undefined;
|
|
266
|
+
if (!(params.awaitStart === false)) {
|
|
267
|
+
_context5.next = 2;
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Fire-and-forget:
|
|
272
|
+
* - request-body stream must start after REQUEST is sent (beforeStart is expected to send REQUEST synchronously)
|
|
273
|
+
* - we must NOT await the response promise before starting stream, otherwise server will time out waiting stream_start
|
|
274
|
+
*/
|
|
275
|
+
void params.stream.start();
|
|
276
|
+
_context5.next = 1;
|
|
277
|
+
return resultPromise;
|
|
278
|
+
case 1:
|
|
279
|
+
return _context5.abrupt("return", _context5.sent);
|
|
280
|
+
case 2:
|
|
281
|
+
_context5.next = 3;
|
|
282
|
+
return resultPromise;
|
|
283
|
+
case 3:
|
|
284
|
+
result = _context5.sent;
|
|
285
|
+
_context5.next = 4;
|
|
286
|
+
return params.stream.start();
|
|
287
|
+
case 4:
|
|
288
|
+
return _context5.abrupt("return", result);
|
|
289
|
+
case 5:
|
|
290
|
+
case "end":
|
|
291
|
+
return _context5.stop();
|
|
292
|
+
}
|
|
293
|
+
}, _callee5);
|
|
294
|
+
}))();
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Send writable stream via peer.
|
|
299
|
+
*/
|
|
300
|
+
sendStream(params) {
|
|
301
|
+
var _this4 = this;
|
|
302
|
+
return (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee7() {
|
|
303
|
+
return _regenerator.default.wrap(function (_context7) {
|
|
304
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
305
|
+
case 0:
|
|
306
|
+
return _context7.abrupt("return", _this4.runWithHooks(params, /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee6() {
|
|
307
|
+
return _regenerator.default.wrap(function (_context6) {
|
|
308
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
309
|
+
case 0:
|
|
310
|
+
_context6.next = 1;
|
|
311
|
+
return _this4.runStreamSend(params);
|
|
312
|
+
case 1:
|
|
313
|
+
return _context6.abrupt("return", _context6.sent);
|
|
314
|
+
case 2:
|
|
315
|
+
case "end":
|
|
316
|
+
return _context6.stop();
|
|
317
|
+
}
|
|
318
|
+
}, _callee6);
|
|
319
|
+
}))));
|
|
320
|
+
case 1:
|
|
321
|
+
case "end":
|
|
322
|
+
return _context7.stop();
|
|
323
|
+
}
|
|
324
|
+
}, _callee7);
|
|
325
|
+
}))();
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Send File/Blob/string as a file stream via peer.
|
|
330
|
+
*/
|
|
331
|
+
sendFile(params) {
|
|
332
|
+
var _this5 = this;
|
|
333
|
+
return (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee9() {
|
|
334
|
+
return _regenerator.default.wrap(function (_context9) {
|
|
335
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
336
|
+
case 0:
|
|
337
|
+
return _context9.abrupt("return", _this5.runWithHooks(params, /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee8() {
|
|
338
|
+
var _params$onFileInfo;
|
|
339
|
+
var created;
|
|
340
|
+
return _regenerator.default.wrap(function (_context8) {
|
|
341
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
342
|
+
case 0:
|
|
343
|
+
_context8.next = 1;
|
|
344
|
+
return (0, _fileWritable.createIframeFileWritableStreamFromContent)({
|
|
345
|
+
content: params.content,
|
|
346
|
+
fileName: params.fileName,
|
|
347
|
+
mimeType: params.mimeType,
|
|
348
|
+
chunked: params.chunked,
|
|
349
|
+
autoResolve: params.autoResolve,
|
|
350
|
+
defaultFileName: params.defaultFileName,
|
|
351
|
+
defaultMimeType: params.defaultMimeType
|
|
352
|
+
});
|
|
353
|
+
case 1:
|
|
354
|
+
created = _context8.sent;
|
|
355
|
+
_context8.next = 2;
|
|
356
|
+
return (_params$onFileInfo = params.onFileInfo) === null || _params$onFileInfo === void 0 ? void 0 : _params$onFileInfo.call(params, {
|
|
357
|
+
fileName: created.fileName,
|
|
358
|
+
mimeType: created.mimeType
|
|
359
|
+
});
|
|
360
|
+
case 2:
|
|
361
|
+
_context8.next = 3;
|
|
362
|
+
return _this5.runStreamSend(_objectSpread(_objectSpread({}, params.stream), {}, {
|
|
363
|
+
stream: created.stream
|
|
364
|
+
}));
|
|
365
|
+
case 3:
|
|
366
|
+
return _context8.abrupt("return", _context8.sent);
|
|
367
|
+
case 4:
|
|
368
|
+
case "end":
|
|
369
|
+
return _context8.stop();
|
|
370
|
+
}
|
|
371
|
+
}, _callee8);
|
|
372
|
+
}))));
|
|
373
|
+
case 1:
|
|
374
|
+
case "end":
|
|
375
|
+
return _context9.stop();
|
|
376
|
+
}
|
|
377
|
+
}, _callee9);
|
|
378
|
+
}))();
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Send typed message with peer pre-bound.
|
|
383
|
+
*/
|
|
384
|
+
sendMessage(type, requestId, data) {
|
|
385
|
+
var payload = _objectSpread({}, data || {});
|
|
386
|
+
if (payload.targetId === undefined && this.defaultTargetId !== undefined) {
|
|
387
|
+
payload.targetId = this.defaultTargetId;
|
|
388
|
+
}
|
|
389
|
+
this.hooks.beforeSendMessage.call(type, requestId, payload);
|
|
390
|
+
try {
|
|
391
|
+
var _ok = this.dispatcher.sendMessage(this.targetWindow, this.targetOrigin, type, requestId, payload);
|
|
392
|
+
this.hooks.afterSendMessage.call(type, requestId, payload, _ok);
|
|
393
|
+
return _ok;
|
|
394
|
+
} catch (e) {
|
|
395
|
+
this.hooks.sendMessageError.call(type, requestId, payload, e);
|
|
396
|
+
throw e;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Send raw message with peer pre-bound.
|
|
402
|
+
*/
|
|
403
|
+
sendRaw(message) {
|
|
404
|
+
this.hooks.beforeSendRaw.call(message);
|
|
405
|
+
try {
|
|
406
|
+
var _ok2 = this.dispatcher.send(this.targetWindow, message, this.targetOrigin);
|
|
407
|
+
this.hooks.afterSendRaw.call(message, _ok2);
|
|
408
|
+
return _ok2;
|
|
409
|
+
} catch (e) {
|
|
410
|
+
this.hooks.sendRawError.call(message, e);
|
|
411
|
+
throw e;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
exports.RequestIframeEndpointOutbox = RequestIframeEndpointOutbox;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { PostMessageData } from '../../types';
|
|
2
|
+
import type { MessageContext } from '../../message';
|
|
3
|
+
import type { StreamMessageData } from '../../stream';
|
|
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
|
+
* - Demultiplex `stream_*` frames by streamId to the bound handler
|
|
9
|
+
* - Does NOT implement the stream protocol itself (protocol lives in `src/stream`)
|
|
10
|
+
*
|
|
11
|
+
* RequestIframeStreamDispatcher
|
|
12
|
+
*
|
|
13
|
+
* - Maintains streamId -> handler mapping
|
|
14
|
+
* - Dispatches incoming `stream_*` PostMessageData to the mapped handler
|
|
15
|
+
*/
|
|
16
|
+
export declare class RequestIframeStreamDispatcher {
|
|
17
|
+
private readonly handledBy;
|
|
18
|
+
private readonly handlers;
|
|
19
|
+
constructor(params: {
|
|
20
|
+
handledBy: string;
|
|
21
|
+
});
|
|
22
|
+
register(streamId: string, handler: (data: StreamMessageData) => void): void;
|
|
23
|
+
unregister(streamId: string): void;
|
|
24
|
+
clear(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Dispatch a framework stream_* PostMessageData to its streamId handler.
|
|
27
|
+
*
|
|
28
|
+
* - If context is provided, dispatcher will mark accepted/handledBy when handler exists.
|
|
29
|
+
* - If context is omitted, dispatcher will skip marking (useful when origin was validated upstream).
|
|
30
|
+
*/
|
|
31
|
+
dispatch(data: PostMessageData, context?: MessageContext): void;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=dispatcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../../src/endpoint/stream/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEtD;;;;;;;;;;;GAWG;AACH,qBAAa,6BAA6B;IACxC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwD;gBAE9D,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE;IAIzC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,iBAAiB,KAAK,IAAI,GAAG,IAAI;IAI5E,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIlC,KAAK,IAAI,IAAI;IAIpB;;;;;OAKG;IACI,QAAQ,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI;CAavE"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.array.filter.js");
|
|
4
|
+
require("core-js/modules/es.object.get-own-property-descriptors.js");
|
|
5
|
+
require("core-js/modules/web.dom-collections.for-each.js");
|
|
6
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.RequestIframeStreamDispatcher = void 0;
|
|
11
|
+
require("core-js/modules/es.array.iterator.js");
|
|
12
|
+
require("core-js/modules/es.map.js");
|
|
13
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
14
|
+
require("core-js/modules/es.string.replace.js");
|
|
15
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
|
+
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; }
|
|
18
|
+
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) { (0, _defineProperty2.default)(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; }
|
|
19
|
+
/**
|
|
20
|
+
* Endpoint Stream integration layer (`src/endpoint/stream`)
|
|
21
|
+
*
|
|
22
|
+
* This directory integrates postMessage `stream_*` messages with the stream object system in `src/stream`:
|
|
23
|
+
* - Demultiplex `stream_*` frames by streamId to the bound handler
|
|
24
|
+
* - Does NOT implement the stream protocol itself (protocol lives in `src/stream`)
|
|
25
|
+
*
|
|
26
|
+
* RequestIframeStreamDispatcher
|
|
27
|
+
*
|
|
28
|
+
* - Maintains streamId -> handler mapping
|
|
29
|
+
* - Dispatches incoming `stream_*` PostMessageData to the mapped handler
|
|
30
|
+
*/
|
|
31
|
+
class RequestIframeStreamDispatcher {
|
|
32
|
+
constructor(params) {
|
|
33
|
+
(0, _defineProperty2.default)(this, "handlers", new Map());
|
|
34
|
+
this.handledBy = params.handledBy;
|
|
35
|
+
}
|
|
36
|
+
register(streamId, handler) {
|
|
37
|
+
this.handlers.set(streamId, handler);
|
|
38
|
+
}
|
|
39
|
+
unregister(streamId) {
|
|
40
|
+
this.handlers.delete(streamId);
|
|
41
|
+
}
|
|
42
|
+
clear() {
|
|
43
|
+
this.handlers.clear();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Dispatch a framework stream_* PostMessageData to its streamId handler.
|
|
48
|
+
*
|
|
49
|
+
* - If context is provided, dispatcher will mark accepted/handledBy when handler exists.
|
|
50
|
+
* - If context is omitted, dispatcher will skip marking (useful when origin was validated upstream).
|
|
51
|
+
*/
|
|
52
|
+
dispatch(data, context) {
|
|
53
|
+
var body = data.body;
|
|
54
|
+
if (!(body !== null && body !== void 0 && body.streamId)) return;
|
|
55
|
+
var handler = this.handlers.get(body.streamId);
|
|
56
|
+
if (!handler) return;
|
|
57
|
+
if (context) {
|
|
58
|
+
context.markAcceptedBy(this.handledBy);
|
|
59
|
+
}
|
|
60
|
+
var messageType = data.type.replace('stream_', '');
|
|
61
|
+
handler(_objectSpread(_objectSpread({}, body), {}, {
|
|
62
|
+
type: messageType
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.RequestIframeStreamDispatcher = RequestIframeStreamDispatcher;
|