cross-tab-worker-databus 0.1.0 → 0.1.2

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.
@@ -5010,7 +5010,11 @@ var CentrifugeSession = class {
5010
5010
  client.on("connected", () => this.post({ type: "STATUS", status: "connected" }));
5011
5011
  client.on("disconnected", () => this.post({ type: "STATUS", status: "disconnected" }));
5012
5012
  client.on("error", (context) => this.postError(context));
5013
- client.on("publication", (context) => this.postPublication(context.channel || getPayloadTopic(context.data), context.data));
5013
+ client.on("publication", (context) => {
5014
+ const topic = context.channel || getPayloadTopic(context.data);
5015
+ if (!topic || this.subscriptions.has(topic)) return;
5016
+ this.postPublication(topic, context.data);
5017
+ });
5014
5018
  client.connect();
5015
5019
  }
5016
5020
  /** Subscribe to a Centrifuge channel. Reuses an existing subscription if one exists. */
@@ -5029,12 +5033,17 @@ var CentrifugeSession = class {
5029
5033
  subscription.on("unsubscribed", () => this.subscriptions.delete(topic));
5030
5034
  subscription.subscribe();
5031
5035
  }
5032
- /** Unsubscribe from a Centrifuge channel and clean up the local reference. */
5036
+ /** Unsubscribe from a Centrifuge channel and clean up the local reference.
5037
+ * Listeners are removed before unsubscribing so a late `unsubscribed` event
5038
+ * cannot delete a subscription that a subsequent `subscribe()` re-added. */
5033
5039
  unsubscribe(topic) {
5034
5040
  const subscription = this.subscriptions.get(topic) ?? this.client?.getSubscription(topic);
5035
5041
  if (!subscription) return;
5036
- subscription.unsubscribe();
5042
+ subscription.removeAllListeners("publication");
5043
+ subscription.removeAllListeners("error");
5044
+ subscription.removeAllListeners("unsubscribed");
5037
5045
  this.subscriptions.delete(topic);
5046
+ subscription.unsubscribe();
5038
5047
  }
5039
5048
  /** Publish a message to the Centrifuge channel. */
5040
5049
  publish(topic, data) {