ntcore-ts-client
    Preparing search index...

    Class NetworkTablesTopic<T>

    Type Parameters

    Hierarchy

    • NetworkTablesBaseTopic<T>
      • NetworkTablesTopic
    Index

    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>

    Properties

    _announceParams:
        | null
        | {
            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[]";
        }
    _lastChangedTime?: number
    client: PubSubClient
    type: "regular" = 'regular'

    Accessors

    • get subscribers(): Map<
          number,
          {
              callback: CallbackFn<T>;
              options: {
                  all?: boolean;
                  periodic?: number;
                  prefix?: boolean;
                  topicsonly?: boolean;
              };
          },
      >

      Gets the subscribers to the topic.

      Returns Map<
          number,
          {
              callback: CallbackFn<T>;
              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

      • 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[]";
        }

        The parameters of the announcement.

      Returns void

    • Publishes the topic.

      Parameters

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

        The properties to publish the topic with.

      • Optionalid: number

        The UID of the publisher. You must verify that the ID is not already in use.

      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.

      Parameters

      • callback: CallbackFn<T>

        The callback to call when the topic value changes.

      • options: Omit<
            {
                all?: boolean;
                periodic?: number;
                prefix?: boolean;
                topicsonly?: boolean;
            },
            "prefix",
        > = {}

        The options for the subscriber.

      • Optionalid: number

        The UID of the subscriber. You must verify that the ID is not already in use.

      • 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