cross-tab-worker-databus 0.1.2 → 0.2.0
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 +44 -0
- package/README.md +11 -0
- package/README.zh.md +9 -0
- package/dist/centrifuge-protocol.d.ts +51 -15
- package/dist/centrifuge-protocol.d.ts.map +1 -1
- package/dist/centrifuge-session.d.ts +11 -3
- package/dist/centrifuge-session.d.ts.map +1 -1
- package/dist/centrifuge.d.ts +10 -2
- package/dist/centrifuge.d.ts.map +1 -1
- package/dist/centrifuge.js +69 -26
- package/dist/centrifuge.js.map +2 -2
- package/dist/centrifuge.shared.worker.js +73 -25
- package/dist/centrifuge.shared.worker.js.map +2 -2
- package/dist/centrifuge.worker.js +41 -12
- package/dist/centrifuge.worker.js.map +2 -2
- package/dist/{chunk-53INHVYO.js → chunk-LBXREMZA.js} +263 -158
- package/dist/chunk-LBXREMZA.js.map +7 -0
- package/dist/core/cluster.d.ts +49 -4
- package/dist/core/cluster.d.ts.map +1 -1
- package/dist/core/data-bus.d.ts +19 -2
- package/dist/core/data-bus.d.ts.map +1 -1
- package/dist/core/environment.d.ts +16 -2
- package/dist/core/environment.d.ts.map +1 -1
- package/dist/core/hash.d.ts.map +1 -1
- package/dist/core/routing.d.ts +5 -2
- package/dist/core/routing.d.ts.map +1 -1
- package/dist/core/storage-batch.d.ts +12 -0
- package/dist/core/storage-batch.d.ts.map +1 -1
- package/dist/core/trace.d.ts +16 -1
- package/dist/core/trace.d.ts.map +1 -1
- package/dist/core/types.d.ts +76 -21
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/worker-mode.d.ts +12 -3
- package/dist/worker-mode.d.ts.map +1 -1
- package/dist/workers/port-reaper.d.ts +21 -6
- package/dist/workers/port-reaper.d.ts.map +1 -1
- package/docs/architecture.md +18 -8
- package/docs/transports.md +144 -0
- package/docs/zh/architecture.md +18 -8
- package/docs/zh/transports.md +132 -0
- package/package.json +7 -2
- package/dist/chunk-53INHVYO.js.map +0 -7
|
@@ -4989,14 +4989,30 @@ var CentrifugeSession = class {
|
|
|
4989
4989
|
client = null;
|
|
4990
4990
|
subscriptions = /* @__PURE__ */ new Map();
|
|
4991
4991
|
transferable = false;
|
|
4992
|
-
/** Dispatch an incoming Worker message to the matching operation.
|
|
4992
|
+
/** Dispatch an incoming Worker message to the matching operation.
|
|
4993
|
+
* Unknown message types are ignored rather than thrown, so a future protocol
|
|
4994
|
+
* extension adding a new variant cannot crash an older session. */
|
|
4993
4995
|
handle(message) {
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
4996
|
+
switch (message.type) {
|
|
4997
|
+
case "INIT":
|
|
4998
|
+
this.initialize(message.url, message.config, message.transferable === true);
|
|
4999
|
+
return;
|
|
5000
|
+
case "SUBSCRIBE":
|
|
5001
|
+
this.subscribe(message.topic);
|
|
5002
|
+
return;
|
|
5003
|
+
case "UNSUBSCRIBE":
|
|
5004
|
+
this.unsubscribe(message.topic);
|
|
5005
|
+
return;
|
|
5006
|
+
case "PUBLISH":
|
|
5007
|
+
case "PUBLISH_BIN":
|
|
5008
|
+
this.publish(message.topic, message.data);
|
|
5009
|
+
return;
|
|
5010
|
+
case "STOP":
|
|
5011
|
+
this.stop();
|
|
5012
|
+
return;
|
|
5013
|
+
default:
|
|
5014
|
+
return;
|
|
5015
|
+
}
|
|
5000
5016
|
}
|
|
5001
5017
|
/** Create the Centrifuge client, wire up lifecycle listeners, and connect. */
|
|
5002
5018
|
initialize(url, config, transferable) {
|
|
@@ -5017,9 +5033,17 @@ var CentrifugeSession = class {
|
|
|
5017
5033
|
});
|
|
5018
5034
|
client.connect();
|
|
5019
5035
|
}
|
|
5020
|
-
/** Subscribe to a Centrifuge channel. Reuses an existing subscription if one exists.
|
|
5036
|
+
/** Subscribe to a Centrifuge channel. Reuses an existing subscription if one exists.
|
|
5037
|
+
* Listeners are only registered once per subscription object — a repeated
|
|
5038
|
+
* SUBSCRIBE for an already-tracked topic skips the listener wiring entirely,
|
|
5039
|
+
* avoiding the removeAllListeners + re-on churn on every duplicate message. */
|
|
5021
5040
|
subscribe(topic) {
|
|
5022
5041
|
if (!this.client) return this.postError(new Error("Centrifuge client is not initialized."));
|
|
5042
|
+
const existing = this.subscriptions.get(topic);
|
|
5043
|
+
if (existing) {
|
|
5044
|
+
existing.subscribe();
|
|
5045
|
+
return;
|
|
5046
|
+
}
|
|
5023
5047
|
let subscription = this.client.getSubscription(topic);
|
|
5024
5048
|
if (!subscription) subscription = this.client.newSubscription(topic);
|
|
5025
5049
|
subscription.removeAllListeners("publication");
|
|
@@ -5050,7 +5074,10 @@ var CentrifugeSession = class {
|
|
|
5050
5074
|
if (!this.client) return this.postError(new Error("Centrifuge client is not initialized."));
|
|
5051
5075
|
void this.client.publish(topic, data).catch((error) => this.postError(error));
|
|
5052
5076
|
}
|
|
5053
|
-
/** Forward a publication to the transport
|
|
5077
|
+
/** Forward a publication to the transport. Binary payloads take the
|
|
5078
|
+
* zero-copy `MESSAGE_BIN` path when `transferable` is enabled; everything
|
|
5079
|
+
* else is structured-cloned via `MESSAGE`. An empty topic means the
|
|
5080
|
+
* publication carried no channel info and is silently dropped. */
|
|
5054
5081
|
postPublication(topic, data) {
|
|
5055
5082
|
if (!topic) return;
|
|
5056
5083
|
if (this.transferable && data instanceof ArrayBuffer) {
|
|
@@ -5082,12 +5109,14 @@ var CentrifugeSession = class {
|
|
|
5082
5109
|
function getPayloadTopic(data) {
|
|
5083
5110
|
if (!data || typeof data !== "object") return "";
|
|
5084
5111
|
const payload = data;
|
|
5085
|
-
const
|
|
5112
|
+
const push = payload.push;
|
|
5113
|
+
const nested = typeof push === "object" && push !== null ? push.channel : void 0;
|
|
5114
|
+
const topic = nested ?? payload.channel;
|
|
5086
5115
|
return typeof topic === "string" ? topic : "";
|
|
5087
5116
|
}
|
|
5117
|
+
var LIVE_STATES = /* @__PURE__ */ new Set(["connecting", "connected"]);
|
|
5088
5118
|
function normalizeStatus(status) {
|
|
5089
|
-
|
|
5090
|
-
return "disconnected";
|
|
5119
|
+
return LIVE_STATES.has(status) ? status : "disconnected";
|
|
5091
5120
|
}
|
|
5092
5121
|
function serializeError(error) {
|
|
5093
5122
|
if (error instanceof Error) {
|