diff --git a/docs/assets/search.js b/docs/assets/search.js index 1c94db0..54d515b 100644 --- a/docs/assets/search.js +++ b/docs/assets/search.js @@ -1 +1 @@ -window.searchData = "data:application/octet-stream;base64,H4sIAAAAAAAAE82cW2/bxhKA/4vy6jjh3um3pH0xcNoGTdqXwAhoiXYIy5RAUukxjPz3wyUpcYackXgrcJ4MmnPb/WZ2hze9rrLdP/nq5uvr6ilJN6ubQLirVRo9x6ub1e9x8c8ue/oS3W/jfHW1OmTb8r/rbZTncf4Onb3+XjxvS5HmZCm2+nl1svleqJPRb0maF1G6HmTxDZJujRf55m2Sv91nyY+oiMtT+yiL06IXcxuDeK/agT3GxW1j9+PLlzh6HhIKpQSGOyuGv/68HR1CrTMuAh2IUwDrXWkqO6yLXTbENxafgwKlwyFLhnivxRbzut9lxRC3jdxifr+tt4kXH5L5J9FZaW9EoFr/w90T3qek+PDEnpLOyNv6e5Q+xgMdQuF5I/w0MJVa0Rn+kvzP3f2u+GWXpvG6iDdDHBM6i0WQpI/jQ6iVZsQQbTbI3i79T5IXcRoPWsjOao+LymgtTVvc34qXfTwvhGv+1Nvg+uRhQJhnLJ05xRZXFpcrzpfdPlkPKi8kPm5S2Q5kgPdK5GwvMmkHbM2y2yA7sjpqZj8Ysh5D55O3hLNRfEsuLCQghFp2Yf/V38ERNNILx+Ar6zZ92A2PA2gsG8uPaHsYPh9H6YXno7RW/FLtkpsvyRg8fcWFI4vSdHcoW+ARSQtVFo5mf7jfJvn3S3sPjAaqLB/NYUw1n+T/nVn5lO32cVYkly72iNlBqrOjG79Tnw2p2YnfihF7wDUxMu7yJM7yakMevjWcifEamZsR7rH/YKLO4iJK0jFleSZmYOzfixgoPCf5pIRo9P5vEtTHM6pP7E1dNSJuwvLDfb7Okvsyo4ZHh5VmT1XnmnbEcpeMSSfe46h2pdetTPU6ukEh+5Op3qe2A+e6gamxjG8A6P1/qv/xWz6948/wP2aTJ/b4qZ6nlD9X/cNjgBeieVz8Pao9BgpzfT+O9f24nO/DflO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ARf3pLhgCqLeAQ/gYF8f17f6lqH5xA5QAqIAh+p05BOs4twOU6vXvP4Cw4dLKDbnU6zgD6xM346VScz8cTDfgrLjSxOuRBAFKLqmTHK4LuDYDMK8BN7HYQPWIFVgAUxtwc/sU+Sdb980zUZCjwL3j8uLp/viAHdQjzG4u7qNiVD9WA25BzI5bxp82zUN14BWQdexYa72+U1BOjttznpLjY3SgCPLCcXlxVOy7BSuX49LxKW8enQM9kFqOS61Gr+8U1HvILVlnehIJ5kpyc0VtFWCwhhtst5WRIAkll4Rp/cyzqH++AGgDONxAkW5/bQQbQ8AlIzZBtAgajFyzI6es4F0SBOO4Fa9nBpsA7CzHrn4vnmmUFChuzRU3/MoVbBMgfsnx6C7zIFk5/G0bSWUdGLHhRtyzQLQoYFmyXCac3mEH8wWWJc0tS2QrLsHQFTtdtSYxcA1nbph6f9QGGLFnjHRacQlIKy5TwSv/IGqwsmluZQPfkET+GxIw28Cx5h0fv2cGuQnSWnKK9esB3fXQwZaC2wLysoEhr3Y0WOA0l+FIm2INojdcUVJGCOLAlD1jqtchSTANikt08CEUgAZ7Wa5ET5rU8IFrc9E1P3Rgxl40szu+Xw8MgP3GsJnAXICCeVfcvFf7Ey41B/RCLuhKj84/CyrccRVObWoStu3VglheenAV6w2kB3TRoAF1zVGvNrBe+6OBa82txfCjQ5BrQFVdVqU2FGDBDLZAbCig8C1X+OCjLDB8kGaaS7OTJlUvYJU03GLXNUDUC7yTxpuhax60RIpriYBud50HWau5rAXqFEew0xgub/smCJAAh2VxVN//9i8rQRCKDQJfwcJmktHo+RHAj5BNsZJJd3e12if7eFtukKubr3c/f/4PS7oy4ZdUAAA="; \ No newline at end of file +window.searchData = "data:application/octet-stream;base64,H4sIAAAAAAAAE82cWW/bSBKA/4vyqjhhX2z6LZl5MbA7G0wy82IYAS3RDmGZEkjKs4aR/75sHmIVWSXxGsw+GTTr6v6quouX3lbp/q9sdX37tnqKk+3q2hN2vUrC52h1vfotyv/ap0/fwvtdlK3Wq2O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pwFXU07Z+qwDoAUKWI1Tr9Z2CGgi4ZHqKm/cIgCJgZDnIjWLfLVi5Ao7wU1a/OwD0AFfLrZe1Xt8pWHwCLinOtEQSAFIcIGqrgH0fN9huJyXh4sCNNKke+ubVj28AbZCIXKBIt782gpg9Di82QTQYGlgx7MgpK3iXBGuX5Rb5nhlsAuS55fK8+jCAabM0mFPNFTf8RhtsE2AaJMeju8yDgLmibvsyKuuAAZ8bcc8C0aKArLds8M1L/GC+wLKk2RFQjbwE06W4rKk1iYFrUOaGK3Os3h+1AUb8M0Y6jbwEaopTA988gKhBvWuu3sFHNKH7iAZs06BENFci7df4IDdBxJJLk+r9iO56GADCAbdGZEUDQ14+aLDLam6XRdpUkoOiNFxRUkaIPAem/DOm+h0SUFSsYvslGNAEJarZuW80qeEDAoarsa4BYujAjH/RzL75wADEAZoBw2YCc/kKMldxmVvuT7jUAjDtARd0qUfnnw8vRbhSpTY1CRJX1jeSAq5inYHkiC4aNFzZOerlBtZrfzRYiw23FsNvP0GuwesmrtxaVSrZgHP/snM+20AkPh8JtUaCNNNcmp00qa0B5Jrhcq1rgNgcgBmfN0PXPNjcNLe5Ad3uOg+yVnNZC9QpjmCnMVze9k0QIAEOn8VRfobdXzSBrmJ18RUsvN/EaPT8CLC0ifpub0Am3d16dYgP0a7YIFfXt3c/f/4P+tk201VXAAA="; \ No newline at end of file diff --git a/docs/classes/NetworkTables.html b/docs/classes/NetworkTables.html index 415183e..02e8e61 100644 --- a/docs/classes/NetworkTables.html +++ b/docs/classes/NetworkTables.html @@ -1,5 +1,5 @@ NetworkTables | ntcore-ts-client

