Skip to content

ntcore-ts / @ntcore-ts/client / NetworkTables

Class: NetworkTables

Defined in: client.ts:44

NetworkTables class for interacting with NetworkTables over a WebSocket connection.

Methods

addRobotConnectionListener()

addRobotConnectionListener(callback, immediateNotify?): () => void

Defined in: client.ts:197

Adds a listener for robot connection status updates.

Parameters

callback

(_) => void

The callback to call when the connection status changes.

immediateNotify?

boolean

When true, also notifies once with the current status on a microtask after this method returns (so the returned disposer can be called from that first notification).

Returns

A function to remove the listener.

() => void


changeTeam()

changeTeam(team, port?, platform?): void

Defined in: client.ts:154

Changes the server using a team number.

Parameters

team

number

The team number of the robot.

port?

number = 5810

The port to connect to the server on. Defaults to 5810.

platform?

RobotPlatform = 'roborio'

RoboRIO mDNS (default) or SystemCore team IP.

Returns

void


changeURI()

changeURI(uri, port?): void

Defined in: client.ts:136

Changes the URI of the server.

Parameters

uri

string

The new URI of the server.

port?

number = 5810

The port to connect to the server on. Defaults to 5810.

Returns

void


close()

close(): void

Defined in: client.ts:221

Disconnects from the server, unsubscribes/unpublishes all topics, and drops this instance (and the underlying PubSubClient/Messenger/Socket singletons) so they do not leak.

Returns

void


createTopic()

Call Signature

createTopic<T>(name, typeInfo, defaultValue?): NetworkTablesJsonTopic<T>

Defined in: client.ts:253

Creates a new JSON topic. Wire format is a JSON string with type 'json'.

Type Parameters
T

T extends object

Parameters
name

string

The name of the topic.

typeInfo

[4, "json"]

Must be NetworkTablesTypeInfos.kJson.

defaultValue?

T

The default parsed JSON value of the topic.

Returns

NetworkTablesJsonTopic<T>

Call Signature

createTopic<T>(name, typeInfo, defaultValue?): NetworkTablesTopic<T>

Defined in: client.ts:271

Creates a new topic.

Type Parameters
T

T extends string | number | boolean | string[] | Uint8Array<ArrayBufferLike> | boolean[] | number[]

Parameters
name

string

The name of the topic.

typeInfo

NetworkTablesTypeInfo

The type information of the topic. Protobuf types are not allowed (use getProtobufTopic instead). Struct types are not allowed (use getStructTopic instead). JSON types return a NetworkTablesJsonTopic.

defaultValue?

T

The default value of the topic.

Returns

NetworkTablesTopic<T>

The topic.

Remarks

If a topic with the same name and type already exists (from a previous call to createTopic), the existing topic instance is returned and the defaultValue from this call is ignored. Only the defaultValue from the first call to createTopic for a given topic name and type will be used. If a topic with the same name but different type exists, an error is thrown.


getBooleanArrayTopic()

getBooleanArrayTopic(name, defaultValue?): NetworkTablesTopic<boolean[]>

Defined in: client.ts:344

Creates a boolean-array topic.

Parameters

name

string

Topic name.

defaultValue?

boolean[]

Optional value shown before the first server update.

Returns

NetworkTablesTopic<boolean[]>


getBooleanTopic()

getBooleanTopic(name, defaultValue?): NetworkTablesTopic<boolean>

Defined in: client.ts:299

Creates a boolean topic.

Parameters

name

string

Topic name (e.g. /MyTable/Enabled).

defaultValue?

boolean

Optional value shown before the first server update.

Returns

NetworkTablesTopic<boolean>


getDoubleArrayTopic()

getDoubleArrayTopic(name, defaultValue?): NetworkTablesTopic<number[]>

Defined in: client.ts:353

Creates a double-array topic.

Parameters

name

string

Topic name.

defaultValue?

number[]

Optional value shown before the first server update.

Returns

NetworkTablesTopic<number[]>


getDoubleTopic()

getDoubleTopic(name, defaultValue?): NetworkTablesTopic<number>

Defined in: client.ts:308

Creates a double (IEEE-754) topic.

Parameters

