mirror of
https://github.com/dergigi/boris.git
synced 2025-12-23 01:24:19 +01:00
chore: upgrade applesauce packages to v4.0.0
- Update all applesauce packages from 3.1.0 to 4.0.0 - Add applesauce-factory dependency - Version 4.0.0 includes app-data helpers needed for NIP-78
This commit is contained in:
57
node_modules/nostr-tools/lib/esm/abstract-relay.js
generated
vendored
57
node_modules/nostr-tools/lib/esm/abstract-relay.js
generated
vendored
@@ -169,7 +169,10 @@ var AbstractRelay = class {
|
||||
baseEoseTimeout = 4400;
|
||||
connectionTimeout = 4400;
|
||||
publishTimeout = 4400;
|
||||
pingFrequency = 2e4;
|
||||
pingTimeout = 2e4;
|
||||
openSubs = /* @__PURE__ */ new Map();
|
||||
enablePing;
|
||||
connectionTimeoutHandle;
|
||||
connectionPromise;
|
||||
openCountRequests = /* @__PURE__ */ new Map();
|
||||
@@ -186,6 +189,7 @@ var AbstractRelay = class {
|
||||
this.url = normalizeURL(url);
|
||||
this.verifyEvent = opts.verifyEvent;
|
||||
this._WebSocket = opts.websocketImplementation || WebSocket;
|
||||
this.enablePing = opts.enablePing;
|
||||
}
|
||||
static async connect(url, opts) {
|
||||
const relay = new AbstractRelay(url, opts);
|
||||
@@ -231,7 +235,7 @@ var AbstractRelay = class {
|
||||
this.ws.onopen = () => {
|
||||
clearTimeout(this.connectionTimeoutHandle);
|
||||
this._connected = true;
|
||||
if (this.ws && this.ws.ping) {
|
||||
if (this.enablePing) {
|
||||
this.pingpong();
|
||||
}
|
||||
resolve();
|
||||
@@ -239,45 +243,54 @@ var AbstractRelay = class {
|
||||
this.ws.onerror = (ev) => {
|
||||
clearTimeout(this.connectionTimeoutHandle);
|
||||
reject(ev.message || "websocket error");
|
||||
if (this._connected) {
|
||||
this._connected = false;
|
||||
this.connectionPromise = void 0;
|
||||
this.onclose?.();
|
||||
this.closeAllSubscriptions("relay connection errored");
|
||||
}
|
||||
this._connected = false;
|
||||
this.connectionPromise = void 0;
|
||||
this.onclose?.();
|
||||
this.closeAllSubscriptions("relay connection errored");
|
||||
};
|
||||
this.ws.onclose = (ev) => {
|
||||
clearTimeout(this.connectionTimeoutHandle);
|
||||
reject(ev.message || "websocket closed");
|
||||
if (this._connected) {
|
||||
this._connected = false;
|
||||
this.connectionPromise = void 0;
|
||||
this.onclose?.();
|
||||
this.closeAllSubscriptions("relay connection closed");
|
||||
}
|
||||
this._connected = false;
|
||||
this.connectionPromise = void 0;
|
||||
this.onclose?.();
|
||||
this.closeAllSubscriptions("relay connection closed");
|
||||
};
|
||||
this.ws.onmessage = this._onmessage.bind(this);
|
||||
});
|
||||
return this.connectionPromise;
|
||||
}
|
||||
async receivePong() {
|
||||
async waitForPingPong() {
|
||||
return new Promise((res, err) => {
|
||||
;
|
||||
this.ws && this.ws.on && this.ws.on("pong", () => res(true)) || err("ws can't listen for pong");
|
||||
this.ws && this.ws.ping && this.ws.ping();
|
||||
});
|
||||
}
|
||||
async waitForDummyReq() {
|
||||
return new Promise((resolve, _) => {
|
||||
const sub = this.subscribe([{ ids: ["a".repeat(64)] }], {
|
||||
oneose: () => {
|
||||
sub.close();
|
||||
resolve(true);
|
||||
},
|
||||
eoseTimeout: this.pingTimeout + 1e3
|
||||
});
|
||||
});
|
||||
}
|
||||
async pingpong() {
|
||||
if (this.ws?.readyState == 1) {
|
||||
this.ws && this.ws.ping && this.ws.ping();
|
||||
if (this.ws?.readyState === 1) {
|
||||
const result = await Promise.any([
|
||||
this.receivePong(),
|
||||
new Promise((res) => setTimeout(() => res(false), 1e4))
|
||||
this.ws && this.ws.ping && this.ws.on ? this.waitForPingPong() : this.waitForDummyReq(),
|
||||
new Promise((res) => setTimeout(() => res(false), this.pingTimeout))
|
||||
]);
|
||||
console.error("pingpong result", result);
|
||||
if (result) {
|
||||
setTimeout(() => this.pingpong(), 1e4);
|
||||
setTimeout(() => this.pingpong(), this.pingFrequency);
|
||||
} else {
|
||||
this.ws && this.ws.close();
|
||||
this.closeAllSubscriptions("pingpong timed out");
|
||||
this._connected = false;
|
||||
this.onclose?.();
|
||||
this.ws?.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -442,8 +455,8 @@ var AbstractRelay = class {
|
||||
close() {
|
||||
this.closeAllSubscriptions("relay connection closed by us");
|
||||
this._connected = false;
|
||||
this.ws?.close();
|
||||
this.onclose?.();
|
||||
this.ws?.close();
|
||||
}
|
||||
_onmessage(ev) {
|
||||
this.incomingMessageQueue.enqueue(ev.data);
|
||||
|
||||
Reference in New Issue
Block a user