Fix quote, retry errored sockets
This commit is contained in:
@@ -180,7 +180,10 @@ export class Router {
|
|||||||
|
|
||||||
Quote = (event: TrustedEvent, value: string, relays = []) => {
|
Quote = (event: TrustedEvent, value: string, relays = []) => {
|
||||||
const tag = event.tags.find(t => t[1] === value)
|
const tag = event.tags.find(t => t[1] === value)
|
||||||
const scenarios: RouterScenario[] = []
|
const scenarios = [
|
||||||
|
this.ForPubkey(event.pubkey),
|
||||||
|
this.FromPubkey(event.pubkey),
|
||||||
|
]
|
||||||
|
|
||||||
if (tag?.[2] && isShareableRelayUrl(tag[2])) {
|
if (tag?.[2] && isShareableRelayUrl(tag[2])) {
|
||||||
scenarios.push(this.FromRelays([tag[2]]))
|
scenarios.push(this.FromRelays([tag[2]]))
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ const {
|
|||||||
} = SocketStatus
|
} = SocketStatus
|
||||||
|
|
||||||
export class Socket {
|
export class Socket {
|
||||||
|
lastError = 0
|
||||||
status = SocketStatus.New
|
status = SocketStatus.New
|
||||||
worker = new Worker<Message>()
|
worker = new Worker<Message>()
|
||||||
ws?: WebSocket
|
ws?: WebSocket
|
||||||
@@ -53,6 +54,13 @@ export class Socket {
|
|||||||
this.cxn.emit(ConnectionEvent.Reset)
|
this.cxn.emit(ConnectionEvent.Reset)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we're closed due to an error retry after a delay
|
||||||
|
if (Date.now() - this.lastError > 15_000) {
|
||||||
|
this.status = New
|
||||||
|
this.lastError = 0
|
||||||
|
this.cxn.emit(ConnectionEvent.Reset)
|
||||||
|
}
|
||||||
|
|
||||||
// If the socket is new, connect
|
// If the socket is new, connect
|
||||||
if (this.status === New) {
|
if (this.status === New) {
|
||||||
this.#init()
|
this.#init()
|
||||||
@@ -94,6 +102,7 @@ export class Socket {
|
|||||||
|
|
||||||
this.ws.onerror = () => {
|
this.ws.onerror = () => {
|
||||||
this.status = Error
|
this.status = Error
|
||||||
|
this.lastError = Date.now()
|
||||||
this.cxn.emit(ConnectionEvent.Error)
|
this.cxn.emit(ConnectionEvent.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user