Skip to content

ntcore-ts / @ntcore-ts/client / NetworkTablesStructTopic

Class: NetworkTablesStructTopic<T>

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

Extends

Type Parameters

T

T extends object | object[]

Constructors

Constructor

new NetworkTablesStructTopic<T>(client, name, options?): NetworkTablesStructTopic<T>

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

Parameters

client

PubSubClient

name

string

options?
defaultValue?

T

schema?

string

typeName?

string

validator?

ZodType<T, unknown, $ZodTypeInternals<T, unknown>>

Returns

NetworkTablesStructTopic<T>

Overrides

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

NetworkTablesTopic._announceParams


_lastChangedTime?

protected optional _lastChangedTime?: number

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

Inherited from

NetworkTablesTopic._lastChangedTime


_publisher

protected _publisher: boolean

Defined in: pubsub/topic.ts:25

Inherited from

NetworkTablesTopic._publisher


_publishProperties?

protected optional _publishProperties?: object

Defined in: pubsub/topic.ts:27

cached?

optional cached?: boolean

persistent?

optional persistent?: boolean

retained?

optional retained?: boolean

Inherited from

NetworkTablesTopic._publishProperties


_pubuid?

protected optional _pubuid?: number

Defined in: pubsub/topic.ts:26

Inherited from

NetworkTablesTopic._pubuid


client

protected client: PubSubClient

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

Inherited from

NetworkTablesTopic.client


type

readonly type: "regular" = 'regular'

Defined in: pubsub/topic.ts:22

Inherited from

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

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

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

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

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

Inherited from

NetworkTablesTopic.publisher


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.

Inherited from

NetworkTablesTopic.pubuid


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

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

Inherited from

NetworkTablesTopic.typeInfo

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

Inherited from

NetworkTablesTopic.afterSetWireValue


announce()

announce(params): void

Defined in: pubsub/struct-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

NetworkTablesTopic.announce


applyOptions()

applyOptions(options?): void

Defined in: pubsub/struct-topic.ts:72

Applies options to this topic. Used when returning a cached topic from getStructTopic. A later validator replaces any previous validator because the topic is a singleton.

Parameters

options?

The options to apply.

defaultValue?

T

schema?

string

typeName?

string

validator?

ZodType<T, unknown, $ZodTypeInternals<T, unknown>>

Returns

void


getValue()

getValue(): T | null

Defined in: pubsub/struct-topic.ts:130

Gets the value of the topic.

Returns

T | null

The value of the topic.

Overrides

NetworkTablesTopic.getValue


isPrefix()

isPrefix(): this is NetworkTablesPrefixTopic

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

Returns

this is NetworkTablesPrefixTopic

Inherited from

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

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

Inherited from

NetworkTablesTopic.notifySubscribers


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/struct-topic.ts:202

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.

Overrides

NetworkTablesTopic.publish


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.

Inherited from

NetworkTablesTopic.republish


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

Inherited from

NetworkTablesTopic.resendLatestValue


resubscribeAll()

resubscribeAll(client): void

Defined in: pubsub/topic.ts:270

Resubscribes all local subscribers.

Parameters

client

PubSubClient

The client to resubscribe with.

Returns

void

Inherited from

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

NetworkTablesTopic.setProperties


setValue()

setValue(value): void

Defined in: pubsub/struct-topic.ts:134

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

Parameters

value

T

The value to set.

Returns

void

Overrides

NetworkTablesTopic.setValue


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

Uint8Array

Returns

void

Inherited from

NetworkTablesTopic.setWireValue


subscribe()

subscribe(callback, options?): number

Defined in: pubsub/topic.ts:217

Creates a new subscriber.

Parameters

callback

CallbackFn<T>

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.

Inherited from

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

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

NetworkTablesTopic.unannounce


unpublish()

unpublish(): void

Defined in: pubsub/topic.ts:349

Unpublishes the topic.

Returns

void

Inherited from

NetworkTablesTopic.unpublish


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

NetworkTablesTopic.unsubscribe


unsubscribeAll()

unsubscribeAll(): void

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

Removes all local subscribers.

Returns

void

Inherited from

NetworkTablesTopic.unsubscribeAll


updateValue()

updateValue(value, lastChangedTime): void

Defined in: pubsub/struct-topic.ts:186

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

Parameters

value

Uint8Array

The value to update (wire format).

lastChangedTime

number

The server time of the last value change.

Returns

void

Overrides

NetworkTablesTopic.updateValue

Released under the MIT License.