Skip to content

ntcore-ts / @ntcore-ts/client / NetworkTablesPrefixTopic

Class: NetworkTablesPrefixTopic ​

Defined in: pubsub/prefix-topic.ts:16

Extends ​

Constructors ​

Constructor ​

new NetworkTablesPrefixTopic(client, name): NetworkTablesPrefixTopic

Defined in: pubsub/prefix-topic.ts:32

Creates a new topic. This should only be done after the base NTCore client has been initialized.

Parameters ​

client ​

PubSubClient

The client that owns the topic.

name ​

string

The name of the topic.

Returns ​

NetworkTablesPrefixTopic

Overrides ​

NetworkTablesBaseTopic<NetworkTablesTypes>.constructor

Properties ​

_announceParams ​

protected _announceParams: { id: number; name: string; properties: {[key: string]: unknown; cached?: boolean; persistent?: boolean; retained?: boolean; }; pubuid?: number; type: string; } | null

Defined in: pubsub/base-topic.ts:24

Inherited from ​

NetworkTablesBaseTopic._announceParams


_lastChangedTime? ​

protected optional _lastChangedTime?: number

Defined in: pubsub/base-topic.ts:23

Inherited from ​

NetworkTablesBaseTopic._lastChangedTime


client ​

protected client: PubSubClient

Defined in: pubsub/base-topic.ts:20

Inherited from ​

NetworkTablesBaseTopic.client


type ​

readonly type: "prefix" = 'prefix'

Defined in: pubsub/prefix-topic.ts:17

Overrides ​

NetworkTablesBaseTopic.type

Accessors ​

announced ​

Get Signature ​

get announced(): boolean

Defined in: pubsub/base-topic.ts:69

Whether the topic has been announced.

Returns ​

boolean

Whether the topic has been announced.

Inherited from ​

NetworkTablesBaseTopic.announced


id ​

Get Signature ​

get id(): number | undefined

Defined in: pubsub/base-topic.ts:45

Gets the ID of the topic.

Returns ​

number | undefined

The ID of the topic.

Inherited from ​

NetworkTablesBaseTopic.id


lastChangedTime ​

Get Signature ​

get lastChangedTime(): number | undefined

Defined in: pubsub/base-topic.ts:61

Gets the server time of the last value change.

Returns ​

number | undefined

The server time of the last value change.

Inherited from ​

NetworkTablesBaseTopic.lastChangedTime


name ​

Get Signature ​

get name(): string

Defined in: pubsub/base-topic.ts:53

Gets the name of the topic.

Returns ​

string

The name of the topic.

Inherited from ​

NetworkTablesBaseTopic.name


subscribers ​

Get Signature ​

get subscribers(): Map<number, { callback: CallbackFn<T>; options: SubscribeOptions; }>

Defined in: pubsub/base-topic.ts:77

Gets the subscribers to the topic.

Returns ​

Map<number, { callback: CallbackFn<T>; options: SubscribeOptions; }>

The subscribers to the topic.

Inherited from ​

NetworkTablesBaseTopic.subscribers

Methods ​

addAnnounceListener() ​

addAnnounceListener(callback, options?): () => void

Defined in: pubsub/prefix-topic.ts:58

Adds a listener for subtopic announcements, including subtopics that haven't sent a value yet.

Parameters ​

callback ​

(params) => void

Called with the subtopic's announce params.

options? ​

The listener options.

immediateNotify? ​

boolean

Also call the listener right away for every matching subtopic already announced on this connection. The server announces each topic to a client only once, so a listener added after another subscription covered a subtopic needs this to see it.

Returns ​

A function to remove the listener.

() => void


addPropertiesListener() ​

addPropertiesListener(callback): () => void

Defined in: pubsub/prefix-topic.ts:86

Adds a listener for subtopic property changes.

Parameters ​

callback ​

(params) => void

Called with the properties update. Properties set to null were deleted.

Returns ​

A function to remove the listener.

() => void


addUnannounceListener() ​

addUnannounceListener(callback): () => void

Defined in: pubsub/prefix-topic.ts:74

Adds a listener for subtopic unannouncements, e.g. when a subtopic's last publisher goes away.

Parameters ​

callback ​

(params) => void

Called with the subtopic's unannounce params.

Returns ​

A function to remove the listener.

() => void


announce() ​

announce(params): void

Defined in: pubsub/prefix-topic.ts:97

Marks a subtopic as announced. This should only be called by the PubSubClient.

Parameters ​

params ​

The parameters of the announcement.

id ​

number = integerSchema

name ​

string = ...

properties ​

{[key: string]: unknown; cached?: boolean; persistent?: boolean; retained?: boolean; } = topicPropertiesSchema

properties.cached? ​

boolean = ...

properties.persistent? ​

boolean = ...

properties.retained? ​

boolean = ...

pubuid? ​

number = ...

type ​

string = typeStringSchema

Returns ​

void

Overrides ​

NetworkTablesBaseTopic.announce


getSubtopicValue() ​

getSubtopicValue(name): { params: { id: number; name: string; properties: {[key: string]: unknown; cached?: boolean; persistent?: boolean; retained?: boolean; }; pubuid?: number; type: string; }; serverTime: number; value: string | number | boolean | Uint8Array<ArrayBufferLike> | string[] | boolean[] | number[]; } | undefined

Defined in: pubsub/prefix-topic.ts:241

Gets the latest value received for a subtopic.

Parameters ​

name ​

string

The subtopic's name.

Returns ​

{ params: { id: number; name: string; properties: {[key: string]: unknown; cached?: boolean; persistent?: boolean; retained?: boolean; }; pubuid?: number; type: string; }; serverTime: number; value: string | number | boolean | Uint8Array<ArrayBufferLike> | string[] | boolean[] | number[]; } | undefined

