Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DefaultServerChooser

This is a simple server chooser that implements the ServerChooser interface. It keeps a list of AMPS instance URIs and Authenticators, and advances to the next one when a failure occurs. You can add any number of URIs to the DefaultServerChooser.

To use the DefaultServerChooser, you add the URIs for the server to choose from, then set the chooser to the Client:

const chooser = new DefaultServerChooser();
chooser.add('wss://server:9005/amps/nvfix');
chooser.add('wss://server-two:9005/amps/nvfix');

const client = new Client('showchooser');
client.serverChooser(chooser);

await client.connect();

Hierarchy

  • DefaultServerChooser

Implements

Index

Constructors

constructor

Methods

add

  • This method adds a URI and an optional authenticator for Client to choose from.

    chooser.add('wss://server:9005/amps/json');
    chooser.add('wss://another_server:9006/amps/json', myAuthenticator);

    Parameters

    • uri: string

      The URI of the server.

    • Default value authenticator: Authenticator = null

      The authenticator object for custom authentication scenarios.

    Returns DefaultServerChooser

    The server chooser object.

addAll

  • This method allows to add as many server choosers as needed. The arguments can be either uri strings or objects that contain uri key, and optionally, the authenticator key.

    chooser.addAll(
        'wss://server:9005/amps/json',
        {uri: 'wss://extra_server:9007/amps/json'},
        {uri: 'wss://another_server:9003/amps/json', authenticator: myAuthenticator}
    );

    Parameters

    • Rest ...options: Array<string | ChooserItem>

      either uri strings or objects that contain uri key, and optionally, the authenticator key.

    Returns DefaultServerChooser

    The server chooser object.

getCurrentAuthenticator

getCurrentURI

  • getCurrentURI(): string
  • This method returns the current URI chosen. If no URI was chosen yet, returns null.

    Returns string

    The current URI chosen (if any).

getError

  • getError(): string
  • This method provides additional detail to be included in an exception thrown by when the AMPS instance(s) are not available. Called by the Client when creating an exception.

    Returns string

    A string with information about the connection that failed and the reason for the failure. When no further information is available, returns an empty string.

reportFailure

  • reportFailure(error: Error, connectionInfo: any): void
  • This method is invoked by the Client to indicate a connection failure occurred.

    Parameters

    • error: Error

      An error object containing an error message.

    • connectionInfo: any

      An object of properties associated with the failed connection.

    Returns void

reportSuccess

  • reportSuccess(connectionInfo: any): void
  • This method is invoked by the Client to indicate a connection attempt was successful.

    Parameters

    • connectionInfo: any

      An object of properties associated with the successful connection.

    Returns void