request-iframe 0.2.0 → 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/cdn/request-iframe.umd.js +26 -0
- package/cdn/request-iframe.umd.js.map +1 -1
- package/cdn/request-iframe.umd.min.js +1 -1
- package/cdn/request-iframe.umd.min.js.map +1 -1
- package/esm/message/dispatcher.js +27 -0
- package/library/message/dispatcher.d.ts.map +1 -1
- package/library/message/dispatcher.js +27 -0
- package/package.json +1 -1
|
@@ -24,6 +24,7 @@ import { isFunction } from '../utils/is';
|
|
|
24
24
|
import { getAckId, getAckMeta } from '../utils/ack';
|
|
25
25
|
import { SyncHook } from '../utils/hooks';
|
|
26
26
|
import { requestIframeLog } from '../utils/logger';
|
|
27
|
+
import { MessageContextStage } from './channel';
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Message handler function type
|
|
@@ -200,6 +201,7 @@ export class MessageDispatcher {
|
|
|
200
201
|
return;
|
|
201
202
|
}
|
|
202
203
|
}
|
|
204
|
+
var offEarlyAutoAck;
|
|
203
205
|
try {
|
|
204
206
|
this.hooks.inbound.call(data, context);
|
|
205
207
|
var _type = data.type;
|
|
@@ -223,6 +225,25 @@ export class MessageDispatcher {
|
|
|
223
225
|
autoAckState.sent = true;
|
|
224
226
|
this.tryAutoAck(data, context);
|
|
225
227
|
};
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Early auto-ack: send ACK as soon as the handler "accepts" the message.
|
|
231
|
+
*
|
|
232
|
+
* Why:
|
|
233
|
+
* - For request delivery confirmation, ACK should represent "accepted/claimed by server"
|
|
234
|
+
* instead of "handler finished".
|
|
235
|
+
* - This keeps client-side ackTimeout meaningful and avoids being delayed by business logic.
|
|
236
|
+
*
|
|
237
|
+
* Notes:
|
|
238
|
+
* - Only contexts created by MessageChannel have onStateChange; tests may provide mocks.
|
|
239
|
+
* - We keep the original end-of-dispatch maybeAutoAck() as a fallback for older/edge contexts.
|
|
240
|
+
*/
|
|
241
|
+
var onStateChangeMaybe = context.onStateChange;
|
|
242
|
+
offEarlyAutoAck = typeof onStateChangeMaybe === 'function' ? onStateChangeMaybe('autoAck:early', (_prev, next) => {
|
|
243
|
+
if (next === MessageContextStage.ACCEPTED) {
|
|
244
|
+
maybeAutoAck();
|
|
245
|
+
}
|
|
246
|
+
}) : undefined;
|
|
226
247
|
var _iterator = _createForOfIteratorHelper(this.handlers),
|
|
227
248
|
_step;
|
|
228
249
|
try {
|
|
@@ -266,6 +287,12 @@ export class MessageDispatcher {
|
|
|
266
287
|
}
|
|
267
288
|
maybeAutoAck();
|
|
268
289
|
} finally {
|
|
290
|
+
try {
|
|
291
|
+
var _offEarlyAutoAck;
|
|
292
|
+
(_offEarlyAutoAck = offEarlyAutoAck) === null || _offEarlyAutoAck === void 0 || _offEarlyAutoAck();
|
|
293
|
+
} catch (_unused) {
|
|
294
|
+
// ignore
|
|
295
|
+
}
|
|
269
296
|
/**
|
|
270
297
|
* Mark as "done" only when this dispatcher actually claimed/handled this message.
|
|
271
298
|
* - If the message was never claimed (handledBy not set), we keep `doneBy` empty so another
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/message/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,gBAAgB,EAA+B,MAAM,cAAc,CAAC;AAC3G,OAAO,EACL,eAAe,EAChB,MAAM,UAAU,CAAC;AAIlB,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/message/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,gBAAgB,EAA+B,MAAM,cAAc,CAAC;AAC3G,OAAO,EACL,eAAe,EAChB,MAAM,UAAU,CAAC;AAIlB,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,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AcV;;OAEG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIvC;;OAEG;IACI,UAAU,IAAI,cAAc;IAInC;;OAEG;IACI,OAAO,IAAI,IAAI;CAIvB"}
|
|
@@ -26,6 +26,7 @@ var _is = require("../utils/is");
|
|
|
26
26
|
var _ack = require("../utils/ack");
|
|
27
27
|
var _hooks = require("../utils/hooks");
|
|
28
28
|
var _logger = require("../utils/logger");
|
|
29
|
+
var _channel = require("./channel");
|
|
29
30
|
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; }
|
|
30
31
|
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; }
|
|
31
32
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
@@ -206,6 +207,7 @@ class MessageDispatcher {
|
|
|
206
207
|
return;
|
|
207
208
|
}
|
|
208
209
|
}
|
|
210
|
+
var offEarlyAutoAck;
|
|
209
211
|
try {
|
|
210
212
|
this.hooks.inbound.call(data, context);
|
|
211
213
|
var _type = data.type;
|
|
@@ -229,6 +231,25 @@ class MessageDispatcher {
|
|
|
229
231
|
autoAckState.sent = true;
|
|
230
232
|
this.tryAutoAck(data, context);
|
|
231
233
|
};
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Early auto-ack: send ACK as soon as the handler "accepts" the message.
|
|
237
|
+
*
|
|
238
|
+
* Why:
|
|
239
|
+
* - For request delivery confirmation, ACK should represent "accepted/claimed by server"
|
|
240
|
+
* instead of "handler finished".
|
|
241
|
+
* - This keeps client-side ackTimeout meaningful and avoids being delayed by business logic.
|
|
242
|
+
*
|
|
243
|
+
* Notes:
|
|
244
|
+
* - Only contexts created by MessageChannel have onStateChange; tests may provide mocks.
|
|
245
|
+
* - We keep the original end-of-dispatch maybeAutoAck() as a fallback for older/edge contexts.
|
|
246
|
+
*/
|
|
247
|
+
var onStateChangeMaybe = context.onStateChange;
|
|
248
|
+
offEarlyAutoAck = typeof onStateChangeMaybe === 'function' ? onStateChangeMaybe('autoAck:early', (_prev, next) => {
|
|
249
|
+
if (next === _channel.MessageContextStage.ACCEPTED) {
|
|
250
|
+
maybeAutoAck();
|
|
251
|
+
}
|
|
252
|
+
}) : undefined;
|
|
232
253
|
var _iterator = _createForOfIteratorHelper(this.handlers),
|
|
233
254
|
_step;
|
|
234
255
|
try {
|
|
@@ -272,6 +293,12 @@ class MessageDispatcher {
|
|
|
272
293
|
}
|
|
273
294
|
maybeAutoAck();
|
|
274
295
|
} finally {
|
|
296
|
+
try {
|
|
297
|
+
var _offEarlyAutoAck;
|
|
298
|
+
(_offEarlyAutoAck = offEarlyAutoAck) === null || _offEarlyAutoAck === void 0 || _offEarlyAutoAck();
|
|
299
|
+
} catch (_unused) {
|
|
300
|
+
// ignore
|
|
301
|
+
}
|
|
275
302
|
/**
|
|
276
303
|
* Mark as "done" only when this dispatcher actually claimed/handled this message.
|
|
277
304
|
* - If the message was never claimed (handledBy not set), we keep `doneBy` empty so another
|