UNPKG

ntcore-ts-client

Version:

A TypeScript library for communication over [WPILib's NetworkTables 4.1 protocol](https://github.com/wpilibsuite/allwpilib/blob/main/ntcore/doc/networktables4.adoc).

97 lines (96 loc) 3.85 kB
import { Messenger } from '../socket/messenger'; import type { NetworkTablesBaseTopic } from './base-topic'; import type { NetworkTablesPrefixTopic } from './prefix-topic'; import type { NetworkTablesTopic } from './topic'; import type { NetworkTablesTypes } from '../types/types'; /** The client for the PubSub protocol. */ export declare class PubSubClient { private readonly _messenger; private readonly topics; private readonly prefixTopics; private readonly knownTopicParams; private static _instances; get messenger(): Messenger; private constructor(); /** * Gets the instance of the NetworkTables client. * @param serverUrl - The URL of the server to connect to. This is not used after the first call. * @returns The instance of the NetworkTables client. */ static getInstance(serverUrl: string): PubSubClient; /** * Reinstantiates the client by resubscribing to all previously subscribed topics * and republishing for all previously published topics. * @param url - The URL of the server to connect to. */ reinstantiate(url: string): void; /** * Registers a topic with this PubSubClient. * @param topic - The topic to register */ registerTopic<T extends NetworkTablesTypes>(topic: NetworkTablesBaseTopic<T>): void; /** * Called by the messenger when a topic is updated. * @param message - The message data. */ private onTopicUpdate; /** * Called by the messenger when a topic is announced. * @param params - The announce message parameters. */ private onTopicAnnounce; /** * Called by the messenger when a topic is unannounced. * @param params - The unannounce message parameters. */ private onTopicUnannounce; /** * Called by the messenger when a topic's properties are updated. * @param params - The properties message parameters. */ private onTopicProperties; /** * Updates the value of a topic on the server. * @param topic - The topic to update. * @param value - The new value of the topic. */ updateServer<T extends NetworkTablesTypes>(topic: NetworkTablesTopic<T>, value: T): void; /** * Gets the topic with the given ID. * @param topicId - The ID of the topic to get. * @returns The topic with the given ID, or null if no topic with that ID exists. */ private getTopicFromId; /** * Gets the topic with the given name. * @param topicName - The name of the topic to get. * @returns The topic with the given name, or null if no topic with that name exists. */ getTopicFromName(topicName: string): NetworkTablesTopic<any> | null; /** * Gets the topic with the given name. * @param topicName - The name of the topic to get. * @returns The topic with the given name, or null if no topic with that name exists. */ getPrefixTopicFromName(topicName: string): NetworkTablesPrefixTopic | null; /** * Gets the known announcement parameters for a topic. * @param id - The ID of the topic. * @returns The known announcement parameters for the topic, or undefined if the topic is not known. */ getKnownTopicParams(id: number): { type: "string" | "boolean" | "float" | "double" | "int" | "json" | "raw" | "rpc" | "msgpack" | "protobuf" | "boolean[]" | "double[]" | "int[]" | "float[]" | "string[]"; name: string; id: number; properties: { persistent?: boolean | undefined; retained?: boolean | undefined; cached?: boolean | undefined; }; pubuid?: number | undefined; } | undefined; /** * Cleans up the client by unsubscribing from all topics and stopping publishing for all topics. */ cleanup(): void; }