Skip to content

ntcore-ts / @ntcore-ts/client / NetworkTablesTopic

Class: NetworkTablesTopic<TWire, TPublic>

Defined in: pubsub/topic.ts:18

Extends

  • NetworkTablesBaseTopic<TPublic>

Extended by

Type Parameters

TWire

TWire extends NetworkTablesTypes

TPublic

TPublic = TWire

Constructors

Constructor

new NetworkTablesTopic<TWire, TPublic>(client, name, typeInfo, defaultValue?): NetworkTablesTopic<TWire, TPublic>

Defined in: pubsub/topic.ts:61

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.

typeInfo

NetworkTablesTypeInfo

The type info for the topic.

defaultValue?

TPublic

The default value for the topic.

Returns

NetworkTablesTopic<TWire, TPublic>

Overrides

NetworkTablesBaseTopic<TPublic>.constructor

Properties

_announceParams

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

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

Inherited from

NetworkTablesBaseTopic._announceParams


_lastChangedTime?

protected optional _lastChangedTime?: number

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

Inherited from

NetworkTablesPrefixTopic._lastChangedTime


_publisher

protected _publisher: boolean

Defined in: pubsub/topic.ts:25


_publishProperties?

protected optional _publishProperties?: object

Defined in: pubsub/topic.ts:27

cached?

optional cached?: boolean

persistent?

optional persistent?: boolean

retained?

optional retained?: boolean


_pubuid?

protected optional _pubuid?: number

Defined in: pubsub/topic.ts:26


client

protected client: PubSubClient

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

Inherited from

NetworkTablesPrefixTopic.client


type

readonly type: "regular" = 'regular'

Defined in: pubsub/topic.ts:22

Overrides

NetworkTablesBaseTopic.type

Accessors

announced

Get Signature

get announced(): boolean

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

Whether the topic has been announced.

Returns

boolean

Whether the topic has been announced.

Inherited from

NetworkTablesPrefixTopic.announced


id

Get Signature

get id(): number | undefined

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

Gets the ID of the topic.

Returns

number | undefined

The ID of the topic.

Inherited from

NetworkTablesPrefixTopic.id


lastChangedTime

Get Signature

get lastChangedTime(): number | undefined

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

Gets the server time of the last value change.

Returns

number | undefined

The server time of the last value change.

Inherited from

NetworkTablesPrefixTopic.lastChangedTime


name

Get Signature

get name(): string

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

Gets the name of the topic.

Returns

string

The name of the topic.

Inherited from

NetworkTablesPrefixTopic.name


publisher

Get Signature

get publisher(): boolean

Defined in: pubsub/topic.ts:41

Gets whether the client is the publisher of the topic.

Returns

boolean

Whether the client is the publisher of the topic.


pubuid

Get Signature

get pubuid(): number | undefined

Defined in: pubsub/topic.ts:49

Gets the UID of the publisher.

Returns

number | undefined

The UID of the publisher, or undefined if the client is not the publisher.


subscribers

Get Signature

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

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

Gets the subscribers to the topic.

Returns

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

The subscribers to the topic.

Inherited from

NetworkTablesBaseTopic.subscribers


typeInfo

Get Signature

get typeInfo(): NetworkTablesTypeInfo

Defined in: pubsub/topic.ts:33

Gets the type info for the topic.

Returns

NetworkTablesTypeInfo

The type info for the topic.

Methods

afterSetWireValue()

protected afterSetWireValue(): void

Defined in: pubsub/topic.ts:110

Called after setWireValue from subclasses that encode before setting. Runs prefix notify and updateServer.

Returns

void


announce()

announce(params): void

Defined in: pubsub/topic.ts:191

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

Parameters

params

The parameters of the announcement.

id

number = integerSchema

name

string = ...

properties

