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).

110 lines (109 loc) 4.22 kB
import { NetworkTablesBaseTopic } from './base-topic'; import type { CallbackFn } from './base-topic'; import type { PubSubClient } from './pubsub'; import type { AnnounceMessage, AnnounceMessageParams, NetworkTablesTypeInfo, NetworkTablesTypes, SubscribeOptions, TopicProperties } from '../types/types'; export declare class NetworkTablesTopic<T extends NetworkTablesTypes> extends NetworkTablesBaseTopic<T> { readonly type = "regular"; private value; private readonly _typeInfo; private _publisher; private _pubuid?; private _publishProperties?; /** * Gets the type info for the topic. * @returns The type info for the topic. */ get typeInfo(): NetworkTablesTypeInfo; /** * Gets whether the client is the publisher of the topic. * @returns Whether the client is the publisher of the topic. */ get publisher(): boolean; /** * Gets the UID of the publisher. * @returns The UID of the publisher, or undefined if the client is not the publisher. */ get pubuid(): number | undefined; /** * Creates a new topic. This should only be done after the * base NTCore client has been initialized. * @param client - The client that owns the topic. * @param name - The name of the topic. * @param typeInfo - The type info for the topic. * @param defaultValue - The default value for the topic. */ constructor(client: PubSubClient, name: string, typeInfo: NetworkTablesTypeInfo, defaultValue?: T); /** * Sets the value of the topic. * The client must be the publisher of the topic to set the value. * @param value - The value to set. */ setValue(value: T): void; /** * Gets the value of the topic. * @returns The value of the topic. */ getValue(): T | null; /** * Updates the value of the topic. * This should only be called by the PubSubClient. * @param value - The value to update. * @param lastChangedTime - The server time of the last value change. */ updateValue(value: T, lastChangedTime: number): void; /** */ /** */ /** * Marks the topic as announced. This should only be called by the PubSubClient. * @param params - The parameters of the announcement. */ announce(params: AnnounceMessageParams): void; /** */ /** */ /** * Creates a new subscriber. * @param callback - The callback to call when the topic value changes. * @param options - The options for the subscriber. * @param id - The UID of the subscriber. You must verify that the ID is not already in use. * @param save - Whether to save the subscriber. * @returns The UID of the subscriber. */ subscribe(callback: CallbackFn<T>, options?: Omit<SubscribeOptions, 'prefix'>, id?: number, save?: boolean): number; resubscribeAll(client: PubSubClient): void; /** * Notifies all subscribers of the current value. */ private notifySubscribers; /** */ /** */ /** * Publishes the topic. * @param properties - The properties to publish the topic with. * @param id - The UID of the publisher. You must verify that the ID is not already in use. * @returns A promise that resolves when the topic is published. */ publish(properties?: TopicProperties, id?: number): Promise<AnnounceMessage | void>; /** * Unpublishes the topic. */ unpublish(): void; /** * Republishes the topic. * @param client - The client to republish with. * @returns A promise that resolves when the topic is republished. */ republish(client: PubSubClient): Promise<void | { params: { 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; }; method: "announce"; }>; }