Class DirectClient

Hierarchy

Constructors

Properties

actionClient: RpcActionClient = ...
clientKernel?: RpcKernel

For server->client (us) communication. This is automatically created when registerController is called. Set this property earlier to work with a custom RpcKernel.

clientKernelConnection?: RpcKernelConnection

Once the server starts actively with first RPC action for the client, a RPC connection is created.

events: Subject<RpcClientEvent> = ...
messageId: number = 1
peerConnections: Map<string, RpcClientPeer> = ...
peerKernel?: RpcKernel

For peer->client(us) communication. This is automatically created when registerAsPeer is called. Set this property earlier to work with a custom RpcKernel.

peerKernelConnection: Map<string, RpcKernelConnection> = ...
registeredAsPeer?: string
replies: Map<number, ((message: RpcMessage) => void)> = ...
token: RpcClientToken = ...
typeReuseDisabled: boolean = false
username?: string

Methods

  • Per default entity types with a name (@entity.name()) will be reused. If a entity with a given name was not loaded and error is thrown. This to ensure nominal typing (object instanceof T). Use this method to disable this behavior and construct new nominal types if an entity is not loaded.

    Returns DirectClient

  • The connection process is only finished when this method resolves and doesn't throw. When an error is thrown, the authentication was unsuccessful.

    If you use controllers in this callback, make sure to use dontWaitForConnection=true, otherwise you get an endless loop.

    async onAuthenticate(): Promise<void> {
    const auth = this.controller<AuthController>('auth', {dontWaitForConnection: true});
    const result = auth.login('username', 'password');
    if (!result) throw new AuthenticationError('Authentication failed);
    }

    Returns Promise<void>

  • Creates a new peer connection, or re-uses an existing non-disconnected one.

    Make sure to call disconnect() on it once you're done using it, otherwise the peer will leak memory. (connection will be dropped if idle for too long automatically tough)

    Parameters

    • peerId: string

    Returns RpcClientPeer

  • Type Parameters

    • T

    Parameters

    • type: number
    • Optional body: T
    • Optional schema: ReceiveType<T>
    • options: {
          connectionId?: number;
          dontWaitForConnection?: boolean;
          peerId?: string;
          timeout?: number;
      } = {}
      • Optional connectionId?: number
      • Optional dontWaitForConnection?: boolean
      • Optional peerId?: string
      • Optional timeout?: number

    Returns RpcMessageSubject

Generated using TypeDoc