{ 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


getValue()

getValue(): TPublic | null

Defined in: pubsub/topic.ts:160

Gets the value of the topic.

Returns

TPublic | null

The value of the topic.


isPrefix()

isPrefix(): this is NetworkTablesPrefixTopic

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

Returns

this is NetworkTablesPrefixTopic

Inherited from

NetworkTablesBaseTopic.isPrefix


isRegular()

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

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

Returns

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

Inherited from

NetworkTablesBaseTopic.isRegular


notifySubscribers()

protected notifySubscribers(): void

Defined in: pubsub/topic.ts:284

Notifies all subscribers of the current value. Protected so derived classes (e.g. NetworkTablesProtobufTopic) can override and pass decoded/transformed values to callbacks.

Returns

void


publish()

publish(properties?, id?): Promise<void | { method: "announce"; params: { id: number; name: string; properties: { cached?: boolean; persistent?: boolean; retained?: boolean; }; pubuid?: number; type: string; }; }>

Defined in: pubsub/topic.ts:320

Publishes the topic.

Parameters

properties?

The properties to publish the topic with.

cached?

boolean = ...

persistent?

boolean = ...

retained?

boolean = ...

id?

number

The UID of the publisher. You must verify that the ID is not already in use.

Returns

Promise<void | { method: "announce"; params: { id: number; name: string; properties: { cached?: boolean; persistent?: boolean; retained?: boolean; }; pubuid?: number; type: string; }; }>

A promise that resolves when the topic is published.


republish()

republish(client): Promise<void | { method: "announce"; params: { id: number; name: string; properties: { cached?: boolean; persistent?: boolean; retained?: boolean; }; pubuid?: number; type: string; }; }>

Defined in: pubsub/topic.ts:371

Republishes the topic.

Parameters

client

PubSubClient

The client to republish with.

Returns

Promise<void | { method: "announce"; params: { id: number; name: string; properties: { cached?: boolean; persistent?: boolean; retained?: boolean; }; pubuid?: number; type: string; }; }>

A promise that resolves when the topic is republished.


resendLatestValue()

resendLatestValue(): void

Defined in: pubsub/topic.ts:139

Resends the latest retained value after reconnect.

This is intended to be called after reconnect, once publish frames have been re-sent. This ensures that if the server/robot restarted, it receives the current state.

Returns

void


resubscribeAll()

resubscribeAll(client): void

Defined in: pubsub/topic.ts:270

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: { cached?: boolean; persistent?: boolean; retained?: boolean; }; }; }>

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

Sets the properties of the topic.

Parameters

properties?

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

cached?

boolean = ...

persistent?

boolean = ...

retained?

boolean = ...

Returns

Promise<{ method: "properties"; params: { ack?: boolean; name: string; update: { cached?: boolean; persistent?: boolean; retained?: boolean; }; }; }>

The server's response.

Inherited from

NetworkTablesBaseTopic.setProperties


setValue()

setValue(value): void

Defined in: pubsub/topic.ts:92

Sets the value of the topic. The client must be the publisher of the topic to set the value.

Parameters

value

TPublic

The value to set.

Returns

void


setWireValue()

protected setWireValue(value): void

Defined in: pubsub/topic.ts:104

Internal: set wire-format value and notify subscribers. Subclasses may call this when encoding decoded values.

Parameters

value

TWire

Returns

void


subscribe()

subscribe(callback, options?): number

Defined in: pubsub/topic.ts:217

Creates a new subscriber.

Parameters

callback

CallbackFn<TPublic>

The callback to call when the topic value changes.

options?

Omit<SubscribeOptions, "prefix"> = {}

The options for the subscriber. immediateNotify is client-side only and is not sent to the NT server. id and save are not part of this public signature.

Returns

number

The UID of the subscriber.

Overrides

NetworkTablesBaseTopic.subscribe


toProtocolSubscribeOptions()

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

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

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:108

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

Returns

void

Inherited from

NetworkTablesBaseTopic.unannounce


unpublish()

unpublish(): void

Defined in: pubsub/topic.ts:349

Unpublishes the topic.

Returns

void


unsubscribe()

unsubscribe(subuid, removeCallback?): void

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

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:168

Removes all local subscribers.

Returns

void

Inherited from

NetworkTablesBaseTopic.unsubscribeAll


updateValue()

updateValue(value, lastChangedTime): void

Defined in: pubsub/topic.ts:170

Updates the value of the topic. This should only be called by the PubSubClient.

Parameters

value

TWire

The value to update (wire format).

lastChangedTime

number

The server time of the last value change.

Returns

void

Released under the MIT License.