Construct a connection manager.
Optional
proxyToWorker: boolean = trueconfigure all connections to proxy to worker (default true)
Protected
autoProtected
connectionsProtected
currentProtected
listenersProtected
pollerProtected
proxyProtected
responseProtected
timeoutStatic
DEFAULT_Static
DEFAULT_Static
DEFAULT_Static
MIN_Static
PollSpecify behavior when polling.
One of PRIORITIZED (poll connections in order of priority until connected; default), CURRENT (poll current connection), or ALL (poll all connections).
Add a connection. The connection may have an elevated priority for this manager to use.
uri or connection to add
this connection manager for chaining
Add a listener to receive notifications when the connection changes.
the listener to add
this connection manager for chaining
Check the current connection. If disconnected and auto switch enabled, switches to best available connection.
this connection manager for chaining
Check all managed connections.
this connection manager for chaining
Protected
checkRemove all connections.
this connection manager for chaining
Protected
compareProtected
compareDisconnect from the current connection.
this connection manager for chaining
Get the best available connection in order of priority then response time.
Optional
excludedConnections: MoneroRpcConnection[]connections to be excluded from consideration (optional)
the best available connection in order of priority then response time, undefined if no connections available
Protected
getGet the best connection from the given responses.
connection responses to update from
the best response among the given responses or undefined if none are best
Get the current connection.
the current connection or undefined if no connection set
Get a connection by URI.
is the URI of the connection to get
the connection with the URI or undefined if no connection with the URI exists
Get all connections in order of current connection (if applicable), online status, priority, and name.
the list of sorted connections
Protected
getGet all listeners.
all listeners
Collect connectable peers of the managed connections.
connectable peers
Protected
onProtected
processRemove a connection.
of the the connection to remove
this connection manager for chaining
Remove a listener.
the listener to remove
this connection manager for chaining
Remove all listeners.
this connection manager for chaining
Reset to default state.
this connection manager for chaining
Automatically switch to the best available connection as connections are polled, based on priority, response time, and consistency.
specifies if the connection should auto switch to a better connection
this connection manager for chaining
Set the current connection. Provide a URI to select an existing connection without updating its credentials. Provide a MoneroRpcConnection to add new connection or replace existing connection with the same URI. Notify if current connection changes. Does not check the connection.
Optional
uriOrConnection: string | Partial<MoneroRpcConnection>is the uri of the connection or the connection to make current (default undefined for no current connection)
this connection manager for chaining
Set the maximum request time before its connection is considered offline.
the timeout before the connection is considered offline
this connection manager for chaining
Start polling connections.
Optional
periodMs: numberpoll period in milliseconds (default 20s)
Optional
autoSwitch: booleanspecifies to automatically switch to the best connection (default true unless changed)
Optional
timeoutMs: numberspecifies the timeout to poll a single connection (default 5s unless changed)
Optional
pollType: numberone of PRIORITIZED (poll connections in order of priority until connected; default), CURRENT (poll current connection), or ALL (poll all connections)
Optional
excludedConnections: MoneroRpcConnection[]connections excluded from being polled
this connection manager for chaining
Protected
startProtected
startProtected
startStop polling connections.
this connection manager for chaining
Protected
updateGenerated using TypeDoc
Manages a collection of prioritized connections to daemon or wallet RPC endpoints.
Example usage:
// imports
import { MoneroRpcConnection, MoneroConnectionManager, MoneroConnectionManagerListener } from "monero-ts";
// create connection manager
let connectionManager = new MoneroConnectionManager();
// add managed connections with priorities
await connectionManager.addConnection({uri: "http://localhost:38081", priority: 1}); // use localhost as first priority
await connectionManager.addConnection({uri: "http://example.com"}); // default priority is prioritized last
// set current connection
await connectionManager.setConnection({uri: "http://foo.bar", username: "admin", password: "password"}); // connection is added if new
// check connection status
await connectionManager.checkConnection();
console.log("Connection manager is connected: " + connectionManager.isConnected());
console.log("Connection is online: " + connectionManager.getConnection().getIsOnline());
console.log("Connection is authenticated: " + connectionManager.getConnection().getIsAuthenticated());
// receive notifications of any changes to current connection
connectionManager.addListener(new class extends MoneroConnectionManagerListener {
async onConnectionChanged(connection) {
console.log("Connection changed to: " + connection);
}
});
// start polling for best connection every 10 seconds and automatically switch
connectionManager.startPolling(10000);
// automatically switch to best available connection if disconnected
connectionManager.setAutoSwitch(true);
// get best available connection in order of priority then response time
let bestConnection = await connectionManager.getBestAvailableConnection();
// check status of all connections
await connectionManager.checkConnections();
// get connections in order of current connection, online status from last check, priority, and name
let connections = connectionManager.getConnections();
// clear connection manager
connectionManager.clear();