Class BaseClient<V>Abstract

Base class for TopicClient and TopicServer classes, responsible for keeping track of topics and services, and sending and receiving messages

Type Parameters

  • V = void

Hierarchy

Constructors

Properties

options: IBaseClientOptions = ...

Options

Accessors

Methods

  • Gets a promise that resolves with the server ID

    Returns

    A promise that resolves with the server ID

    Parameters

    • timeout: number = 10000

      The timeout for the request (in ms)

    Returns Promise<string>

  • Gets a promise that resolves with a topic channel's value (waits for a value before resolving)

    Returns

    A promise that resolves with the topic channel's value

    Type Parameters

    Parameters

    • channel: TopicChannel<T>

      The channel to get the value of

    • timeout: number = 100

      The timeout for the request (in ms)

    Returns Promise<T>

  • Gets a topic channel's current value

    Returns

    The current value of the topic channel

    Throws

    Error if the channel is not a topic channel, not found, or not valid

    Type Parameters

    Parameters

    Returns T

  • Checks if the topic channel is valid according to the schema

    Returns

    Whether the topic is valid

    Type Parameters

    Parameters

    • channel: Channel<T>

      The channel object

    Returns boolean

  • Lists all clients connected to the server

    Returns

    An array of client IDs

    Returns string[]

  • Publishes a new value to a topic channel by broadcasting the diff between the current value and the new value

    Type Parameters

    Parameters

    • channel: TopicChannel<T>

      The channel to publish to

    • data: RecursivePartial<T>

      The new value

    • updateSelf: boolean = true

      Whether to call the client's own topic subscribers

    • publishDeletes: boolean = true

      Whether to publish deletions of topic properties (not recommended if multiple clients are publishing to the same topic with overlapping properties)

    • Optional source: string

      Optional source of the update (Only used on TopicServer for broadcasting / forwarding messages)

    Returns void

  • Publishes a raw diff to a topic channel by broadcasting the diff

    Type Parameters

    Parameters

    • channel: TopicChannel<T>

      The channel to publish to

    • diff: DiffResult<T, T>

      The diff to publish

    • updateSelf: boolean = true

      Whether to call the client's own topic subscribers

    • Optional source: string

      Optional source of the update (Only used on TopicServer for broadcasting / forwarding messages)

    Returns void

  • Sends a service request to the specified destination

    Returns

    A promise that resolves with the response

    Type Parameters

    Parameters

    • channel: ServiceChannel<T, U>

      The channel to send the request on

    • dest: string

      The destination to send the request to

    • Optional serviceData: T

      The data to send

    • Optional timeout: number

      The timeout for the request (in ms)

    Returns Promise<U>

  • Resets all topic channels' values to an empty object

    Returns void

  • Serves a service channel by registering a handler function

    Type Parameters

    Parameters

    • channel: ServiceChannel<T, U>

      The channel object

    • handler: ((topic: T) => U | Promise<U>)

      The handler function to call when a service is requested

        • (topic: T): U | Promise<U>
        • Parameters

          • topic: T

          Returns U | Promise<U>

    Returns void

  • Subscribes to the changes of a topic channel

    Returns

    The unsubscriber function

    Type Parameters

    Parameters

    • channel: TopicChannel<T>

      The channel object

    • handler: Subscriber<T>

      The handler function to call when the topic changes

    • initialUpdate: boolean = true

      Whether to immediately call the handler with the current topic value when subscribing

    Returns Unsubscriber

  • Subscribes to the changes of a topic channel once (convenience function)

    Returns

    The unsubscriber function

    Type Parameters

    Parameters

    • channel: TopicChannel<T>

      The channel object

    • handler: Subscriber<T>

      The handler function to call when the topic changes

    • initialUpdate: boolean = true

      Whether to immediately call the handler with the current topic value when subscribing

    Returns Unsubscriber

Generated using TypeDoc