cross-tab-worker-databus 0.8.0 → 0.11.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 +34 -0
- package/README.md +2 -0
- package/README.zh.md +2 -0
- package/dist/centrifuge-protocol.d.ts +4 -0
- package/dist/centrifuge-protocol.d.ts.map +1 -1
- package/dist/centrifuge-session.d.ts.map +1 -1
- package/dist/centrifuge.js +29 -11
- package/dist/centrifuge.js.map +2 -2
- package/dist/centrifuge.shared.worker.js +37 -6
- package/dist/centrifuge.shared.worker.js.map +3 -3
- package/dist/centrifuge.worker.js +37 -6
- package/dist/centrifuge.worker.js.map +3 -3
- package/dist/{chunk-WWUY2FV2.js → chunk-NX76TAV3.js} +137 -26
- package/dist/chunk-NX76TAV3.js.map +7 -0
- package/dist/cjs/centrifuge.cjs +164 -35
- package/dist/cjs/centrifuge.cjs.map +4 -4
- package/dist/cjs/index.cjs +172 -38
- package/dist/cjs/index.cjs.map +3 -3
- package/dist/core/cluster.d.ts +3 -2
- package/dist/core/cluster.d.ts.map +1 -1
- package/dist/core/data-bus.d.ts +19 -0
- package/dist/core/data-bus.d.ts.map +1 -1
- package/dist/core/publication.d.ts +10 -0
- package/dist/core/publication.d.ts.map +1 -0
- package/dist/core/replay-persistence.d.ts +2 -0
- package/dist/core/replay-persistence.d.ts.map +1 -1
- package/dist/core/trace.d.ts +7 -0
- package/dist/core/trace.d.ts.map +1 -1
- package/dist/core/types.d.ts +19 -7
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -14
- package/dist/index.js.map +2 -2
- package/dist/websocket.d.ts.map +1 -1
- package/docs/api.md +27 -6
- package/docs/architecture.md +7 -1
- package/docs/capabilities.md +2 -2
- package/docs/configuration.md +1 -1
- package/docs/roadmap.md +15 -1
- package/docs/transports.md +9 -5
- package/docs/zh/api.md +27 -6
- package/docs/zh/architecture.md +7 -1
- package/docs/zh/capabilities.md +2 -2
- package/docs/zh/configuration.md +1 -1
- package/docs/zh/transports.md +8 -4
- package/package.json +1 -1
- package/dist/chunk-WWUY2FV2.js.map +0 -7
|
@@ -4981,6 +4981,26 @@ Centrifuge.SubscriptionState = SubscriptionState;
|
|
|
4981
4981
|
Centrifuge.State = State;
|
|
4982
4982
|
Centrifuge.UnauthorizedError = UnauthorizedError;
|
|
4983
4983
|
|
|
4984
|
+
// src/core/publication.ts
|
|
4985
|
+
function parseDataBusPublication(value, fallbackTopic) {
|
|
4986
|
+
if (!value || typeof value !== "object") {
|
|
4987
|
+
return fallbackTopic ? { topic: fallbackTopic, data: value } : null;
|
|
4988
|
+
}
|
|
4989
|
+
const frame = value;
|
|
4990
|
+
const nested = frame.publication && typeof frame.publication === "object" ? frame.publication : null;
|
|
4991
|
+
const publication = nested ?? frame;
|
|
4992
|
+
const topic = typeof publication.topic === "string" ? publication.topic : fallbackTopic;
|
|
4993
|
+
if (!topic) return null;
|
|
4994
|
+
const hasMetadataEnvelope = fallbackTopic !== void 0 && Object.prototype.hasOwnProperty.call(publication, "data") && (typeof publication.messageId === "string" || typeof publication.timestamp === "number");
|
|
4995
|
+
const data = nested || fallbackTopic === void 0 || hasMetadataEnvelope ? publication.data : value;
|
|
4996
|
+
return {
|
|
4997
|
+
topic,
|
|
4998
|
+
data,
|
|
4999
|
+
...typeof publication.messageId === "string" ? { messageId: publication.messageId } : {},
|
|
5000
|
+
...typeof publication.timestamp === "number" ? { timestamp: publication.timestamp } : {}
|
|
5001
|
+
};
|
|
5002
|
+
}
|
|
5003
|
+
|
|
4984
5004
|
// src/centrifuge-session.ts
|
|
4985
5005
|
var CentrifugeSession = class {
|
|
4986
5006
|
constructor(sink) {
|
|
@@ -5005,7 +5025,7 @@ var CentrifugeSession = class {
|
|
|
5005
5025
|
return;
|
|
5006
5026
|
case "PUBLISH":
|
|
5007
5027
|
case "PUBLISH_BIN":
|
|
5008
|
-
this.publish(message.topic, message.data, message.messageId);
|
|
5028
|
+
this.publish(message.topic, message.data, message.messageId, message.timestamp);
|
|
5009
5029
|
return;
|
|
5010
5030
|
case "STOP":
|
|
5011
5031
|
this.stop();
|
|
@@ -5070,9 +5090,14 @@ var CentrifugeSession = class {
|
|
|
5070
5090
|
subscription.unsubscribe();
|
|
5071
5091
|
}
|
|
5072
5092
|
/** Publish a message to the Centrifuge channel. */
|
|
5073
|
-
publish(topic, data, messageId) {
|
|
5093
|
+
publish(topic, data, messageId, timestamp) {
|
|
5074
5094
|
if (!this.client) return this.postError(new Error("Centrifuge client is not initialized."));
|
|
5075
|
-
const
|
|
5095
|
+
const hasMetadata = messageId !== void 0 || timestamp !== void 0;
|
|
5096
|
+
const payload = hasMetadata ? {
|
|
5097
|
+
data,
|
|
5098
|
+
...messageId === void 0 ? {} : { messageId },
|
|
5099
|
+
...timestamp === void 0 ? {} : { timestamp }
|
|
5100
|
+
} : data;
|
|
5076
5101
|
void this.client.publish(topic, payload).catch((error) => this.postError(error));
|
|
5077
5102
|
}
|
|
5078
5103
|
/** Forward a publication to the transport. Binary payloads take the
|
|
@@ -5085,9 +5110,15 @@ var CentrifugeSession = class {
|
|
|
5085
5110
|
this.post({ type: "MESSAGE_BIN", topic, data }, [data]);
|
|
5086
5111
|
return;
|
|
5087
5112
|
}
|
|
5088
|
-
const
|
|
5089
|
-
|
|
5090
|
-
this.post({
|
|
5113
|
+
const publication = parseDataBusPublication(data, topic);
|
|
5114
|
+
if (!publication) return;
|
|
5115
|
+
this.post({
|
|
5116
|
+
type: "MESSAGE",
|
|
5117
|
+
topic: publication.topic,
|
|
5118
|
+
data: publication.data,
|
|
5119
|
+
...publication.messageId === void 0 ? {} : { messageId: publication.messageId },
|
|
5120
|
+
...publication.timestamp === void 0 ? {} : { timestamp: publication.timestamp }
|
|
5121
|
+
});
|
|
5091
5122
|
}
|
|
5092
5123
|
/** Disconnect the client and clear all subscriptions. */
|
|
5093
5124
|
stop() {
|