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

96 lines (95 loc) 3.92 kB
import type { NetworkTablesPrefixTopic } from './prefix-topic'; import type { PubSubClient } from './pubsub'; import type { NetworkTablesTopic } from './topic'; import type { AnnounceMessageParams, NetworkTablesTypes, PropertiesMessage, SubscribeOptions } from '../types/types'; export type CallbackFn<T extends NetworkTablesTypes> = (value: T | null, params: AnnounceMessageParams) => void; export declare abstract class NetworkTablesBaseTopic<T extends NetworkTablesTypes> { protected abstract readonly type: 'regular' | 'prefix'; protected client: PubSubClient; private _id?; private readonly _name; protected _lastChangedTime?: number; protected _announceParams: AnnounceMessageParams | null; private _subscribers; isRegular(): this is NetworkTablesTopic<NetworkTablesTypes>; isPrefix(): this is NetworkTablesPrefixTopic; /** * Gets the ID of the topic. * @returns The ID of the topic. */ get id(): number | undefined; /** * Gets the name of the topic. * @returns The name of the topic. */ get name(): string; /** * Gets the server time of the last value change. * @returns The server time of the last value change. */ get lastChangedTime(): number | undefined; /** * Whether the topic has been announced. * @returns Whether the topic has been announced. */ get announced(): boolean; /** * Gets the subscribers to the topic. * @returns The subscribers to the topic. */ get subscribers(): Map<number, { callback: CallbackFn<T>; options: SubscribeOptions; }>; /** * 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. */ constructor(client: PubSubClient, name: string); /** */ /** */ /** * Marks the topic as announced. This should only be called by the PubSubClient. * @param params - The parameters of the announcement. */ announce(params: AnnounceMessageParams): void; /** Marks the topic as unannounced. This should only be called by the PubSubClient. */ unannounce(): void; /** */ /** */ /** * Creates a new subscriber. This should only be called by the PubSubClient. * @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. * @param save - Whether to save the subscriber. * @returns The UID of the subscriber. */ abstract subscribe(callback: CallbackFn<T>, options?: SubscribeOptions, id?: number, save?: boolean): number; /** * Resubscribes all local subscribers. * @param client - The client to resubscribe with. */ abstract resubscribeAll(client: PubSubClient): void; /** * Removes a subscriber * @param subuid - The UID of the subscriber. * @param removeCallback - Whether to remove the callback. Leave this as true unless you know what you're doing. */ unsubscribe(subuid: number, removeCallback?: boolean): void; /** * Removes all local subscribers. */ unsubscribeAll(): void; /** */ /** */ /** * Sets the properties of the topic. * @param persistent - 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. * @param retained - Topics with this property set to true will not be deleted by the server when the last publisher stops publishing. * @returns The server's response. */ setProperties(persistent?: boolean, retained?: boolean): Promise<PropertiesMessage>; }