ntcore-ts / @ntcore-ts/client / NetworkTablesJsonTopic
Class: NetworkTablesJsonTopic<T>
Defined in: pubsub/json-topic.ts:18
JSON topic: public value is a parsed object; wire format is a JSON string with type 'json'.
Extends
NetworkTablesTopic<string,T>
Type Parameters
T
T extends object
Constructors
Constructor
new NetworkTablesJsonTopic<
T>(client,name,defaultValue?,options?):NetworkTablesJsonTopic<T>
Defined in: pubsub/json-topic.ts:29
Creates a new JSON topic.
Parameters
client
PubSubClient
The client that owns the topic.
name
string
The name of the topic.
defaultValue?
T
The default public value of the topic.
options?
Optional runtime validator for parsed JSON.
Returns
NetworkTablesJsonTopic<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?
protectedoptional_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
_publishProperties?
protectedoptional_publishProperties?:object
Defined in: pubsub/topic.ts:27
cached?
optionalcached?:boolean
persistent?
optionalpersistent?:boolean
retained?
optionalretained?:boolean
Inherited from
NetworkTablesTopic._publishProperties
_pubuid?
protectedoptional_pubuid?:number
Defined in: pubsub/topic.ts:26
Inherited from
client
protectedclient:PubSubClient
Defined in: pubsub/base-topic.ts:19
Inherited from
type
readonlytype:"regular"='regular'
Defined in: pubsub/topic.ts:22
Inherited from
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
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
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
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
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
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
The type info for the topic.
Inherited from
Methods
afterSetWireValue()
protectedafterSetWireValue():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/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
Inherited from
applyOptions()
applyOptions(
options?):void
Defined in: pubsub/json-topic.ts:43
Applies options to this topic. Used when returning a cached topic from getJsonTopic. A later defaultValue is ignored once a value exists (matches createTopic). A later validator replaces any previous validator because the topic is a singleton.
Parameters
options?
object & JsonTopicOptions<T>
The options to apply.
Returns
void
getValue()
getValue():
T|null
Defined in: pubsub/json-topic.ts:60
Gets the parsed JSON value of the topic.
Returns
T | null
The parsed JSON object, or null if no value has been set.
Overrides
isPrefix()
isPrefix():
this is NetworkTablesPrefixTopic
Defined in: pubsub/base-topic.ts:36
Returns
this is NetworkTablesPrefixTopic
Inherited from
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
notifySubscribers()
protectednotifySubscribers():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/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.
Inherited from
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
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/json-topic.ts:68
Sets the JSON value of the topic. The value is serialized with JSON.stringify for the wire.
Parameters
value
T
The object to publish.
Returns
void
Overrides
setWireValue()
protectedsetWireValue(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
string
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
toProtocolSubscribeOptions()
protectedtoProtocolSubscribeOptions(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
unpublish()
unpublish():
void
Defined in: pubsub/topic.ts:349
Unpublishes the topic.
Returns
void
Inherited from
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/json-topic.ts:86
Updates the value of the topic from the wire JSON string. This should only be called by the PubSubClient.
Parameters
value
string
The wire-format JSON string.
lastChangedTime
number
The server time of the last value change.
Returns
void