name

string

Topic name (e.g. /MyTable/Gyro).

defaultValue?

number

Optional value shown before the first server update.

Returns

NetworkTablesTopic<number>


getFloatArrayTopic()

getFloatArrayTopic(name, defaultValue?): NetworkTablesTopic<number[]>

Defined in: client.ts:371

Creates a float-array topic.

Parameters

name

string

Topic name.

defaultValue?

number[]

Optional value shown before the first server update.

Returns

NetworkTablesTopic<number[]>


getFloatTopic()

getFloatTopic(name, defaultValue?): NetworkTablesTopic<number>

Defined in: client.ts:326

Creates a float topic.

Parameters

name

string

Topic name.

defaultValue?

number

Optional value shown before the first server update.

Returns

NetworkTablesTopic<number>


getIntegerArrayTopic()

getIntegerArrayTopic(name, defaultValue?): NetworkTablesTopic<number[]>

Defined in: client.ts:362

Creates an integer-array topic.

Parameters

name

string

Topic name.

defaultValue?

number[]

Optional value shown before the first server update.

Returns

NetworkTablesTopic<number[]>


getIntegerTopic()

getIntegerTopic(name, defaultValue?): NetworkTablesTopic<number>

Defined in: client.ts:317

Creates an integer topic.

Parameters

name

string

Topic name.

defaultValue?

number

Optional value shown before the first server update.

Returns

NetworkTablesTopic<number>


getJsonTopic()

getJsonTopic<T>(name, defaultValue?, options?): NetworkTablesJsonTopic<T>

Defined in: client.ts:400

Creates a JSON topic with optional Zod validation. If a topic with the same name already exists, the existing instance is returned and options are applied.

Type Parameters

T

T extends object

Parameters

name

string

Topic name.

defaultValue?

T

Optional value shown before the first server update.

options?

JsonTopicOptions<T>

Optional validator schema.

Returns

NetworkTablesJsonTopic<T>


getPort()

getPort(): number

Defined in: client.ts:162

Returns the port to connect to the robot on.

Returns

number

The port number.


getPrefixTopic()

getPrefixTopic(prefix): NetworkTablesPrefixTopic

Defined in: client.ts:496

Creates a prefix topic (wildcard subscription).

Parameters

prefix

string

The prefix of the topic.

Returns

NetworkTablesPrefixTopic

The topic.


getProtobufTopic()

getProtobufTopic<T>(name, options?): NetworkTablesProtobufTopic<T>

Defined in: client.ts:420

Creates a protobuf topic. If a topic with the same name already exists, the existing instance is returned and options are applied.

Type Parameters

T

T extends object

Parameters

name

string

options?

ProtobufTopicOptions<T>

Returns

NetworkTablesProtobufTopic<T>


getRawTopic()

getRawTopic(name, defaultValue?): NetworkTablesTopic<Uint8Array<ArrayBufferLike>>

Defined in: client.ts:389

Creates a raw (uint8[]) topic. Values are Uint8Array.

Parameters

name

string

Topic name.

defaultValue?

Uint8Array<ArrayBufferLike>

Optional value shown before the first server update.

Returns

NetworkTablesTopic<Uint8Array<ArrayBufferLike>>


getRttMs()

getRttMs(): number

Defined in: client.ts:186

Returns the best round-trip time to the robot in milliseconds.

Returns

number

RTT in ms, or -1 if not connected or not yet measured.


getStringArrayTopic()

getStringArrayTopic(name, defaultValue?): NetworkTablesTopic<string[]>

Defined in: client.ts:380

Creates a string-array topic.

Parameters

name

string

Topic name.

defaultValue?

string[]

Optional value shown before the first server update.

Returns

NetworkTablesTopic<string[]>


getStringTopic()

getStringTopic(name, defaultValue?): NetworkTablesTopic<string>

Defined in: client.ts:335

Creates a string topic.

Parameters

name

string

Topic name (e.g. /MyTable/AutoMode).

defaultValue?

string

Optional value shown before the first server update.

Returns

NetworkTablesTopic<string>


getStructTopic()

Call Signature

getStructTopic<T>(name, type, options?): NetworkTablesStructTopic<T>

