cross-tab-worker-databus 0.20.60 → 0.20.61
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/CHANGELOG.md +14 -1
- package/dist/centrifuge.js +1 -1
- package/dist/{chunk-KLHPSFVU.js → chunk-VB4P6DS6.js} +14 -9
- package/dist/chunk-VB4P6DS6.js.map +7 -0
- package/dist/cjs/centrifuge.cjs +13 -8
- package/dist/cjs/centrifuge.cjs.map +2 -2
- package/dist/cjs/index.cjs +13 -8
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/core/cluster.d.ts +9 -4
- package/dist/core/cluster.d.ts.map +1 -1
- package/dist/core/data-bus.d.ts.map +1 -1
- package/dist/core/types.d.ts +10 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/docs/roadmap.md +8 -1
- package/docs/zh/roadmap.md +8 -1
- package/package.json +1 -1
- package/dist/chunk-KLHPSFVU.js.map +0 -7
package/dist/cjs/index.cjs
CHANGED
|
@@ -702,9 +702,12 @@ var WorkerClusterRuntime = class {
|
|
|
702
702
|
routeOwnerIsLive(route, workers) {
|
|
703
703
|
return Boolean(route && workers.some((worker) => worker.workerId === route.workerId));
|
|
704
704
|
}
|
|
705
|
-
/** Broadcast an event to every tab — used to fan out transport publications.
|
|
706
|
-
|
|
707
|
-
|
|
705
|
+
/** Broadcast an event to every tab — used to fan out transport publications.
|
|
706
|
+
* `originTabId` (when set) is propagated across the BroadcastChannel hop so
|
|
707
|
+
* listeners can attribute the event to its source tab even after fan-out. */
|
|
708
|
+
broadcastEvent(eventType, payload, originTabId) {
|
|
709
|
+
const effectiveOriginTabId = originTabId ?? this.tabId;
|
|
710
|
+
this.send({ type: "EVENT", sourceWorkerId: this.workerId, eventType, payload, originTabId: effectiveOriginTabId });
|
|
708
711
|
}
|
|
709
712
|
isAssigned(topic) {
|
|
710
713
|
const topicKey = createOpaqueKey(topic);
|
|
@@ -792,7 +795,7 @@ var WorkerClusterRuntime = class {
|
|
|
792
795
|
case "ROUTE_RELEASED":
|
|
793
796
|
return this.handleRouteReleasedMessage(message);
|
|
794
797
|
case "EVENT":
|
|
795
|
-
this.handlers.onEvent(message.eventType, message.payload, message.sourceWorkerId);
|
|
798
|
+
this.handlers.onEvent(message.eventType, message.payload, message.sourceWorkerId, message.originTabId);
|
|
796
799
|
return;
|
|
797
800
|
case "REGISTRY":
|
|
798
801
|
default:
|
|
@@ -1544,9 +1547,10 @@ var CrossTabDataBus = class {
|
|
|
1544
1547
|
// typed `unknown` at the cluster boundary (the cluster is transport-
|
|
1545
1548
|
// agnostic); here we narrow it to DataBusMessage — the sender is our
|
|
1546
1549
|
// own broadcastEvent call, which always posts a DataBusMessage.
|
|
1547
|
-
onEvent: (eventType, payload) => {
|
|
1550
|
+
onEvent: (eventType, payload, _sourceWorkerId, originTabId) => {
|
|
1548
1551
|
if (eventType !== PUBLICATION_EVENT) return;
|
|
1549
|
-
const
|
|
1552
|
+
const incoming = payload;
|
|
1553
|
+
const message = incoming.originTabId !== void 0 ? incoming : originTabId !== void 0 ? { ...incoming, originTabId } : incoming;
|
|
1550
1554
|
if (this.cluster.hasLocalSubscriber(message.topic)) this.dispatch(message);
|
|
1551
1555
|
},
|
|
1552
1556
|
onSuspend: () => {
|
|
@@ -1909,9 +1913,10 @@ var CrossTabDataBus = class {
|
|
|
1909
1913
|
this.trace.recordDiscarded(message.topic);
|
|
1910
1914
|
return;
|
|
1911
1915
|
}
|
|
1912
|
-
this.cluster.
|
|
1916
|
+
const stamped = message.originTabId === void 0 ? { ...message, originTabId: this.cluster.tabId } : message;
|
|
1917
|
+
this.cluster.broadcastEvent(PUBLICATION_EVENT, stamped, stamped.originTabId);
|
|
1913
1918
|
if (this.cluster.hasLocalSubscriber(message.topic)) {
|
|
1914
|
-
this.dispatch(
|
|
1919
|
+
this.dispatch(stamped);
|
|
1915
1920
|
return;
|
|
1916
1921
|
}
|
|
1917
1922
|
this.trace.recordDiscarded(message.topic);
|