Constructor
new MoneroConnectionManager(proxyToWorker)
Construct a connection manager.
Parameters:
Name | Type | Description |
---|---|---|
proxyToWorker |
boolean | configure all connections to proxy to worker (default true) |
Methods
(async) addConnection(connection) → {Promise.<MoneroConnectionManager>}
Add a connection. The connection may have an elevated priority for this manager to use.
Parameters:
Name | Type | Description |
---|---|---|
connection |
MoneroRpcConnection | the connection to add |
Returns:
this connection manager for chaining
- Type
- Promise.<MoneroConnectionManager>
addListener(listener) → {MoneroConnectionManager}
Add a listener to receive notifications when the connection changes.
Parameters:
Name | Type | Description |
---|---|---|
listener |
MoneroConnectionManagerListener | the listener to add |
Returns:
this connection manager for chaining
(async) checkConnection() → {Promise.<MoneroConnectionManager>}
Check the current connection. If disconnected and auto switch enabled, switches to best available connection.
Returns:
this connection manager for chaining
- Type
- Promise.<MoneroConnectionManager>
checkConnectionPromises() → {Array.<Promise>}
Check all managed connections, returning a promise for each connection check.
Does not auto switch if disconnected.
Returns:
a promise for each connection in the order of getConnections().
- Type
- Array.<Promise>
(async) checkConnections() → {Promise.<MoneroConnectionManager>}
Check all managed connections.
Returns:
this connection manager for chaining
- Type
- Promise.<MoneroConnectionManager>
clear() → {MoneroConnectonManager}
Remove all connections.
Returns:
this connection manager for chaining
- Type
- MoneroConnectonManager
disconnect() → {MoneroConnectionManager}
Disconnect from the current connection.
Returns:
this connection manager for chaining
getAutoSwitch() → {boolean}
Get if auto switch is enabled or disabled.
Returns:
true if auto switch enabled, false otherwise
- Type
- boolean
(async) getBestAvailableConnection(excludedConnections) → {Promise.<MoneroRpcConnection>}
Get the best available connection in order of priority then response time.
Parameters:
Name | Type | Description |
---|---|---|
excludedConnections |
Array.<MoneroRpcConnection> | connections to be excluded from consideration (optional) |
Returns:
the best available connection in order of priority then response time, undefined if no connections available
- Type
- Promise.<MoneroRpcConnection>
getConnection() → {MoneroRpcConnection}
Get the current connection.
Returns:
the current connection or undefined if no connection set
- Type
- MoneroRpcConnection
getConnectionByUri(uri) → {MoneroRpcConnection}
Get a connection by URI.
Parameters:
Name | Type | Description |
---|---|---|
uri |
string | is the URI of the connection to get |
Returns:
the connection with the URI or undefined if no connection with the URI exists
- Type
- MoneroRpcConnection
getConnections() → {Array.<MoneroRpcConnection>}
Get all connections in order of current connection (if applicable), online status, priority, and name.
Returns:
the list of sorted connections
- Type
- Array.<MoneroRpcConnection>
(async) getPeerConnections() → {Array.<MoneroRpcConnection>}
Collect connectable peers of the managed connections.
Returns:
connectable peers
- Type
- Array.<MoneroRpcConnection>
getTimeout() → {int}
Get the request timeout.
Returns:
the request timeout before a connection is considered offline
- Type
- int
isConnected() → {boolean}
Indicates if the connection manager is connected to a node.
Returns:
true if the current connection is set, online, and not unauthenticated. false otherwise
- Type
- boolean
(async) removeConnection(uri) → {Promise.<MoneroConnectionManager>}
Remove a connection.
Parameters:
Name | Type | Description |
---|---|---|
uri |
string | of the the connection to remove |
Returns:
this connection manager for chaining
- Type
- Promise.<MoneroConnectionManager>
removeListener(listener) → {MoneroConnectionManager}
Remove a listener.
Parameters:
Name | Type | Description |
---|---|---|
listener |
MoneroConnectionManagerListener | the listener to remove |
Returns:
this connection manager for chaining
removeListeners() → {MoneroConnectionManager}
Remove all listeners.
Returns:
this connection manager for chaining
reset() → {MoneroConnectonManager}
Reset to default state.
Returns:
this connection manager for chaining
- Type
- MoneroConnectonManager
setAutoSwitch(autoSwitch) → {MoneroConnectionManager}
Automatically switch to best available connection if current connection is disconnected after being checked.
Parameters:
Name | Type | Description |
---|---|---|
autoSwitch |
boolean | specifies if the connection should switch on disconnect |
Returns:
this connection manager for chaining
setConnection(uriOrConnection) → {MoneroConnectionManager}
Set the current connection.
Provide a URI to select an existing connection without updating its credentials.
Provide a MoneroRpcConnection to add new connection or update credentials of existing connection with same URI.
Notify if current connection changes.
Does not check the connection.
Parameters:
Name | Type | Description |
---|---|---|
uriOrConnection |
string | MoneroRpcConnection | is the uri of the connection or the connection to make current (default undefined for no current connection) |
Returns:
this connection manager for chaining
setTimeout(timeoutInMs) → {MoneroConnectionManager}
Set the maximum request time before its connection is considered offline.
Parameters:
Name | Type | Description |
---|---|---|
timeoutInMs |
int | the timeout before the connection is considered offline |
Returns:
this connection manager for chaining
(async) startCheckingConnection(periodMs) → {Promise.<MoneroConnectionManager>}
Check the connection and start checking the connection periodically.
Parameters:
Name | Type | Description |
---|---|---|
periodMs |
number | is the time between checks in milliseconds (default 10000 or 10 seconds) |
Returns:
this connection manager for chaining (after first checking the connection)
- Type
- Promise.<MoneroConnectionManager>
stopCheckingConnection() → {MoneroConnectionManager}
Stop checking the connection status periodically.
Returns:
this connection manager for chaining