{"id":15149106,"url":"https://github.com/cjlawson02/ntcore-ts-client","last_synced_at":"2025-07-30T19:09:24.035Z","repository":{"id":65262188,"uuid":"577605148","full_name":"cjlawson02/ntcore-ts-client","owner":"cjlawson02","description":"A TypeScript library for WPILib's NT4.1 spec","archived":false,"fork":false,"pushed_at":"2025-01-21T06:25:10.000Z","size":1039,"stargazers_count":23,"open_issues_count":0,"forks_count":8,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-30T23:51:09.211Z","etag":null,"topics":["dashboard","first-robotics-competition","networktables","nodejs","ntcore","pubsub","typescript"],"latest_commit_sha":null,"homepage":"https://ntcore.chrislawson.dev","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cjlawson02.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-13T05:29:05.000Z","updated_at":"2025-01-21T06:25:14.000Z","dependencies_parsed_at":"2024-01-15T23:38:42.998Z","dependency_job_id":"592ad815-a77d-407e-949e-12678ff4dc26","html_url":"https://github.com/cjlawson02/ntcore-ts-client","commit_stats":{"total_commits":68,"total_committers":7,"mean_commits":9.714285714285714,"dds":0.5147058823529411,"last_synced_commit":"bee722e6d52a08db13ac2762a0e65a832a81efb5"},"previous_names":["cjlawson02/ntcore-ts-client"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjlawson02%2Fntcore-ts-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjlawson02%2Fntcore-ts-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjlawson02%2Fntcore-ts-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjlawson02%2Fntcore-ts-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cjlawson02","download_url":"https://codeload.github.com/cjlawson02/ntcore-ts-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237918710,"owners_count":19387305,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dashboard","first-robotics-competition","networktables","nodejs","ntcore","pubsub","typescript"],"created_at":"2024-09-26T13:41:50.242Z","updated_at":"2025-02-09T07:30:55.128Z","avatar_url":"https://github.com/cjlawson02.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ntcore-ts-client\n\nA TypeScript library for communication over [WPILib's NetworkTables 4.1 protocol](https://github.com/wpilibsuite/allwpilib/blob/main/ntcore/doc/networktables4.adoc).\n\n## Features\n\n- NodeJS and DOM support\n- Togglable auto-reconnect\n- Callbacks for new data on subscriptions\n- Callbacks for connection listeners\n- Wildcard prefix listeners for multiple topics\n- Retrying for messages queued during a connection loss\n- On-the-fly server switching with resubscribing and republishing\n- Generic types for Topics\n- Client-side data validation using [Zod](https://github.com/colinhacks/zod)\n- Server-matching timestamping using RTT calculation\n\n## Documentation\n\nTypeDocs are available at [https://ntcore.chrislawson.dev](https://ntcore.chrislawson.dev)\n\n## Quick Start\n\nThis section will help get you started with sending and receiving data over NetworkTables\n\n### Installation\n\n`npm install --save ntcore-ts-client`\n\n### Connecting to the NetworkTables Server\n\nThe NetworkTables class is instance-based, but allows for connections to multiple teams/URIs.\n\n### Importing `NetworkTables`\n\nUse this at the top of your file:\n\n```typescript\nimport { NetworkTables } from 'ntcore-ts-client';\n```\n\n### With Team Number\n\nUse this function:\n\n```typescript\nNetworkTables.getInstanceByTeam(team: number, port = 5810)\n```\n\n\u003e This creates the instance using the team number. Connects to `roborio-\u003cteam\u003e-frc.local`\n\n### With URI\n\nUse this function:\n\n```typescript\nNetworkTables.getInstanceByURI(uri: string, port?)\n```\n\n\u003e This creates the instance using a custom URI, i.e. 127.0.0.1, localhost, google.com, etc.\n\n### Publishing and Subscribing to a Topic\n\nTo use a Topic, it must be created through the NetworkTables client using the function:\n\n```typescript\ncreateTopic\u003cT extends NetworkTablesTypes\u003e(name: string, typeInfo: NetworkTablesTypeInfo, defaultValue?: T)\n```\n\n\u003e The valid `NetworkTablesTypes` are `string | number | boolean | string[] | ArrayBuffer | boolean[] | number[]`\n\u003e\n\u003e The valid `NetworkTablesTypeInfo`s are:\n\u003e\n\u003e - `NetworkTablesTypeInfos.kBoolean`\n\u003e - `NetworkTablesTypeInfos.kDouble`\n\u003e - `NetworkTablesTypeInfos.kInteger`\n\u003e - `NetworkTablesTypeInfos.kString`\n\u003e - `NetworkTablesTypeInfos.kArrayBuffer`\n\u003e - `NetworkTablesTypeInfos.kBooleanArray`\n\u003e - `NetworkTablesTypeInfos.kDoubleArray`\n\u003e - `NetworkTablesTypeInfos.kIntegerArray`\n\u003e - `NetworkTablesTypeInfos.kStringArray`\n\nOnce a topic has been created, it can be used as a subscriber:\n\n```typescript\nsubscribe(\n  callback: (value: T | null, params: AnnounceMessageParams) =\u003e void,\n  options: SubscribeOptions = {},\n  id?: number,\n  save = true\n)\n```\n\nand/or a publisher:\n\n```typescript\nawait publish(properties: TopicProperties = {}, id?: number)\n```\n\nFor example, here's a subscription for a Gyro:\n\n```typescript\nimport { NetworkTables, NetworkTablesTypeInfos } from 'ntcore-ts-client';\n\n// Get or create the NT client instance\nconst ntcore = NetworkTables.getInstanceByTeam(973);\n\n// Create the gyro topic\nconst gyroTopic = ntcore.createTopic\u003cnumber\u003e('/MyTable/Gyro', NetworkTablesTypeInfos.kDouble);\n\n// Subscribe and immediately call the callback with the current value\ngyroTopic.subscribe((value) =\u003e {\n  console.log(`Got Gyro Value: ${value}`);\n});\n\n// Or you can use the topic's announce parameters to get more info, like the topic ID\ngyroTopic.subscribe((value, params) =\u003e {\n  console.log(`Got Gyro Value: ${value} at from topic id ${params.id}`);\n});\n```\n\nOr a publisher for an auto mode:\n\n```typescript\nimport { NetworkTables, NetworkTablesTypeInfos } from 'ntcore-ts-client';\n\n// Get or create the NT client instance\nconst ntcore = NetworkTables.getInstanceByTeam(973);\n\n// Create the autoMode topic w/ a default return value of 'No Auto'\nconst autoModeTopic = ntcore.createTopic\u003cstring\u003e('/MyTable/autoMode', NetworkTablesTypeInfos.kString, 'No Auto');\n\n// Make us the publisher\nawait autoModeTopic.publish();\n\n// Set a new value, this will error if we aren't the publisher!\nautoModeTopic.setValue('25 Ball Auto and Climb');\n```\n\n### Subscribing to Multiple Topics\n\nYou can also subscribe to multiple topics by using a \"wildcard\" through creating a prefix topic.\n\nFor example, here's a subscription for an Accelerometer with topics `/MyTable/Accelerometer/X`, `/MyTable/Accelerometer/Y`, and `/MyTable/Accelerometer/Z`:\n\n```typescript\nimport { NetworkTables } from 'ntcore-ts-client';\n\n// Get or create the NT client instance\nconst ntcore = NetworkTables.getInstanceByTeam(973);\n\n// Create the accelerator topic\nconst accelerometerTopic = ntcore.createPrefixTopic('/MyTable/Accelerometer/');\n\nlet x, y, z;\n\n// Subscribe to all topics under the prefix /MyTable/Accelerometer/\naccelerometerTopic.subscribe((value, params) =\u003e {\n  console.log(`Got Accelerometer Value: ${value} from topic ${params.name}`); // i.e. Got Accelerometer Value: 9.81 from topic /MyTable/Accelerometer/Y\n\n  // You can also use the topic name to determine which value to set\n  if (params.name.endsWith('X')) {\n    x = value;\n  } else if (params.name.endsWith('Y')) {\n    y = value;\n  } else if (params.name.endsWith('Z')) {\n    z = value;\n  }\n\n  // Since there can be many types in subtopics,\n  // you can use the type information for other checks...\n  if (params.type === 'int') {\n    console.warn('Hmm... the accelerometer seems low precision');\n  } else if (params.type === 'double') {\n    console.log('The accelerometer is high precision');\n  }\n});\n\n// x, y, and z will be updated as new values come in\n```\n\n### Subscribing to All Topics\n\nYou can also subscribe to all topics by doing the above, but with a prefix of `/`.\n\nFor example, here's a subscription for all topics:\n\n```typescript\nimport { NetworkTables } from 'ntcore-ts-client';\n\n// Get or create the NT client instance\nconst ntcore = NetworkTables.getInstanceByTeam(973);\n\n// Create a prefix for all topics\nconst allTopics = ntcore.createPrefixTopic('/');\n\n// Subscribe to all topics\nallTopics.subscribe((value, params) =\u003e {\n  console.log(`Got Value: ${value} from topic ${params.name}`);\n});\n```\n\n### More Info\n\nThe API for Topics is much more exhaustive than this quick example. Feel free to view the docs at [https://ntcore.chrislawson.dev](https://ntcore.chrislawson.dev).\n\n## Known Limitations\n\n- \"Raw\" type only supports ArrayBuffer\n\n## Contributing\n\nContributions are welcome and encouraged! If you encounter a bug, please open an issue and provide as much information as possible. If you'd like to open a PR, I'll be more than happy to review it as soon as I can!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcjlawson02%2Fntcore-ts-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcjlawson02%2Fntcore-ts-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcjlawson02%2Fntcore-ts-client/lists"}