Resubscribe on reconnect

This commit is contained in:
Wietse Wind
2023-10-06 01:42:30 +02:00
parent 9d1b9557d4
commit e51dde1386

View File

@@ -13,31 +13,36 @@ await createDirectory('store/xpop')
process.env.NODES.split(',').map(h => h.trim())
.map(h => new XrplClient(h)).map(async c => {
await c.ready()
const subscribe = async () => {
await c.ready()
/**
* TODO: Auto disconnect if no messages for X
* TODO: Generate xPOPs for matching transactions
*/
/**
* TODO: Auto disconnect if no messages for X
* TODO: Generate xPOPs for matching transactions
*/
c.send({ command: "subscribe", streams: [
"validations",
"ledger",
// No transactions, to make it easier for clients transactions are
// processed in order (sorted on sequence) and emitted in order
// to clients to prevent async tx sequence problems.
] })
c.send({ command: "subscribe", streams: [
"validations",
"ledger",
// No transactions, to make it easier for clients transactions are
// processed in order (sorted on sequence) and emitted in order
// to clients to prevent async tx sequence problems.
] })
c.on("validation", validation => onValidation({
connectionUrl: c.getState()?.server?.uri,
networkId: c.getState()?.server?.networkId,
validation,
}))
c.on("validation", validation => onValidation({
connectionUrl: c.getState()?.server?.uri,
networkId: c.getState()?.server?.networkId,
validation,
}))
c.on("ledger", ledger => onLedger({
connectionUrl: c.getState()?.server?.uri,
networkId: c.getState()?.server?.networkId,
ledger,
connection: c,
}))
}
c.on("ledger", ledger => onLedger({
connectionUrl: c.getState()?.server?.uri,
networkId: c.getState()?.server?.networkId,
ledger,
connection: c,
}))
c.on('online', () => subscribe())
})