NetworkTables class for interacting with NetworkTables over a WebSocket connection.

-

Hierarchy

  • NetworkTables

Constructors

Hierarchy

  • NetworkTables

Constructors

Properties

_client port uri @@ -17,36 +17,36 @@

Constructors

Properties

_client: PubSubClient

The PubSubClient instance used to establish and manage the connection to the robot.

-
port: number
uri: string

The URI of the server.

-
_instances: Map<string, NetworkTables> = ...

The instance of the NetworkTables class.

-

Accessors

Properties

_client: PubSubClient

The PubSubClient instance used to establish and manage the connection to the robot.

+
port: number
uri: string

The URI of the server.

+
_instances: Map<string, NetworkTables> = ...

The instance of the NetworkTables class.

+

Accessors

Methods

Methods

  • Adds a listener for robot connection status updates.

    Parameters

    • callback: ((_) => void)

      The callback to call when the connection status changes.

        • (_): void
        • Parameters

          • _: boolean

          Returns void

    • Optional immediateNotify: boolean

      Whether to immediately notify the callback of the current connection status.

      -

    Returns (() => boolean)

    A function to remove the listener.

    -
      • (): boolean
      • Returns boolean

  • Creates a new topic.

    +

Returns (() => void)

A function to remove the listener.

+
    • (): void
    • Returns void

Generated using TypeDoc

\ No newline at end of file +

Generated using TypeDoc

\ No newline at end of file diff --git a/docs/classes/NetworkTablesTopic.html b/docs/classes/NetworkTablesTopic.html index f3bd342..b39fa3e 100644 --- a/docs/classes/NetworkTablesTopic.html +++ b/docs/classes/NetworkTablesTopic.html @@ -1,8 +1,9 @@ -NetworkTablesTopic | ntcore-ts-client

Class NetworkTablesTopic<T>

Type Parameters

Hierarchy

  • NetworkTablesTopic

Constructors

constructor +NetworkTablesTopic | ntcore-ts-client

Class NetworkTablesTopic<T>

Type Parameters

Hierarchy

  • NetworkTablesTopic

Constructors

Properties

Methods

