Skip to content

Commit

Permalink
v0.2.0 (#29)
Browse files Browse the repository at this point in the history
* chore: update deps

* style: prepend nt client id with `ntcore-ts-`

* feat: allow multiple connections

BREAKING CHANGE: deprecated NetworkTables.createInstance*()
 - Please use NetworkTables.getInstanceByTeam() and NetworkTables.getInstanceByURI()

BREAKING CHANGE: removed NetworkTables.getInstance() and NetworkTables.getServerURL()

* fix: rename NetworkTableTypeInfos to NetworkTablesTypeInfos

BREAKING CHANGE: deprecated NetworkTableTypeInfos

* chore: bump version

* fix: connect to the correct mDNS address
fix: bug with creating instance on same URI w/ different port

* fix: queue value to published topic w/o server connection

* chore: update deps

* chore: bump version to 0.2.0
  • Loading branch information
Chris Lawson authored Feb 23, 2023
1 parent 8b77023 commit b88b49f
Show file tree
Hide file tree
Showing 66 changed files with 2,718 additions and 2,520 deletions.
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,32 @@ This section will help get you started with sending and receiving data over Netw

### Connecting to the NetworkTables Server

The NetworkTables class is a singleton that will keep the same instance
The NetworkTables class is instance-based, but allows for connections to multiple teams/URIs.

### Importing `NetworkTables`

Use this at the top of your file:

```typescript
import { NetworkTables } from 'ntcore-ts-client'
import { NetworkTables } from 'ntcore-ts-client';
```

### With Team Number

Use this function:

```typescript
NetworkTables.createInstanceByTeam(team: number, port = 5810)
NetworkTables.getInstanceByTeam(team: number, port = 5810)
```

> This creates the instance using the team number. Connects to `roborio-frc-<team>.local`
> This creates the instance using the team number. Connects to `roborio-<team>-frc.local`
### With URI

Use this function:

```typescript
NetworkTables.createInstanceByURI(uri: string, port?)
NetworkTables.getInstanceByURI(uri: string, port?)
```
> This creates the instance using a custom URI, i.e. 127.0.0.1, localhost, google.com, etc.
Expand All @@ -70,15 +70,15 @@ createTopic<T extends NetworkTablesTypes>(name: string, typeInfo: NetworkTablesT
>
> The valid `NetworkTablesTypeInfo`s are:
>
> - `NetworkTableTypeInfos.kBoolean`
> - `NetworkTableTypeInfos.kDouble`
> - `NetworkTableTypeInfos.kInteger`
> - `NetworkTableTypeInfos.kString`
> - `NetworkTableTypeInfos.kArrayBuffer`
> - `NetworkTableTypeInfos.kBooleanArray`
> - `NetworkTableTypeInfos.kDoubleArray`
> - `NetworkTableTypeInfos.kIntegerArray`
> - `NetworkTableTypeInfos.kStringArray`
> - `NetworkTablesTypeInfos.kBoolean`
> - `NetworkTablesTypeInfos.kDouble`
> - `NetworkTablesTypeInfos.kInteger`
> - `NetworkTablesTypeInfos.kString`
> - `NetworkTablesTypeInfos.kArrayBuffer`
> - `NetworkTablesTypeInfos.kBooleanArray`
> - `NetworkTablesTypeInfos.kDoubleArray`
> - `NetworkTablesTypeInfos.kIntegerArray`
> - `NetworkTablesTypeInfos.kStringArray`

Once a topic has been created, it can be used as a subscriber:

Expand All @@ -101,13 +101,13 @@ publish(properties: TopicProperties = {}, id?: number)
For example, here's a subscription for a Gyro:

```typescript
import { NetworkTables, NetworkTableTypeInfos } from 'ntcore-ts-client';
import { NetworkTables, NetworkTablesTypeInfos } from 'ntcore-ts-client';

// Create the NT client instance
const ntcore = NetworkTables.createInstanceByTeam(973);
// Get or create the NT client instance
const ntcore = NetworkTables.getInstanceByTeam(973);

// Create the gyro topic
const gyroTopic = ntcore.createTopic<number>('/MyTable/Gyro', NetworkTableTypeInfos.kDouble);
const gyroTopic = ntcore.createTopic<number>('/MyTable/Gyro', NetworkTablesTypeInfos.kDouble);

// Subscribe and immediately call the callback with the current value
gyroTopic.subscribe((value) => {
Expand All @@ -118,13 +118,13 @@ gyroTopic.subscribe((value) => {
Or a publisher for an auto mode:
```typescript
import { NetworkTables, NetworkTableTypeInfos } from 'ntcore-ts-client';
import { NetworkTables, NetworkTablesTypeInfos } from 'ntcore-ts-client';

// We're assuming we have already done a createInstance in our app, or this will throw an error!
const ntcore = NetworkTables.getInstance();
// Get or create the NT client instance
const ntcore = NetworkTables.getInstanceByTeam(973);

// Create the autoMode topic w/ a default return value of 'No Auto'
const autoModeTopic = ntcore.createTopic<string>('/MyTable/autoMode', NetworkTableTypeInfos.kString, 'No Auto');
const autoModeTopic = ntcore.createTopic<string>('/MyTable/autoMode', NetworkTablesTypeInfos.kString, 'No Auto');

// Make us the publisher
autoModeTopic.publish();
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/search.js

Large diffs are not rendered by default.

104 changes: 54 additions & 50 deletions docs/classes/NetworkTableTypeInfos.html

Large diffs are not rendered by default.

118 changes: 73 additions & 45 deletions docs/classes/NetworkTables.html

Large diffs are not rendered by default.

68 changes: 34 additions & 34 deletions docs/classes/NetworkTablesTopic.html

Large diffs are not rendered by default.

137 changes: 137 additions & 0 deletions docs/classes/NetworkTablesTypeInfos.html

Large diffs are not rendered by default.

55 changes: 24 additions & 31 deletions docs/classes/_internal_.Messenger.html

Large diffs are not rendered by default.

100 changes: 50 additions & 50 deletions docs/classes/_internal_.NetworkTablesSocket.html

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions docs/classes/_internal_.PubSubClient.html

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ <h3 class="tsd-index-heading">Modules</h3>
</div></section>
<section class="tsd-index-section">
<h3 class="tsd-index-heading">Classes</h3>
<div class="tsd-index-list"><a href="classes/NetworkTableTypeInfos.html" class="tsd-index-link tsd-kind-class"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-class)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6" id="icon-128-path"></rect><path d="M11.898 16.1201C11.098 16.1201 10.466 15.8961 10.002 15.4481C9.53803 15.0001 9.30603 14.3841 9.30603 13.6001V9.64012C9.30603 8.85612 9.53803 8.24012 10.002 7.79212C10.466 7.34412 11.098 7.12012 11.898 7.12012C12.682 7.12012 13.306 7.34812 13.77 7.80412C14.234 8.25212 14.466 8.86412 14.466 9.64012H13.386C13.386 9.14412 13.254 8.76412 12.99 8.50012C12.734 8.22812 12.37 8.09212 11.898 8.09212C11.426 8.09212 11.054 8.22412 10.782 8.48812C10.518 8.75212 10.386 9.13212 10.386 9.62812V13.6001C10.386 14.0961 10.518 14.4801 10.782 14.7521C11.054 15.0161 11.426 15.1481 11.898 15.1481C12.37 15.1481 12.734 15.0161 12.99 14.7521C13.254 14.4801 13.386 14.0961 13.386 13.6001H14.466C14.466 14.3761 14.234 14.9921 13.77 15.4481C13.306 15.8961 12.682 16.1201 11.898 16.1201Z" fill="var(--color-text)" id="icon-128-text"></path></svg><span>Network<wbr/>Table<wbr/>Type<wbr/>Infos</span></a>
<div class="tsd-index-list"><a href="classes/NetworkTableTypeInfos.html" class="tsd-index-link deprecated tsd-kind-class"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-class)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6" id="icon-128-path"></rect><path d="M11.898 16.1201C11.098 16.1201 10.466 15.8961 10.002 15.4481C9.53803 15.0001 9.30603 14.3841 9.30603 13.6001V9.64012C9.30603 8.85612 9.53803 8.24012 10.002 7.79212C10.466 7.34412 11.098 7.12012 11.898 7.12012C12.682 7.12012 13.306 7.34812 13.77 7.80412C14.234 8.25212 14.466 8.86412 14.466 9.64012H13.386C13.386 9.14412 13.254 8.76412 12.99 8.50012C12.734 8.22812 12.37 8.09212 11.898 8.09212C11.426 8.09212 11.054 8.22412 10.782 8.48812C10.518 8.75212 10.386 9.13212 10.386 9.62812V13.6001C10.386 14.0961 10.518 14.4801 10.782 14.7521C11.054 15.0161 11.426 15.1481 11.898 15.1481C12.37 15.1481 12.734 15.0161 12.99 14.7521C13.254 14.4801 13.386 14.0961 13.386 13.6001H14.466C14.466 14.3761 14.234 14.9921 13.77 15.4481C13.306 15.8961 12.682 16.1201 11.898 16.1201Z" fill="var(--color-text)" id="icon-128-text"></path></svg><span>Network<wbr/>Table<wbr/>Type<wbr/>Infos</span></a>
<a href="classes/NetworkTables.html" class="tsd-index-link tsd-kind-class"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-128-path"></use><use href="#icon-128-text"></use></svg><span>Network<wbr/>Tables</span></a>
<a href="classes/NetworkTablesTopic.html" class="tsd-index-link tsd-kind-class"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-128-path"></use><use href="#icon-128-text"></use></svg><span>Network<wbr/>Tables<wbr/>Topic</span></a>
<a href="classes/NetworkTablesTypeInfos.html" class="tsd-index-link tsd-kind-class"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-128-path"></use><use href="#icon-128-text"></use></svg><span>Network<wbr/>Tables<wbr/>Type<wbr/>Infos</span></a>
</div></section>
<section class="tsd-index-section">
<h3 class="tsd-index-heading">Interfaces</h3>
Expand Down
12 changes: 6 additions & 6 deletions docs/interfaces/BinaryMessageData.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h4>Hierarchy</h4>
<ul class="tsd-hierarchy">
<li><span class="target">BinaryMessageData</span></li></ul></section><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Chris2fourlaw/ntcore-ts/blob/db304b4/packages/ntcore-ts-client/src/lib/types/types.ts#L68">packages/ntcore-ts-client/src/lib/types/types.ts:68</a></li></ul></aside>
<li>Defined in <a href="https://github.com/Chris2fourlaw/ntcore-ts/blob/43de007/packages/ntcore-ts-client/src/lib/types/types.ts#L82">packages/ntcore-ts-client/src/lib/types/types.ts:82</a></li></ul></aside>
<section class="tsd-panel-group tsd-index-group">
<section class="tsd-panel tsd-index-panel">
<details class="tsd-index-content tsd-index-accordion" open><summary class="tsd-accordion-summary tsd-index-summary">
Expand All @@ -39,22 +39,22 @@ <h2>Properties</h2>
<h3 class="tsd-anchor-link"><span>server<wbr/>Time</span><a href="#serverTime" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none" id="icon-anchor-a"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5" id="icon-anchor-b"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5" id="icon-anchor-c"></path></svg></a></h3>
<div class="tsd-signature">server<wbr/>Time<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Chris2fourlaw/ntcore-ts/blob/db304b4/packages/ntcore-ts-client/src/lib/types/types.ts#L70">packages/ntcore-ts-client/src/lib/types/types.ts:70</a></li></ul></aside></section>
<li>Defined in <a href="https://github.com/Chris2fourlaw/ntcore-ts/blob/43de007/packages/ntcore-ts-client/src/lib/types/types.ts#L84">packages/ntcore-ts-client/src/lib/types/types.ts:84</a></li></ul></aside></section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="topicId" class="tsd-anchor"></a>
<h3 class="tsd-anchor-link"><span>topic<wbr/>Id</span><a href="#topicId" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
<div class="tsd-signature">topic<wbr/>Id<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Chris2fourlaw/ntcore-ts/blob/db304b4/packages/ntcore-ts-client/src/lib/types/types.ts#L69">packages/ntcore-ts-client/src/lib/types/types.ts:69</a></li></ul></aside></section>
<li>Defined in <a href="https://github.com/Chris2fourlaw/ntcore-ts/blob/43de007/packages/ntcore-ts-client/src/lib/types/types.ts#L83">packages/ntcore-ts-client/src/lib/types/types.ts:83</a></li></ul></aside></section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="typeInfo" class="tsd-anchor"></a>
<h3 class="tsd-anchor-link"><span>type<wbr/>Info</span><a href="#typeInfo" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
<div class="tsd-signature">type<wbr/>Info<span class="tsd-signature-symbol">:</span> <a href="../classes/NetworkTableTypeInfos.html" class="tsd-signature-type" data-tsd-kind="Class">NetworkTableTypeInfos</a></div><aside class="tsd-sources">
<div class="tsd-signature">type<wbr/>Info<span class="tsd-signature-symbol">:</span> <a href="../classes/NetworkTablesTypeInfos.html" class="tsd-signature-type" data-tsd-kind="Class">NetworkTablesTypeInfos</a></div><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Chris2fourlaw/ntcore-ts/blob/db304b4/packages/ntcore-ts-client/src/lib/types/types.ts#L71">packages/ntcore-ts-client/src/lib/types/types.ts:71</a></li></ul></aside></section>
<li>Defined in <a href="https://github.com/Chris2fourlaw/ntcore-ts/blob/43de007/packages/ntcore-ts-client/src/lib/types/types.ts#L85">packages/ntcore-ts-client/src/lib/types/types.ts:85</a></li></ul></aside></section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="value" class="tsd-anchor"></a>
<h3 class="tsd-anchor-link"><span>value</span><a href="#value" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
<div class="tsd-signature">value<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">ArrayBuffer</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">[]</span></div><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Chris2fourlaw/ntcore-ts/blob/db304b4/packages/ntcore-ts-client/src/lib/types/types.ts#L72">packages/ntcore-ts-client/src/lib/types/types.ts:72</a></li></ul></aside></section></section></div>
<li>Defined in <a href="https://github.com/Chris2fourlaw/ntcore-ts/blob/43de007/packages/ntcore-ts-client/src/lib/types/types.ts#L86">packages/ntcore-ts-client/src/lib/types/types.ts:86</a></li></ul></aside></section></section></div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<div class="tsd-navigation settings">
<details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
Expand Down
8 changes: 4 additions & 4 deletions docs/interfaces/_internal_.NT_PROPS.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h4>Hierarchy</h4>
<ul class="tsd-hierarchy">
<li><span class="target">NT_PROPS</span></li></ul></section><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Chris2fourlaw/ntcore-ts/blob/db304b4/packages/ntcore-ts-client/src/lib/ntcore-ts-client.ts#L8">packages/ntcore-ts-client/src/lib/ntcore-ts-client.ts:8</a></li></ul></aside>
<li>Defined in <a href="https://github.com/Chris2fourlaw/ntcore-ts/blob/43de007/packages/ntcore-ts-client/src/lib/ntcore-ts-client.ts#L8">packages/ntcore-ts-client/src/lib/ntcore-ts-client.ts:8</a></li></ul></aside>
<section class="tsd-panel-group tsd-index-group">
<section class="tsd-panel tsd-index-panel">
<details class="tsd-index-content tsd-index-accordion" open><summary class="tsd-accordion-summary tsd-index-summary">
Expand All @@ -44,21 +44,21 @@ <h3 class="tsd-anchor-link"><span>port</span><a href="#port" aria-label="Permali
<div class="tsd-comment tsd-typography"><p>The port to connect to the robot on.</p>
</div><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Chris2fourlaw/ntcore-ts/blob/db304b4/packages/ntcore-ts-client/src/lib/ntcore-ts-client.ts#L14">packages/ntcore-ts-client/src/lib/ntcore-ts-client.ts:14</a></li></ul></aside></section>
<li>Defined in <a href="https://github.com/Chris2fourlaw/ntcore-ts/blob/43de007/packages/ntcore-ts-client/src/lib/ntcore-ts-client.ts#L14">packages/ntcore-ts-client/src/lib/ntcore-ts-client.ts:14</a></li></ul></aside></section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="team" class="tsd-anchor"></a>
<h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagOptional">Optional</code> <span>team</span><a href="#team" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
<div class="tsd-signature">team<span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">number</span></div>
<div class="tsd-comment tsd-typography"><p>The team number of the robot (overrides URI).</p>
</div><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Chris2fourlaw/ntcore-ts/blob/db304b4/packages/ntcore-ts-client/src/lib/ntcore-ts-client.ts#L10">packages/ntcore-ts-client/src/lib/ntcore-ts-client.ts:10</a></li></ul></aside></section>
<li>Defined in <a href="https://github.com/Chris2fourlaw/ntcore-ts/blob/43de007/packages/ntcore-ts-client/src/lib/ntcore-ts-client.ts#L10">packages/ntcore-ts-client/src/lib/ntcore-ts-client.ts:10</a></li></ul></aside></section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="uri" class="tsd-anchor"></a>
<h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagOptional">Optional</code> <span>uri</span><a href="#uri" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
<div class="tsd-signature">uri<span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">string</span></div>
<div class="tsd-comment tsd-typography"><p>The URI of the robot (not used if team is specified).</p>
</div><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Chris2fourlaw/ntcore-ts/blob/db304b4/packages/ntcore-ts-client/src/lib/ntcore-ts-client.ts#L12">packages/ntcore-ts-client/src/lib/ntcore-ts-client.ts:12</a></li></ul></aside></section></section></div>
<li>Defined in <a href="https://github.com/Chris2fourlaw/ntcore-ts/blob/43de007/packages/ntcore-ts-client/src/lib/ntcore-ts-client.ts#L12">packages/ntcore-ts-client/src/lib/ntcore-ts-client.ts:12</a></li></ul></aside></section></section></div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<div class="tsd-navigation settings">
<details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
Expand Down
Loading

0 comments on commit b88b49f

Please sign in to comment.