mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(pubsub): restore browser pure p2p publishing
This commit is contained in:
+69
-47
@@ -1,5 +1,51 @@
|
||||
diff --git a/dist/browser/helia/helia-for-pkc.js b/dist/browser/helia/helia-for-pkc.js
|
||||
index e6821667b0601ac56a850e989bfedf76c14796a2..1a2ae7ab9b0afc605c9b4dcddccf25ac02aa1337 100644
|
||||
--- a/dist/browser/helia/helia-for-pkc.js
|
||||
+++ b/dist/browser/helia/helia-for-pkc.js
|
||||
@@ -145,6 +145,11 @@ export async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
|
||||
warmupPromisesByTopic.set(topic, p);
|
||||
return p;
|
||||
};
|
||||
+ const ignoreBestEffortPubsubWarmupError = (operation, topic, err, options) => {
|
||||
+ if (options?.signal?.aborted)
|
||||
+ throw err;
|
||||
+ log.error(`Best-effort pubsub peer warmup failed before ${operation} on topic`, topic, err);
|
||||
+ };
|
||||
const throwIfHeliaIsStoppingOrStopped = () => {
|
||||
if (helia.libp2p.status === "stopped" || helia.libp2p.status === "stopping")
|
||||
throw new PKCError("ERR_HELIAS_STOPPING_OR_STOPPED", {
|
||||
@@ -290,8 +295,13 @@ export async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
|
||||
if (!wasAlreadySubscribed)
|
||||
helia.libp2p.services.pubsub.subscribe(topic);
|
||||
try {
|
||||
- await warmupForTopic(topic, options);
|
||||
- const res = await helia.libp2p.services.pubsub.publish(topic, data);
|
||||
+ try {
|
||||
+ await warmupForTopic(topic, options);
|
||||
+ }
|
||||
+ catch (err) {
|
||||
+ ignoreBestEffortPubsubWarmupError("publish", topic, err, options);
|
||||
+ }
|
||||
+ const res = await helia.libp2p.services.pubsub.publish(topic, data, { allowPublishToZeroTopicPeers: true });
|
||||
log("Published new data to pubsub topic (string, e.g. community address)", topic, "Direct gossipsub recipients (libp2p peer IDs, NOT signer/community addresses):", res.recipients.map((p) => p.toString()));
|
||||
}
|
||||
finally {
|
||||
@@ -314,7 +324,12 @@ export async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
|
||||
// locally subscribed to).
|
||||
const warmupPromise = warmupForTopic(topic, options);
|
||||
helia.libp2p.services.pubsub.subscribe(topic);
|
||||
- await warmupPromise;
|
||||
+ try {
|
||||
+ await warmupPromise;
|
||||
+ }
|
||||
+ catch (err) {
|
||||
+ ignoreBestEffortPubsubWarmupError("subscribe", topic, err, options);
|
||||
+ }
|
||||
},
|
||||
unsubscribe: async (topic, handler, options) => {
|
||||
throwIfHeliaIsStoppingOrStopped();
|
||||
diff --git a/dist/browser/publications/publication.js b/dist/browser/publications/publication.js
|
||||
index 5e17c02a39c2715c7ac932695fe90d5078bce405..339d299de85ba5d144e4608f9189c88f4ef42dc8 100644
|
||||
index 5e17c02a39c2715c7ac932695fe90d5078bce405..2d43d996e2b3cdab759e89c296eb9ed8aae857db 100644
|
||||
--- a/dist/browser/publications/publication.js
|
||||
+++ b/dist/browser/publications/publication.js
|
||||
@@ -842,8 +842,14 @@ class Publication extends TypedEmitter {
|
||||
@@ -19,49 +65,25 @@ index 5e17c02a39c2715c7ac932695fe90d5078bce405..339d299de85ba5d144e4608f9189c88f
|
||||
pubsubTopic: this._communityPubsubTopicWithFallback(),
|
||||
providerHeliaContexts: this._libp2pJsClientHeliaContexts()
|
||||
});
|
||||
diff --git a/dist/browser/helia/helia-for-pkc.js b/dist/browser/helia/helia-for-pkc.js
|
||||
index 3eca64dd532a19393c55ddf953dfd4ef207c65f8..683fed56722effc54b1b08e5b050e311ed174424 100644
|
||||
--- a/dist/browser/helia/helia-for-pkc.js
|
||||
+++ b/dist/browser/helia/helia-for-pkc.js
|
||||
@@ -161,6 +161,11 @@ export async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
|
||||
warmupPromisesByTopic.set(topic, p);
|
||||
return p;
|
||||
};
|
||||
+ const ignoreBestEffortPubsubWarmupError = (operation, topic, err, options) => {
|
||||
+ if (options?.signal?.aborted)
|
||||
+ throw err;
|
||||
+ log.error(`Best-effort pubsub peer warmup failed before ${operation} on topic`, topic, err);
|
||||
+ };
|
||||
const throwIfHeliaIsStoppingOrStopped = () => {
|
||||
if (helia.libp2p.status === "stopped" || helia.libp2p.status === "stopping")
|
||||
throw new PKCError("ERR_HELIAS_STOPPING_OR_STOPPED", {
|
||||
@@ -299,8 +304,13 @@ export async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
|
||||
if (!wasAlreadySubscribed)
|
||||
helia.libp2p.services.pubsub.subscribe(topic);
|
||||
try {
|
||||
- await warmupForTopic(topic, options);
|
||||
- const res = await helia.libp2p.services.pubsub.publish(topic, data);
|
||||
+ try {
|
||||
+ await warmupForTopic(topic, options);
|
||||
+ }
|
||||
+ catch (err) {
|
||||
+ ignoreBestEffortPubsubWarmupError("publish", topic, err, options);
|
||||
+ }
|
||||
+ const res = await helia.libp2p.services.pubsub.publish(topic, data, { allowPublishToZeroTopicPeers: true });
|
||||
log("Published new data to pubsub topic (string, e.g. community address)", topic, "Direct gossipsub recipients (libp2p peer IDs, NOT signer/community addresses):", res.recipients.map((p) => p.toString()));
|
||||
}
|
||||
finally {
|
||||
@@ -323,7 +333,12 @@ export async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
|
||||
// locally subscribed to).
|
||||
const warmupPromise = warmupForTopic(topic, options);
|
||||
helia.libp2p.services.pubsub.subscribe(topic);
|
||||
- await warmupPromise;
|
||||
+ try {
|
||||
+ await warmupPromise;
|
||||
+ }
|
||||
+ catch (err) {
|
||||
+ ignoreBestEffortPubsubWarmupError("subscribe", topic, err, options);
|
||||
+ }
|
||||
},
|
||||
unsubscribe: async (topic, handler, options) => {
|
||||
throwIfHeliaIsStoppingOrStopped();
|
||||
diff --git a/dist/browser/runtime/browser/libp2p-extra-transports.js b/dist/browser/runtime/browser/libp2p-extra-transports.js
|
||||
index 1b7028978d1da8c3f78e9b4d18e790a3ad025e25..2b8eff3ce509cff57ac5be3d31b26b38a5301a52 100644
|
||||
--- a/dist/browser/runtime/browser/libp2p-extra-transports.js
|
||||
+++ b/dist/browser/runtime/browser/libp2p-extra-transports.js
|
||||
@@ -1,3 +1,4 @@
|
||||
-const extraLibp2pTransports = [];
|
||||
+import { webTransport } from "@libp2p/webtransport";
|
||||
+const extraLibp2pTransports = typeof globalThis.WebTransport === "function" ? [webTransport()] : [];
|
||||
export default extraLibp2pTransports;
|
||||
//# sourceMappingURL=libp2p-extra-transports.js.map
|
||||
diff --git a/package.json b/package.json
|
||||
index 2a44f27220191ee556a317bf25005b7fcbde6aaa..335ee82cc7e9850eb1bc036b2a481ae5a575eabd 100644
|
||||
--- a/package.json
|
||||
+++ b/package.json
|
||||
@@ -78,6 +78,7 @@
|
||||
"@libp2p/identify": "4.1.3",
|
||||
"@libp2p/interface": "3.2.2",
|
||||
"@libp2p/peer-id": "6.0.8",
|
||||
+ "@libp2p/webtransport": "6.0.0",
|
||||
"@multiformats/multiaddr": "13.0.1",
|
||||
"@noble/curves": "2.2.0",
|
||||
"@pkcprotocol/pkc-logger": "0.1.0",
|
||||
Reference in New Issue
Block a user