Methods

  • name: string

    The name of the topic.

  • typeInfo: NetworkTablesTypeInfo

    The type info for the topic.

  • Optional defaultValue: T

    The default value for the topic.

    -
  • Returns NetworkTablesTopic<T>

    Properties

    _announced: boolean
    _id?: number
    _lastChangedTime?: number
    _name: string
    _publishPromise?: ((value?) => void)

    Type declaration

      • (value?): void
      • Parameters

        • Optional value: void | PromiseLike<void>

        Returns void

    _publishProperties?: {
        persistent?: boolean;
        retained?: boolean;
    }

    Type declaration

    • Optional persistent?: boolean
    • Optional retained?: boolean
    _publisher: boolean
    _pubuid?: number
    _subscribers: Map<number, {
        callback: ((_) => void);
        immediateNotify: boolean;
        options: {
            all?: boolean;
            periodic?: number;
            prefix?: boolean;
            topicsonly?: boolean;
        };
    }>

    Type declaration

    • callback: ((_) => void)
        • (_): void
        • Parameters

          • _: null | T

          Returns void

    • immediateNotify: boolean
    • options: {
          all?: boolean;
          periodic?: number;
          prefix?: boolean;
          topicsonly?: boolean;
      }
      • Optional all?: boolean
      • Optional periodic?: number
      • Optional prefix?: boolean
      • Optional topicsonly?: boolean
    client: PubSubClient
    value: null | T

    Accessors

    • get announced(): boolean
    • Whether the topic has been announced.

      +

    Returns NetworkTablesTopic<T>

    Properties

    _announced: boolean
    _id?: number
    _lastChangedTime?: number
    _name: string
    _propertyPromise?: ((value?) => void)

    Type declaration

      • (value?): void
      • Parameters

        • Optional value: void | PromiseLike<void>

        Returns void

    _publishPromise?: ((value?) => void)

    Type declaration

      • (value?): void
      • Parameters

        • Optional value: void | PromiseLike<void>

        Returns void

    _publishProperties?: {
        persistent?: boolean;
        retained?: boolean;
    }

    Type declaration

    • Optional persistent?: boolean
    • Optional retained?: boolean
    _publisher: boolean
    _pubuid?: number
    _subscribers: Map<number, {
        callback: ((_) => void);
        immediateNotify: boolean;
        options: {
            all?: boolean;
            periodic?: number;
            prefix?: boolean;
            topicsonly?: boolean;
        };
    }>

    Type declaration

    • callback: ((_) => void)
        • (_): void
        • Parameters

          • _: null | T

          Returns void

    • immediateNotify: boolean
    • options: {
          all?: boolean;
          periodic?: number;
          prefix?: boolean;
          topicsonly?: boolean;
      }
      • Optional all?: boolean
      • Optional periodic?: number
      • Optional prefix?: boolean
      • Optional topicsonly?: boolean
    client: PubSubClient
    value: null | T

    Accessors

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

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

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

      The subscribers to the topic.

      -

    Methods

    Methods

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

      Parameters

      • id: number

        The ID of the topic.

      • Optional pubuid: number

        The UID of the publisher.

        -

      Returns void

    • Publishes the topic.

      +

    Returns void

    Returns void

    Returns void

    Returns Promise<void>

    Returns void

    Returns void

    Generated using TypeDoc

    \ No newline at end of file +

    Returns void

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/classes/NetworkTablesTypeInfos.html b/docs/classes/NetworkTablesTypeInfos.html index 1d3b21b..52aa50e 100644 --- a/docs/classes/NetworkTablesTypeInfos.html +++ b/docs/classes/NetworkTablesTypeInfos.html @@ -1,4 +1,4 @@ -NetworkTablesTypeInfos | ntcore-ts-client

    Class NetworkTablesTypeInfos

    Hierarchy

    • NetworkTablesTypeInfos

    Constructors

    constructor +NetworkTablesTypeInfos | ntcore-ts-client

    Class NetworkTablesTypeInfos

    Hierarchy

    • NetworkTablesTypeInfos

    Constructors

    Properties

    kArrayBuffer: NetworkTablesTypeInfo = ...
    kBoolean: NetworkTablesTypeInfo = ...
    kBooleanArray: NetworkTablesTypeInfo = ...
    kDouble: NetworkTablesTypeInfo = ...
    kDoubleArray: NetworkTablesTypeInfo = ...
    kInteger: NetworkTablesTypeInfo = ...
    kIntegerArray: NetworkTablesTypeInfo = ...
    kString: NetworkTablesTypeInfo = ...
    kStringArray: NetworkTablesTypeInfo = ...

    Generated using TypeDoc

    \ No newline at end of file +

    Constructors

    Properties

    kArrayBuffer: NetworkTablesTypeInfo = ...
    kBoolean: NetworkTablesTypeInfo = ...
    kBooleanArray: NetworkTablesTypeInfo = ...
    kDouble: NetworkTablesTypeInfo = ...
    kDoubleArray: NetworkTablesTypeInfo = ...
    kInteger: NetworkTablesTypeInfo = ...
    kIntegerArray: NetworkTablesTypeInfo = ...
    kString: NetworkTablesTypeInfo = ...
    kStringArray: NetworkTablesTypeInfo = ...

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/interfaces/BinaryMessageData.html b/docs/interfaces/BinaryMessageData.html index cf91eab..c3e32f4 100644 --- a/docs/interfaces/BinaryMessageData.html +++ b/docs/interfaces/BinaryMessageData.html @@ -1,5 +1,5 @@ -BinaryMessageData | ntcore-ts-client

    Interface BinaryMessageData

    Hierarchy

    • BinaryMessageData

    Properties

    serverTime +BinaryMessageData | ntcore-ts-client

    Generated using TypeDoc

    \ No newline at end of file +

    Properties

    serverTime: number
    topicId: number
    value: string | number | boolean | string[] | ArrayBuffer | boolean[] | number[]

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/AnnounceMessage.html b/docs/types/AnnounceMessage.html index 506d3c6..2d4d5c4 100644 --- a/docs/types/AnnounceMessage.html +++ b/docs/types/AnnounceMessage.html @@ -1 +1 @@ -AnnounceMessage | ntcore-ts-client

    Type alias AnnounceMessage

    AnnounceMessage: z.infer<typeof announceMessageSchema>

    Generated using TypeDoc

    \ No newline at end of file +AnnounceMessage | ntcore-ts-client

    Type alias AnnounceMessage

    AnnounceMessage: z.infer<typeof announceMessageSchema>

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/AnnounceMessageParams.html b/docs/types/AnnounceMessageParams.html index 26fd4b1..150385f 100644 --- a/docs/types/AnnounceMessageParams.html +++ b/docs/types/AnnounceMessageParams.html @@ -1 +1 @@ -AnnounceMessageParams | ntcore-ts-client

    Type alias AnnounceMessageParams

    AnnounceMessageParams: AnnounceMessage["params"]

    Generated using TypeDoc

    \ No newline at end of file +AnnounceMessageParams | ntcore-ts-client

    Type alias AnnounceMessageParams

    AnnounceMessageParams: AnnounceMessage["params"]

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/BinaryMessage.html b/docs/types/BinaryMessage.html index 409f0ab..4f620f5 100644 --- a/docs/types/BinaryMessage.html +++ b/docs/types/BinaryMessage.html @@ -1 +1 @@ -BinaryMessage | ntcore-ts-client

    Type alias BinaryMessage

    BinaryMessage: z.infer<typeof msgPackSchema>

    Generated using TypeDoc

    \ No newline at end of file +BinaryMessage | ntcore-ts-client

    Type alias BinaryMessage

    BinaryMessage: z.infer<typeof msgPackSchema>

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/Message.html b/docs/types/Message.html index f2d291c..d344922 100644 --- a/docs/types/Message.html +++ b/docs/types/Message.html @@ -1 +1 @@ -Message | ntcore-ts-client

    Type alias Message

    Generated using TypeDoc

    \ No newline at end of file +Message | ntcore-ts-client

    Type alias Message

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/NetworkTablesTypeInfo.html b/docs/types/NetworkTablesTypeInfo.html index 822f42e..56a19ed 100644 --- a/docs/types/NetworkTablesTypeInfo.html +++ b/docs/types/NetworkTablesTypeInfo.html @@ -1 +1 @@ -NetworkTablesTypeInfo | ntcore-ts-client

    Type alias NetworkTablesTypeInfo

    NetworkTablesTypeInfo: [TypeNum, TypeString]

    Generated using TypeDoc

    \ No newline at end of file +NetworkTablesTypeInfo | ntcore-ts-client

    Type alias NetworkTablesTypeInfo

    NetworkTablesTypeInfo: [TypeNum, TypeString]

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/NetworkTablesTypes.html b/docs/types/NetworkTablesTypes.html index f507c4a..e7f4fb2 100644 --- a/docs/types/NetworkTablesTypes.html +++ b/docs/types/NetworkTablesTypes.html @@ -1 +1 @@ -NetworkTablesTypes | ntcore-ts-client

    Type alias NetworkTablesTypes

    NetworkTablesTypes: z.infer<typeof msgPackValueSchema>

    Generated using TypeDoc

    \ No newline at end of file +NetworkTablesTypes | ntcore-ts-client

    Type alias NetworkTablesTypes

    NetworkTablesTypes: z.infer<typeof msgPackValueSchema>

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/PropertiesMessage.html b/docs/types/PropertiesMessage.html index a17d907..fc977bc 100644 --- a/docs/types/PropertiesMessage.html +++ b/docs/types/PropertiesMessage.html @@ -1 +1 @@ -PropertiesMessage | ntcore-ts-client

    Type alias PropertiesMessage

    PropertiesMessage: z.infer<typeof propertiesMessageSchema>

    Generated using TypeDoc

    \ No newline at end of file +PropertiesMessage | ntcore-ts-client

    Type alias PropertiesMessage

    PropertiesMessage: z.infer<typeof propertiesMessageSchema>

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/PropertiesMessageParams.html b/docs/types/PropertiesMessageParams.html index 2c29a7d..006482d 100644 --- a/docs/types/PropertiesMessageParams.html +++ b/docs/types/PropertiesMessageParams.html @@ -1 +1 @@ -PropertiesMessageParams | ntcore-ts-client

    Type alias PropertiesMessageParams

    PropertiesMessageParams: PropertiesMessage["params"]

    Generated using TypeDoc

    \ No newline at end of file +PropertiesMessageParams | ntcore-ts-client

    Type alias PropertiesMessageParams

    PropertiesMessageParams: PropertiesMessage["params"]

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/PublishMessage.html b/docs/types/PublishMessage.html index 34f5ef1..7296b84 100644 --- a/docs/types/PublishMessage.html +++ b/docs/types/PublishMessage.html @@ -1 +1 @@ -PublishMessage | ntcore-ts-client

    Type alias PublishMessage

    PublishMessage: z.infer<typeof publishMessageSchema>

    Generated using TypeDoc

    \ No newline at end of file +PublishMessage | ntcore-ts-client

    Type alias PublishMessage

    PublishMessage: z.infer<typeof publishMessageSchema>

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/PublishMessageParams.html b/docs/types/PublishMessageParams.html index 68f2938..2f0c195 100644 --- a/docs/types/PublishMessageParams.html +++ b/docs/types/PublishMessageParams.html @@ -1 +1 @@ -PublishMessageParams | ntcore-ts-client

    Type alias PublishMessageParams

    PublishMessageParams: PublishMessage["params"]

    Generated using TypeDoc

    \ No newline at end of file +PublishMessageParams | ntcore-ts-client

    Type alias PublishMessageParams

    PublishMessageParams: PublishMessage["params"]

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/SetPropertiesMessage.html b/docs/types/SetPropertiesMessage.html index 44bf0b1..901fe2d 100644 --- a/docs/types/SetPropertiesMessage.html +++ b/docs/types/SetPropertiesMessage.html @@ -1 +1 @@ -SetPropertiesMessage | ntcore-ts-client

    Type alias SetPropertiesMessage

    SetPropertiesMessage: z.infer<typeof setPropertiesMessageSchema>

    Generated using TypeDoc

    \ No newline at end of file +SetPropertiesMessage | ntcore-ts-client

    Type alias SetPropertiesMessage

    SetPropertiesMessage: z.infer<typeof setPropertiesMessageSchema>

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/SetPropertiesMessageParams.html b/docs/types/SetPropertiesMessageParams.html index 39d497a..e8301d2 100644 --- a/docs/types/SetPropertiesMessageParams.html +++ b/docs/types/SetPropertiesMessageParams.html @@ -1 +1 @@ -SetPropertiesMessageParams | ntcore-ts-client

    Type alias SetPropertiesMessageParams

    SetPropertiesMessageParams: SetPropertiesMessage["params"]

    Generated using TypeDoc

    \ No newline at end of file +SetPropertiesMessageParams | ntcore-ts-client

    Type alias SetPropertiesMessageParams

    SetPropertiesMessageParams: SetPropertiesMessage["params"]

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/SubscribeMessage.html b/docs/types/SubscribeMessage.html index 5e6fdf8..82ff1e9 100644 --- a/docs/types/SubscribeMessage.html +++ b/docs/types/SubscribeMessage.html @@ -1 +1 @@ -SubscribeMessage | ntcore-ts-client

    Type alias SubscribeMessage

    SubscribeMessage: z.infer<typeof subscribeMessageSchema>

    Generated using TypeDoc

    \ No newline at end of file +SubscribeMessage | ntcore-ts-client

    Type alias SubscribeMessage

    SubscribeMessage: z.infer<typeof subscribeMessageSchema>

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/SubscribeMessageParams.html b/docs/types/SubscribeMessageParams.html index a719488..22fc7b8 100644 --- a/docs/types/SubscribeMessageParams.html +++ b/docs/types/SubscribeMessageParams.html @@ -1 +1 @@ -SubscribeMessageParams | ntcore-ts-client

    Type alias SubscribeMessageParams

    SubscribeMessageParams: SubscribeMessage["params"]

    Generated using TypeDoc

    \ No newline at end of file +SubscribeMessageParams | ntcore-ts-client

    Type alias SubscribeMessageParams

    SubscribeMessageParams: SubscribeMessage["params"]

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/SubscribeOptions.html b/docs/types/SubscribeOptions.html index 53f74d7..c1a9cb9 100644 --- a/docs/types/SubscribeOptions.html +++ b/docs/types/SubscribeOptions.html @@ -1 +1 @@ -SubscribeOptions | ntcore-ts-client

    Type alias SubscribeOptions

    SubscribeOptions: z.infer<typeof subscriptionOptionsSchema>

    Generated using TypeDoc

    \ No newline at end of file +SubscribeOptions | ntcore-ts-client

    Type alias SubscribeOptions

    SubscribeOptions: z.infer<typeof subscriptionOptionsSchema>

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/TopicProperties.html b/docs/types/TopicProperties.html index 8548bb9..81e1eee 100644 --- a/docs/types/TopicProperties.html +++ b/docs/types/TopicProperties.html @@ -1 +1 @@ -TopicProperties | ntcore-ts-client

    Type alias TopicProperties

    TopicProperties: z.infer<typeof topicPropertiesSchema>

    Generated using TypeDoc

    \ No newline at end of file +TopicProperties | ntcore-ts-client

    Type alias TopicProperties

    TopicProperties: z.infer<typeof topicPropertiesSchema>

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/TypeNum.html b/docs/types/TypeNum.html index 7379142..55c31ec 100644 --- a/docs/types/TypeNum.html +++ b/docs/types/TypeNum.html @@ -1 +1 @@ -TypeNum | ntcore-ts-client

    Type alias TypeNum

    TypeNum: z.infer<typeof typeNumSchema>

    Generated using TypeDoc

    \ No newline at end of file +TypeNum | ntcore-ts-client

    Type alias TypeNum

    TypeNum: z.infer<typeof typeNumSchema>

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/TypeString.html b/docs/types/TypeString.html index a7663a8..7d9dd93 100644 --- a/docs/types/TypeString.html +++ b/docs/types/TypeString.html @@ -1 +1 @@ -TypeString | ntcore-ts-client

    Type alias TypeString

    TypeString: z.infer<typeof typeStringSchema>

    Generated using TypeDoc

    \ No newline at end of file +TypeString | ntcore-ts-client

    Type alias TypeString

    TypeString: z.infer<typeof typeStringSchema>

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/UnannounceMessage.html b/docs/types/UnannounceMessage.html index 57db67a..8e0167d 100644 --- a/docs/types/UnannounceMessage.html +++ b/docs/types/UnannounceMessage.html @@ -1 +1 @@ -UnannounceMessage | ntcore-ts-client

    Type alias UnannounceMessage

    UnannounceMessage: z.infer<typeof unannounceMessageSchema>

    Generated using TypeDoc

    \ No newline at end of file +UnannounceMessage | ntcore-ts-client

    Type alias UnannounceMessage

    UnannounceMessage: z.infer<typeof unannounceMessageSchema>

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/UnannounceMessageParams.html b/docs/types/UnannounceMessageParams.html index c3e33fa..c12ae99 100644 --- a/docs/types/UnannounceMessageParams.html +++ b/docs/types/UnannounceMessageParams.html @@ -1 +1 @@ -UnannounceMessageParams | ntcore-ts-client

    Type alias UnannounceMessageParams

    UnannounceMessageParams: UnannounceMessage["params"]

    Generated using TypeDoc

    \ No newline at end of file +UnannounceMessageParams | ntcore-ts-client

    Type alias UnannounceMessageParams

    UnannounceMessageParams: UnannounceMessage["params"]

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/UnpublishMessage.html b/docs/types/UnpublishMessage.html index 150ce6d..87f0810 100644 --- a/docs/types/UnpublishMessage.html +++ b/docs/types/UnpublishMessage.html @@ -1 +1 @@ -UnpublishMessage | ntcore-ts-client

    Type alias UnpublishMessage

    UnpublishMessage: z.infer<typeof unpublishMessageSchema>

    Generated using TypeDoc

    \ No newline at end of file +UnpublishMessage | ntcore-ts-client

    Type alias UnpublishMessage

    UnpublishMessage: z.infer<typeof unpublishMessageSchema>

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/UnpublishMessageParams.html b/docs/types/UnpublishMessageParams.html index 4ebc9a6..1302859 100644 --- a/docs/types/UnpublishMessageParams.html +++ b/docs/types/UnpublishMessageParams.html @@ -1 +1 @@ -UnpublishMessageParams | ntcore-ts-client

    Type alias UnpublishMessageParams

    UnpublishMessageParams: UnpublishMessage["params"]

    Generated using TypeDoc

    \ No newline at end of file +UnpublishMessageParams | ntcore-ts-client

    Type alias UnpublishMessageParams

    UnpublishMessageParams: UnpublishMessage["params"]

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/UnsubscribeMessage.html b/docs/types/UnsubscribeMessage.html index 3a6dff4..2b5171c 100644 --- a/docs/types/UnsubscribeMessage.html +++ b/docs/types/UnsubscribeMessage.html @@ -1 +1 @@ -UnsubscribeMessage | ntcore-ts-client

    Type alias UnsubscribeMessage

    UnsubscribeMessage: z.infer<typeof unsubscribeMessageSchema>

    Generated using TypeDoc

    \ No newline at end of file +UnsubscribeMessage | ntcore-ts-client

    Type alias UnsubscribeMessage

    UnsubscribeMessage: z.infer<typeof unsubscribeMessageSchema>

    Generated using TypeDoc

    \ No newline at end of file diff --git a/docs/types/UnsubscribeMessageParams.html b/docs/types/UnsubscribeMessageParams.html index b66808c..ce729fd 100644 --- a/docs/types/UnsubscribeMessageParams.html +++ b/docs/types/UnsubscribeMessageParams.html @@ -1 +1 @@ -UnsubscribeMessageParams | ntcore-ts-client

    Type alias UnsubscribeMessageParams

    UnsubscribeMessageParams: UnsubscribeMessage["params"]

    Generated using TypeDoc

    \ No newline at end of file +UnsubscribeMessageParams | ntcore-ts-client

    Type alias UnsubscribeMessageParams

    UnsubscribeMessageParams: UnsubscribeMessage["params"]

    Generated using TypeDoc

    \ No newline at end of file diff --git a/packages/ntcore-ts-client/src/lib/ntcore-ts-client.spec.ts b/packages/ntcore-ts-client/src/lib/ntcore-ts-client.spec.ts index 605124f..85eb2de 100644 --- a/packages/ntcore-ts-client/src/lib/ntcore-ts-client.spec.ts +++ b/packages/ntcore-ts-client/src/lib/ntcore-ts-client.spec.ts @@ -2,47 +2,65 @@ import { NetworkTables } from './ntcore-ts-client'; import { NetworkTablesTypeInfos } from './types/types'; describe('NetworkTables', () => { - let networkTables: NetworkTables; - beforeEach(() => { - networkTables = NetworkTables.getInstanceByTeam(973); + NetworkTables['_instances'].clear(); }); it('gets the client', () => { + const networkTables = NetworkTables.getInstanceByTeam(973); expect(networkTables.client).toBe(NetworkTables.getInstanceByTeam(973).client); const anotherClient = NetworkTables.getInstanceByTeam(9973).client; expect(anotherClient).not.toBe(networkTables.client); }); it('creates a new NetworkTables instance with the correct port number', () => { + const networkTables = NetworkTables.getInstanceByTeam(973); expect(networkTables.getPort()).toBe(5810); }); it('creates a new NetworkTables instance with the correct robot address', () => { + const networkTables = NetworkTables.getInstanceByTeam(973); expect(networkTables.getURI()).toBe('roborio-973-frc.local'); }); + it('returns the same instance when calling getInstance multiple times', () => { + const instance1 = NetworkTables.getInstanceByTeam(973); + const instance2 = NetworkTables.getInstanceByTeam(973); + expect(instance1).toBe(instance2); + }); + + it('returns the same instance when calling getInstanceByURI multiple times', () => { + const instance1 = NetworkTables.getInstanceByURI('roborio-973-frc.local'); + const instance2 = NetworkTables.getInstanceByURI('roborio-973-frc.local'); + expect(instance1).toBe(instance2); + }); + it('lets you change the URI', () => { + const networkTables = NetworkTables.getInstanceByTeam(973); networkTables.changeURI('roborio-9973-frc.local'); expect(networkTables.getURI()).toBe('roborio-9973-frc.local'); }); it('returns the correct value for isRobotConnected', () => { + const networkTables = NetworkTables.getInstanceByTeam(973); expect(networkTables.isRobotConnected()).toBe(false); }); it('returns the correct value for isRobotConnecting', () => { + const networkTables = NetworkTables.getInstanceByTeam(973); expect(networkTables.isRobotConnecting()).toBe(true); }); it('allows adding and removing robot connection listeners', () => { const spy = jest.fn(); + const networkTables = NetworkTables.getInstanceByTeam(973); const removeListener = networkTables.addRobotConnectionListener(spy, true); expect(spy).toHaveBeenCalledWith(false); removeListener(); }); it('creates a topic', () => { + const networkTables = NetworkTables.getInstanceByTeam(973); const topic = networkTables.createTopic('/foo', NetworkTablesTypeInfos.kDouble, 1.0); expect(topic).toBeDefined(); }); diff --git a/packages/ntcore-ts-client/src/lib/pubsub/pubsub.spec.ts b/packages/ntcore-ts-client/src/lib/pubsub/pubsub.spec.ts index d10e561..b056479 100644 --- a/packages/ntcore-ts-client/src/lib/pubsub/pubsub.spec.ts +++ b/packages/ntcore-ts-client/src/lib/pubsub/pubsub.spec.ts @@ -57,4 +57,28 @@ describe('PubSubClient', () => { client['onTopicUnannounce']({ name: 'test' } as never); expect(topic.unannounce).toHaveBeenCalled(); }); + + it('reinstantates topics', () => { + const topic = { + name: 'test', + publisher: true, + announce: jest.fn(), + resubscribeAll: jest.fn(), + republish: jest.fn(), + }; + const topic2 = { + name: 'test2', + publisher: true, + announce: jest.fn(), + resubscribeAll: jest.fn(), + republish: jest.fn(), + }; + client.registerTopic(topic as never); + client.registerTopic(topic2 as never); + client.reinstantiate('ws://localhost:5810'); + expect(topic.resubscribeAll).toHaveBeenCalled(); + expect(topic2.resubscribeAll).toHaveBeenCalled(); + expect(topic.republish).toHaveBeenCalled(); + expect(topic2.republish).toHaveBeenCalled(); + }); }); diff --git a/packages/ntcore-ts-client/src/lib/pubsub/pubsub.ts b/packages/ntcore-ts-client/src/lib/pubsub/pubsub.ts index 55dc5b7..3b264e9 100644 --- a/packages/ntcore-ts-client/src/lib/pubsub/pubsub.ts +++ b/packages/ntcore-ts-client/src/lib/pubsub/pubsub.ts @@ -5,6 +5,7 @@ import type { AnnounceMessageParams, BinaryMessageData, NetworkTablesTypes, + PropertiesMessageParams, UnannounceMessageParams, } from '../types/types'; @@ -24,7 +25,8 @@ export class PubSubClient { serverUrl, this.onTopicUpdate, this.onTopicAnnounce, - this.onTopicUnannounce + this.onTopicUnannounce, + this.onTopicProperties ); this.topics = new Map(); @@ -114,6 +116,22 @@ export class PubSubClient { topic.unannounce(); }; + /** + * Called by the messenger when a topic's properties are updated. + * @param params - The properties message parameters. + */ + private onTopicProperties = (params: PropertiesMessageParams) => { + const topic = this.topics.get(params.name); + if (params.ack) { + if (!topic) { + console.warn(`Topic ${params.name} properties were updated, but does not exist`); + return; + } + + topic.ackProperties(); + } + }; + /** * Updates the value of a topic on the server. * @param topic - The topic to update. diff --git a/packages/ntcore-ts-client/src/lib/pubsub/topic.spec.ts b/packages/ntcore-ts-client/src/lib/pubsub/topic.spec.ts index 2191994..daca8e2 100644 --- a/packages/ntcore-ts-client/src/lib/pubsub/topic.spec.ts +++ b/packages/ntcore-ts-client/src/lib/pubsub/topic.spec.ts @@ -1,3 +1,5 @@ +import WSMock from 'jest-websocket-mock'; + import { NetworkTablesTypeInfos } from '../types/types'; import { PubSubClient } from './pubsub'; @@ -7,9 +9,11 @@ import type { SubscribeMessageParams } from '../types/types'; describe('Topic', () => { let topic: NetworkTablesTopic; + let client: PubSubClient; + const serverUrl = 'ws://localhost:5810/nt/1234'; beforeEach(() => { - const serverUrl = 'ws://localhost:5810/nt/1234'; - const client = PubSubClient.getInstance(serverUrl); + client = PubSubClient.getInstance(serverUrl); + client.messenger.socket.stopAutoConnect(); topic = new NetworkTablesTopic(client, 'test', NetworkTablesTypeInfos.kString, 'default'); }); @@ -17,6 +21,8 @@ describe('Topic', () => { afterEach(() => { topic['client']['topics'].clear(); topic.subscribers.clear(); + topic['_publisher'] = false; + topic['_pubuid'] = undefined; }); describe('constructor', () => { @@ -54,11 +60,13 @@ describe('Topic', () => { expect(() => topic.setValue('new value')).toThrow('Cannot set value on topic without being the publisher'); }); - it('allows the value to be set if the client is the publisher', () => { - topic.publish().then(() => { - topic.setValue('new value'); - expect(topic.getValue()).toEqual('new value'); - }); + it('allows the value to be set if the client is the publisher', async () => { + setTimeout(() => { + topic.announce(1, 1); + }, 100); + await topic.publish({}, 1); + topic.setValue('new value'); + expect(topic.getValue()).toEqual('new value'); topic.announce(1); }); }); @@ -194,45 +202,54 @@ describe('Topic', () => { }); describe('publish', () => { - it('sets the publisher to the client', () => { - topic.publish().then(() => { - expect(topic.publisher).toBe(true); - expect(topic.pubuid).toBeDefined(); - }); - - topic.announce(1); + it('sets the publisher to the client', async () => { + setTimeout(() => { + topic.announce(1, 1); + }, 100); + await topic.publish({}, 1); + expect(topic.publisher).toBe(true); + expect(topic.pubuid).toBeDefined(); }); - it('does not set the publisher if the client is already the publisher', () => { - topic.publish().then(() => { - const id = topic.pubuid; - topic.publish().then(() => { - expect(id).toEqual(topic.pubuid); - }); - }); + it('does not set the publisher if the client is already the publisher', async () => { + setTimeout(() => { + topic.announce(1, 1); + }, 100); + await topic.publish({}, 1); + const id = topic.pubuid; + + await topic.publish(); + expect(id).toEqual(topic.pubuid); }); - it('should throw an error if the topic is not announced', () => { - topic - .publish() - .then(() => fail('Topic should have not been announced')) - .catch((e) => { - expect(e).toEqual(new Error(`Topic ${topic.name} was not announced within 5 seconds`)); - }); + it('should throw an error if the topic is not announced', async () => { + try { + topic = new NetworkTablesTopic(client, 'test2', NetworkTablesTypeInfos.kString, 'default'); + client.messenger.reinstantiate(serverUrl + '1'); + new WSMock(serverUrl + '1'); + await client.messenger.socket.waitForConnection(); + await topic.publish({}, 1); + fail('Topic should have not been announced'); + } catch (e) { + expect(e).toEqual(new Error(`Topic ${topic.name} was not announced within 3 seconds`)); + } }); }); describe('unpublish', () => { - it('sets the publisher to false', () => { - topic.publish().then(() => { - topic.unpublish(); - expect(topic.publisher).toBe(false); - expect(topic.pubuid).toBeUndefined(); - }); + it('sets the publisher to false', async () => { + setTimeout(() => { + topic.announce(1, 1); + }, 100); + await topic.publish({}, 1); + expect(topic.publisher).toBe(true); + topic.unpublish(); + expect(topic.publisher).toBe(false); + expect(topic.pubuid).toBeUndefined(); }); it('should throw an error if the client is not the publisher', () => { - expect(() => topic.unpublish()).toThrowError('Cannot unpublish topic without being the publisher'); + expect(() => topic.unpublish()).toThrow('Cannot unpublish topic without being the publisher'); }); }); diff --git a/packages/ntcore-ts-client/src/lib/pubsub/topic.ts b/packages/ntcore-ts-client/src/lib/pubsub/topic.ts index b2646ac..154dae7 100644 --- a/packages/ntcore-ts-client/src/lib/pubsub/topic.ts +++ b/packages/ntcore-ts-client/src/lib/pubsub/topic.ts @@ -23,6 +23,7 @@ export class NetworkTablesTopic { private _pubuid?: number; private _publishProperties?: TopicProperties; private _publishPromise?: (value?: void | PromiseLike | undefined) => void; + private _propertyPromise?: (value?: void | PromiseLike | undefined) => void; private _subscribers: Map< number, { @@ -179,6 +180,11 @@ export class NetworkTablesTopic { this._id = undefined; } + /** Called after a setProperties message is ack by the server */ + ackProperties() { + this._propertyPromise?.(); + } + /** */ /* SUBSCRIBING */ /** */ @@ -284,9 +290,9 @@ export class NetworkTablesTopic { if (this.client.messenger.socket.isConnected()) { setTimeout(() => { if (!this.announced) { - reject(new Error(`Topic ${this.name} was not announced within 5 seconds`)); + reject(new Error(`Topic ${this.name} was not announced within 3 seconds`)); } - }, 5000); + }, 3000); } }); } @@ -334,6 +340,21 @@ export class NetworkTablesTopic { }, }; - this.client.messenger.setProperties(setPropertiesParams); + return new Promise((resolve, reject) => { + // Register the promise resolver + this._propertyPromise = resolve; + + // Send the set properties request + this.client.messenger.setProperties(setPropertiesParams); + + // Set a timeout to reject the promise if the topic is not announced + if (this.client.messenger.socket.isConnected()) { + setTimeout(() => { + if (!this.announced) { + reject(new Error(`Topic ${this.name} property change was not acknowledged within 3 seconds`)); + } + }, 3000); + } + }); } } diff --git a/packages/ntcore-ts-client/src/lib/socket/messenger.ts b/packages/ntcore-ts-client/src/lib/socket/messenger.ts index af888b8..a48278c 100644 --- a/packages/ntcore-ts-client/src/lib/socket/messenger.ts +++ b/packages/ntcore-ts-client/src/lib/socket/messenger.ts @@ -14,6 +14,7 @@ import type { BinaryMessageData, AnnounceMessageParams, UnannounceMessageParams, + PropertiesMessageParams, } from '../types/types'; /** NetworkTables client. */ @@ -37,12 +38,14 @@ export class Messenger { * @param onTopicUpdate - Called when a topic is updated. * @param onAnnounce - Called when a topic is announced. * @param onUnannounce - Called when a topic is unannounced. + * @param onTopicProperties - Called when a topic's properties are updated. */ private constructor( serverUrl: string, onTopicUpdate: (_: BinaryMessageData) => void, onAnnounce: (_: AnnounceMessageParams) => void, - onUnannounce: (_: UnannounceMessageParams) => void + onUnannounce: (_: UnannounceMessageParams) => void, + onTopicProperties: (_: PropertiesMessageParams) => void ) { this._socket = NetworkTablesSocket.getInstance( serverUrl, @@ -50,7 +53,8 @@ export class Messenger { this.onSocketClose, onTopicUpdate, onAnnounce, - onUnannounce + onUnannounce, + onTopicProperties ); } @@ -60,17 +64,19 @@ export class Messenger { * @param onTopicUpdate - Called when a topic is updated. * @param onAnnounce - Called when a topic is announced. * @param onUnannounce - Called when a topic is unannounced. + * @param onTopicProperties - Called when a topic's properties are updated. * @returns The instance of the NetworkTables client. */ static getInstance( serverUrl: string, onTopicUpdate: (_: BinaryMessageData) => void, onAnnounce: (_: AnnounceMessageParams) => void, - onUnannounce: (_: UnannounceMessageParams) => void + onUnannounce: (_: UnannounceMessageParams) => void, + onTopicProperties: (_: PropertiesMessageParams) => void ): Messenger { let instance = this._instances.get(serverUrl); if (!instance) { - instance = new this(serverUrl, onTopicUpdate, onAnnounce, onUnannounce); + instance = new this(serverUrl, onTopicUpdate, onAnnounce, onUnannounce, onTopicProperties); this._instances.set(serverUrl, instance); } return instance; diff --git a/packages/ntcore-ts-client/src/lib/socket/socket.spec.ts b/packages/ntcore-ts-client/src/lib/socket/socket.spec.ts index 02bfeb4..95a2291 100644 --- a/packages/ntcore-ts-client/src/lib/socket/socket.spec.ts +++ b/packages/ntcore-ts-client/src/lib/socket/socket.spec.ts @@ -10,6 +10,8 @@ import type { AnnounceMessage, AnnounceMessageParams, BinaryMessage, + PropertiesMessage, + PropertiesMessageParams, UnannounceMessage, UnannounceMessageParams, } from '../types/types'; @@ -23,6 +25,7 @@ describe('NetworkTablesSocket', () => { const onTopicUpdate = jest.fn(); const onAnnounce = jest.fn(); const onUnannounce = jest.fn(); + const onProperties = jest.fn(); beforeEach(async () => { server = new WSMock(serverUrl); @@ -34,7 +37,8 @@ describe('NetworkTablesSocket', () => { onSocketClose, onTopicUpdate, onAnnounce, - onUnannounce + onUnannounce, + onProperties ); await server.connected; @@ -225,4 +229,20 @@ describe('NetworkTablesSocket', () => { expect(onUnannounce).toHaveBeenCalledWith(params); }); }); + + it('should call the onProperties handler for an properties message', () => { + const params: PropertiesMessageParams = { + name: 'foo', + ack: true, + }; + + const message: PropertiesMessage = { + method: 'properties', + params, + }; + + server.send(JSON.stringify([message])); + + expect(onProperties).toHaveBeenCalledWith(params); + }); }); diff --git a/packages/ntcore-ts-client/src/lib/socket/socket.ts b/packages/ntcore-ts-client/src/lib/socket/socket.ts index ba0be01..948b0c3 100644 --- a/packages/ntcore-ts-client/src/lib/socket/socket.ts +++ b/packages/ntcore-ts-client/src/lib/socket/socket.ts @@ -40,6 +40,7 @@ export class NetworkTablesSocket { private readonly onTopicUpdate: (_: BinaryMessageData) => void; private readonly onAnnounce: (_: AnnounceMessageParams) => void; private readonly onUnannounce: (_: UnannounceMessageParams) => void; + private readonly onProperties: (_: PropertiesMessageParams) => void; private autoConnect = true; private messageQueue: (string | ArrayBuffer)[] = []; @@ -52,6 +53,7 @@ export class NetworkTablesSocket { * @param onTopicUpdate - Called when a topic is updated. * @param onAnnounce - Called when a topic is announced. * @param onUnannounce - Called when a topic is unannounced. + * @param onProperties - Called when a topic's properties are updated. * @param autoConnect - Whether to automatically connect to the server. */ private constructor( @@ -61,6 +63,7 @@ export class NetworkTablesSocket { onTopicUpdate: (_: BinaryMessageData) => void, onAnnounce: (_: AnnounceMessageParams) => void, onUnannounce: (_: UnannounceMessageParams) => void, + onProperties: (_: PropertiesMessageParams) => void, autoConnect: boolean ) { // Connect to the server using the provided URL @@ -71,6 +74,7 @@ export class NetworkTablesSocket { this.onTopicUpdate = onTopicUpdate; this.onAnnounce = onAnnounce; this.onUnannounce = onUnannounce; + this.onProperties = onProperties; this.autoConnect = autoConnect; @@ -85,6 +89,7 @@ export class NetworkTablesSocket { * @param onTopicUpdate - Called when a topic is updated. * @param onAnnounce - Called when a topic is announced. * @param onUnannounce - Called when a topic is unannounced. + * @param onProperties - Called when a topic's properties are updated. * @param autoConnect - Whether to automatically connect to the server. * @returns The instance of the NetworkTables socket. */ @@ -95,11 +100,21 @@ export class NetworkTablesSocket { onTopicUpdate: (_: BinaryMessageData) => void, onAnnounce: (_: AnnounceMessageParams) => void, onUnannounce: (_: UnannounceMessageParams) => void, + onProperties: (_: PropertiesMessageParams) => void, autoConnect = true ): NetworkTablesSocket { let instance = this.instances.get(serverUrl); if (!instance) { - instance = new this(serverUrl, onSocketOpen, onSocketClose, onTopicUpdate, onAnnounce, onUnannounce, autoConnect); + instance = new this( + serverUrl, + onSocketOpen, + onSocketClose, + onTopicUpdate, + onAnnounce, + onUnannounce, + onProperties, + autoConnect + ); this.instances.set(serverUrl, instance); } @@ -201,6 +216,26 @@ export class NetworkTablesSocket { return this._websocket.readyState === WebSocket.CLOSED; } + /** + * Wait for the socket to connect. + * @returns A promise that resolves when the socket is connected. + */ + waitForConnection() { + return new Promise((resolve) => { + if (this.isConnected()) { + resolve(); + } else { + const listener = () => { + if (this.isConnected()) { + this.removeConnectionListener(listener); + resolve(); + } + }; + this.addConnectionListener(listener); + } + }); + } + /** * Create a connection listener. * @param callback - Called when the connection state changes. @@ -214,7 +249,15 @@ export class NetworkTablesSocket { callback(this.isConnected()); } - return () => this.connectionListeners.delete(callback); + return () => this.removeConnectionListener(callback); + } + + /** + * Remove a connection listener. + * @param callback - The callback to remove. + */ + removeConnectionListener(callback: (_: boolean) => void) { + this.connectionListeners.delete(callback); } /** @@ -337,11 +380,7 @@ export class NetworkTablesSocket { * @param params - The message params. */ private handlePropertiesParams(params: PropertiesMessageParams) { - // Extract the topic ID and properties from the params - // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars - const { name, ack } = params; - - // TODO: Do we need to do something with this? + this.onProperties(params); } /**