The value and its server time, or undefined if none is cached.


isPrefix() ​

isPrefix(): this is NetworkTablesPrefixTopic

Defined in: pubsub/base-topic.ts:37

Returns ​

this is NetworkTablesPrefixTopic

Inherited from ​

NetworkTablesBaseTopic.isPrefix


isRegular() ​

isRegular(): this is NetworkTablesTopic<string | number | boolean | Uint8Array<ArrayBufferLike> | string[] | boolean[] | number[], string | number | boolean | Uint8Array<ArrayBufferLike> | string[] | boolean[] | number[]>

Defined in: pubsub/base-topic.ts:33

Returns ​

this is NetworkTablesTopic<string | number | boolean | Uint8Array<ArrayBufferLike> | string[] | boolean[] | number[], string | number | boolean | Uint8Array<ArrayBufferLike> | string[] | boolean[] | number[]>

Inherited from ​

NetworkTablesBaseTopic.isRegular


resubscribeAll() ​

resubscribeAll(client): void

Defined in: pubsub/prefix-topic.ts:205

Resubscribes all local subscribers.

Parameters ​

client ​

PubSubClient

The client to resubscribe with.

Returns ​

void

Overrides ​

NetworkTablesBaseTopic.resubscribeAll


setProperties() ​

setProperties(properties?): Promise<{ method: "properties"; params: { ack?: boolean; name: string; update: {[key: string]: unknown; cached?: boolean | null; persistent?: boolean | null; retained?: boolean | null; }; }; }>

Defined in: pubsub/base-topic.ts:197

Sets the properties of the topic.

Parameters ​

properties? ​

TopicProperties = {}

Topic properties to update (e.g. { persistent: true, retained: true }).

Returns ​

Promise<{ method: "properties"; params: { ack?: boolean; name: string; update: {[key: string]: unknown; cached?: boolean | null; persistent?: boolean | null; retained?: boolean | null; }; }; }>

The server's response.

Inherited from ​

NetworkTablesBaseTopic.setProperties


subscribe() ​

subscribe(callback, options?): number

Defined in: pubsub/prefix-topic.ts:141

Creates a new subscriber.

Parameters ​

callback ​

CallbackFn<string | number | boolean | Uint8Array<ArrayBufferLike> | string[] | boolean[] | number[]>

The callback to call when the topic value changes.

options? ​

Omit<SubscribeOptions, "prefix"> = {}

The options for the subscriber. immediateNotify is client-side only and replays cached matching subtopic values (not sent to the NT server).

Returns ​

number

The UID of the subscriber.

Overrides ​

NetworkTablesBaseTopic.subscribe


toProtocolSubscribeOptions() ​

protected toProtocolSubscribeOptions(options?): Omit<SubscribeOptions, "prefix" | "immediateNotify">

Defined in: pubsub/base-topic.ts:180

Strips client-only subscribe options (e.g. immediateNotify) before sending to the NT server.

Parameters ​

options? ​

Omit<SubscribeOptions, "prefix"> = {}

The subscriber options, possibly including client-only fields.

Returns ​

Omit<SubscribeOptions, "prefix" | "immediateNotify">

Protocol subscribe options.

Inherited from ​

NetworkTablesBaseTopic.toProtocolSubscribeOptions


unannounce() ​

unannounce(): void

Defined in: pubsub/base-topic.ts:109

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

Returns ​

void

Inherited from ​

NetworkTablesBaseTopic.unannounce


unannounceSubtopic() ​

unannounceSubtopic(params): void

Defined in: pubsub/prefix-topic.ts:106

Marks a subtopic as unannounced. This should only be called by the PubSubClient.

Parameters ​

params ​

The unannounce message parameters.

id ​

number = integerSchema

name ​

string = ...

Returns ​

void


unsubscribe() ​

unsubscribe(subuid, removeCallback?): void

Defined in: pubsub/base-topic.ts:155

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

Inherited from ​

NetworkTablesBaseTopic.unsubscribe


unsubscribeAll() ​

unsubscribeAll(): void

Defined in: pubsub/base-topic.ts:169

Removes all local subscribers.

Returns ​

void

Inherited from ​

NetworkTablesBaseTopic.unsubscribeAll


updateSubtopicProperties() ​

updateSubtopicProperties(params): void

Defined in: pubsub/prefix-topic.ts:116

Notifies listeners of a subtopic properties update. This should only be called by the PubSubClient, after it has applied the update to the subtopic's announce params.

Parameters ​

params ​

The properties message parameters.

ack? ​

boolean = ...

name ​

string = ...

update ​

{[key: string]: unknown; cached?: boolean | null; persistent?: boolean | null; retained?: boolean | null; } = topicPropertiesUpdateSchema

update.cached? ​

boolean | null = ...

update.persistent? ​

boolean | null = ...

update.retained? ​

boolean | null = ...

Returns ​

void


updateValue() ​

updateValue(params, value, serverTime): void

Defined in: pubsub/prefix-topic.ts:220

Updates the value of a subtopic. Notifies all subscribers of the change.

Parameters ​

params ​

The params of the subtopic

id ​

number = integerSchema

name ​

string = ...

properties ​

{[key: string]: unknown; cached?: boolean; persistent?: boolean; retained?: boolean; } = topicPropertiesSchema

properties.cached? ​

boolean = ...

properties.persistent? ​

boolean = ...

properties.retained? ​

boolean = ...

pubuid? ​

number = ...

type ​

string = typeStringSchema

value ​

string | number | boolean | Uint8Array<ArrayBufferLike> | string[] | boolean[] | number[] | null

The value of the subtopic

serverTime ​

number

The time the value was updated

Returns ​

void

Released under the MIT License.