Skip to content

Commit

Permalink
feat: adds addOnTopicAnnouncedListener
Browse files Browse the repository at this point in the history
  • Loading branch information
jnallard committed Oct 30, 2024
1 parent 79c17ad commit 7901138
Show file tree
Hide file tree
Showing 35 changed files with 167 additions and 71 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,29 @@ await autoModeTopic.publish();
autoModeTopic.setValue('25 Ball Auto and Climb');
```
### Subscribing to Announced Topics
You can register a callback to know when your topics are announced:
```typescript
const ntcore = NetworkTables.getInstanceByTeam(973);
ntcore.addOnTopicAnnouncedListener((topic) => {
console.log(`Topic announced: ${topic.name}`);
});
```
By supplying `true` to the `announceAll` parameter, all topics published to NetworkTables (from any client) will also be announced:
```typescript
const ntcore = NetworkTables.getInstanceByTeam(973);
ntcore.addOnTopicAnnouncedListener((topic) => {
console.log(`Topic announced: ${topic.name}`);
topic.subscribe((value) => console.log(`Got ${topic.name} value: ${value}`));
}, true);
```
This will allow you to subscribe to any or all topics from the robot, which is useful for dynamic dashboard applications.
### More info
The 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).
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/navigation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/assets/search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7901138

Please sign in to comment.