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.
@@ -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
- broadcastEvent(eventType, payload) {
707
- this.send({ type: "EVENT", sourceWorkerId: this.workerId, eventType, payload });
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 message = payload;
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.broadcastEvent(PUBLICATION_EVENT, message);
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(message);
1919
+ this.dispatch(stamped);
1915
1920
  return;
1916
1921
  }
1917
1922
  this.trace.recordDiscarded(message.topic);