Class NetworkTablesTopic<T>

Type Parameters

Constructors

  • Creates a new topic. This should only be done after the base NTCore client has been initialized.

    Type Parameters

    • T extends
          | string
          | number
          | boolean
          | string[]
          | ArrayBuffer
          | boolean[]
          | number[]

    Parameters

    • client: PubSubClient

      The client that owns the topic.

    • name: string

      The name of the topic.

    • typeInfo: NetworkTablesTypeInfo

      The type info for the topic.

    • OptionaldefaultValue: T

      The default value for the topic.

    Returns NetworkTablesTopic<T>

Accessors

  • get subscribers(): Map<number, {
        callback: ((_: null | T) => void);
        immediateNotify: boolean;
        options: {
            all?: boolean;
            periodic?: number;
            prefix?: boolean;
            topicsonly?: boolean;
        };
    }>
  • Gets the subscribers to the topic.

    Returns Map<number, {
        callback: ((_: null | T) => void);
        immediateNotify: boolean;
        options: {
            all?: boolean;
            periodic?: number;
            prefix?: boolean;
            topicsonly?: boolean;
        };
    }>

    The subscribers to the topic.

Methods

  • Marks the topic as announced. This should only be called by the PubSubClient.

    Parameters

    • id: number

      The ID of the topic.

    • Optionalpubuid: number

      The UID of the publisher.

    Returns void

  • Publishes the topic.

    Parameters

    • properties: {
          cached?: boolean;
          persistent?: boolean;
          retained?: boolean;
      } = {}

      The properties to publish the topic with.

      • Optionalcached?: boolean
      • Optionalpersistent?: boolean
      • Optionalretained?: boolean
    • Optionalid: number

      The UID of the publisher.

    Returns Promise<void | {
        method: "announce";
        params: {
            id: number;
            name: string;
            properties: {
                cached?: boolean;
                persistent?: boolean;
                retained?: boolean;
            };
            pubuid?: number;
            type:
                | "string"
                | "boolean"
                | "float"
                | "double"
                | "int"
                | "json"
                | "raw"
                | "rpc"
                | "msgpack"
                | "protobuf"
                | "boolean[]"
                | "double[]"
                | "int[]"
                | "float[]"
                | "string[]";
        };
    }>

    A promise that resolves when the topic is published.

  • Republishes the topic.

    Parameters

    • client: PubSubClient

      The client to republish with.

    Returns Promise<void | {
        method: "announce";
        params: {
            id: number;
            name: string;
            properties: {
                cached?: boolean;
                persistent?: boolean;
                retained?: boolean;
            };
            pubuid?: number;
            type:
                | "string"
                | "boolean"
                | "float"
                | "double"
                | "int"
                | "json"
                | "raw"
                | "rpc"
                | "msgpack"
                | "protobuf"
                | "boolean[]"
                | "double[]"
                | "int[]"
                | "float[]"
                | "string[]";
        };
    }>

    A promise that resolves when the topic is republished.

  • Sets the properties of the topic.

    Parameters

    • Optionalpersistent: boolean

      If true, the last set value will be periodically saved to persistent storage on the server and be restored during server startup. Topics with this property set to true will not be deleted by the server when the last publisher stops publishing.

    • Optionalretained: boolean

      Topics with this property set to true will not be deleted by the server when the last publisher stops publishing.

    Returns Promise<{
        method: "properties";
        params: {
            ack: boolean;
            name: string;
        };
    }>

    The server's response.

  • Creates a new subscriber. This should only be called by the PubSubClient.

    Parameters

    • callback: ((_: null | T) => void)

      The callback to call when the topic value changes.

        • (_): void
        • Parameters

          • _: null | T

          Returns void

    • immediateNotify: boolean = false

      Whether to immediately notify the subscriber of the current value.

    • options: {
          all?: boolean;
          periodic?: number;
          prefix?: boolean;
          topicsonly?: boolean;
      } = {}

      The options for the subscriber.

      • Optionalall?: boolean
      • Optionalperiodic?: number
      • Optionalprefix?: boolean
      • Optionaltopicsonly?: boolean
    • Optionalid: number

      The UID of the subscriber.

    • save: boolean = true

      Whether to save the subscriber.

    Returns number

    The UID of the subscriber.

  • Removes a subscriber

    Parameters

    • subuid: number

      The UID of the subscriber.

    • removeCallback: boolean = true

      Whether to remove the callback. Leave this as true unless you know what you're doing.

    Returns void

  • Updates the value of the topic. This should only be called by the PubSubClient.

    Parameters

    • value: T

      The value to update.

    • lastChangedTime: number

      The server time of the last value change.

    Returns void