Defined in: client.ts:433

Creates a struct topic from a WPILib-style type descriptor (e.g. Pose2d). Infers NetworkTablesStructTopic for Pose2d from nt.getStructTopic(name, Pose2d).

Type Parameters
T

T extends object

Parameters
name

string

type

StructTypeDescriptor<T>

options?

Omit<StructTopicOptions<T>, "validator" | "typeName">

Returns

NetworkTablesStructTopic<T>

Call Signature

getStructTopic<T>(name, options?): NetworkTablesStructTopic<T>

Defined in: client.ts:449

Creates a struct topic.

Type Parameters
T

T extends object | object[]

Parameters
name

string

The name of the topic.

options?

StructTopicOptions<T>

Optional typeName, schema, defaultValue, validator. typeName (or a type descriptor as the second argument) is required when creating a new topic. Reusing an existing topic may omit typeName.

Returns

NetworkTablesStructTopic<T>

The struct topic. If a topic with the same name already exists, the existing topic is returned.

Remarks

Struct fields using int64 or uint64 are returned as JavaScript number, which loses precision beyond ±2^53 (Number.MAX_SAFE_INTEGER). No built-in WPILib struct types are affected — they all use double.


getURI()

getURI(): string

Defined in: client.ts:127

Returns the URI of the server.

Returns

string

The robot address.


isRobotConnected()

isRobotConnected(): boolean

Defined in: client.ts:170

Returns whether the robot is currently connected.

Returns

boolean

Whether the robot is connected.


isRobotConnecting()

isRobotConnecting(): boolean

Defined in: client.ts:178

Returns whether the robot is currently connecting.

Returns

boolean

Whether the robot is connecting.


release()

release(): void

Defined in: client.ts:240

Decrements the retain count and calls close when it reaches zero.

Returns

void


retain()

retain(): void

Defined in: client.ts:233

Increments the retain count used by NtcoreProvider so multiple trees can share this singleton without tearing it down on the first unmount.

Returns

void


startAutoConnect()

startAutoConnect(): void

Defined in: client.ts:213

Resumes automatic reconnection to the server after a previous call to stopAutoConnect.

Returns

void


stopAutoConnect()

stopAutoConnect(): void

Defined in: client.ts:206

Stops automatic reconnection to the server. Use when the user dismisses the connection overlay (e.g. Escape) so the client does not keep trying to reconnect in the background.

Returns

void


getInstanceByTeam()

static getInstanceByTeam(team, port?, platform?): NetworkTables

Defined in: client.ts:93

Creates a new NetworkTables instance if it does not exist.

Parameters

team

number

The team number of the robot.

port?

number = 5810

The port to connect to the robot on. Defaults to 5810.

platform?

RobotPlatform = 'roborio'

RoboRIO mDNS (roborio-{team}-frc.local, default) or SystemCore team IP (10.TE.AM.2).

Returns

NetworkTables

The NetworkTables instance.

Throws

Error if the team number is not provided.


getInstanceByURI()

static getInstanceByURI(uri, port?): NetworkTables

Defined in: client.ts:112

Creates a new NetworkTables instance if it does not exist.

Parameters

uri

string

The URI of the robot.

port?

number = 5810

The port to connect to the robot on. Defaults to 5810.

Returns

NetworkTables

The NetworkTables instance.

Throws

Error if the URI is not provided.


getModuleLogLevel()

static getModuleLogLevel(module?): LogLevel

Defined in: client.ts:523

Gets the current log level for a specific module.

Parameters

module?

LoggerModule = 'default'

The module name ('socket', 'messenger', 'pubsub', or 'default').

Returns

LogLevel

The current log level.


setLogLevel()

static setLogLevel(level): void

Defined in: client.ts:505

Sets the global log level for all modules.

Parameters

level

LogLevel

The log level to set.

Returns

void


setModuleLogLevel()

static setModuleLogLevel(module, level): void

Defined in: client.ts:514

Sets the log level for a specific module.

Parameters

module

LoggerModule

The module name ('socket', 'messenger', 'pubsub', or 'default').

level

LogLevel

The log level to set.

Returns

void

Released under the MIT License.