@ntcore-ts/client 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +51 -0
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.esm.js +4845 -0
  5. package/dist/index.esm.js.map +1 -0
  6. package/dist/lib/client.d.ts +262 -0
  7. package/dist/lib/client.d.ts.map +1 -0
  8. package/dist/lib/index.d.ts +8 -0
  9. package/dist/lib/index.d.ts.map +1 -0
  10. package/dist/lib/pubsub/base-topic.d.ts +104 -0
  11. package/dist/lib/pubsub/base-topic.d.ts.map +1 -0
  12. package/dist/lib/pubsub/index.d.ts +6 -0
  13. package/dist/lib/pubsub/index.d.ts.map +1 -0
  14. package/dist/lib/pubsub/json-topic.d.ts +50 -0
  15. package/dist/lib/pubsub/json-topic.d.ts.map +1 -0
  16. package/dist/lib/pubsub/prefix-topic.d.ts +45 -0
  17. package/dist/lib/pubsub/prefix-topic.d.ts.map +1 -0
  18. package/dist/lib/pubsub/protobuf-schema-manager.d.ts +96 -0
  19. package/dist/lib/pubsub/protobuf-schema-manager.d.ts.map +1 -0
  20. package/dist/lib/pubsub/protobuf-topic.d.ts +126 -0
  21. package/dist/lib/pubsub/protobuf-topic.d.ts.map +1 -0
  22. package/dist/lib/pubsub/pubsub.d.ts +134 -0
  23. package/dist/lib/pubsub/pubsub.d.ts.map +1 -0
  24. package/dist/lib/pubsub/struct-topic.d.ts +40 -0
  25. package/dist/lib/pubsub/struct-topic.d.ts.map +1 -0
  26. package/dist/lib/pubsub/topic.d.ts +134 -0
  27. package/dist/lib/pubsub/topic.d.ts.map +1 -0
  28. package/dist/lib/socket/messenger.d.ts +104 -0
  29. package/dist/lib/socket/messenger.d.ts.map +1 -0
  30. package/dist/lib/socket/socket.d.ts +193 -0
  31. package/dist/lib/socket/socket.d.ts.map +1 -0
  32. package/dist/lib/struct/built-in-schemas.d.ts +21 -0
  33. package/dist/lib/struct/built-in-schemas.d.ts.map +1 -0
  34. package/dist/lib/struct/geometry.d.ts +129 -0
  35. package/dist/lib/struct/geometry.d.ts.map +1 -0
  36. package/dist/lib/struct/index.d.ts +5 -0
  37. package/dist/lib/struct/index.d.ts.map +1 -0
  38. package/dist/lib/struct/struct-codec.d.ts +14 -0
  39. package/dist/lib/struct/struct-codec.d.ts.map +1 -0
  40. package/dist/lib/struct/struct-descriptor.d.ts +60 -0
  41. package/dist/lib/struct/struct-descriptor.d.ts.map +1 -0
  42. package/dist/lib/struct/struct-parser.d.ts +28 -0
  43. package/dist/lib/struct/struct-parser.d.ts.map +1 -0
  44. package/dist/lib/struct/struct-schema-manager.d.ts +41 -0
  45. package/dist/lib/struct/struct-schema-manager.d.ts.map +1 -0
  46. package/dist/lib/types/index.d.ts +2 -0
  47. package/dist/lib/types/index.d.ts.map +1 -0
  48. package/dist/lib/types/schemas.d.ts +269 -0
  49. package/dist/lib/types/schemas.d.ts.map +1 -0
  50. package/dist/lib/types/types.d.ts +66 -0
  51. package/dist/lib/types/types.d.ts.map +1 -0
  52. package/dist/lib/util/logger.d.ts +60 -0
  53. package/dist/lib/util/logger.d.ts.map +1 -0
  54. package/dist/lib/util/util.d.ts +68 -0
  55. package/dist/lib/util/util.d.ts.map +1 -0
  56. package/package.json +64 -0
@@ -0,0 +1,134 @@
1
+ import { NetworkTablesBaseTopic } from './base-topic';
2
+ import type { CallbackFn } from './base-topic';
3
+ import type { PubSubClient } from './pubsub';
4
+ import type { AnnounceMessage, AnnounceMessageParams, NetworkTablesTypeInfo, NetworkTablesTypes, SubscribeOptions, TopicProperties } from '../types/types';
5
+ export declare class NetworkTablesTopic<TWire extends NetworkTablesTypes, TPublic = TWire> extends NetworkTablesBaseTopic<TPublic> {
6
+ readonly type = "regular";
7
+ private _wireValue;
8
+ private readonly _typeInfo;
9
+ protected _publisher: boolean;
10
+ protected _pubuid?: number;
11
+ protected _publishProperties?: TopicProperties;
12
+ /**
13
+ * Gets the type info for the topic.
14
+ * @returns The type info for the topic.
15
+ */
16
+ get typeInfo(): NetworkTablesTypeInfo;
17
+ /**
18
+ * Gets whether the client is the publisher of the topic.
19
+ * @returns Whether the client is the publisher of the topic.
20
+ */
21
+ get publisher(): boolean;
22
+ /**
23
+ * Gets the UID of the publisher.
24
+ * @returns The UID of the publisher, or undefined if the client is not the publisher.
25
+ */
26
+ get pubuid(): number | undefined;
27
+ /**
28
+ * Creates a new topic. This should only be done after the
29
+ * base NTCore client has been initialized.
30
+ * @param client - The client that owns the topic.
31
+ * @param name - The name of the topic.
32
+ * @param typeInfo - The type info for the topic.
33
+ * @param defaultValue - The default value for the topic.
34
+ */
35
+ constructor(client: PubSubClient, name: string, typeInfo: NetworkTablesTypeInfo, defaultValue?: TPublic);
36
+ /**
37
+ * Sets the value of the topic.
38
+ * The client must be the publisher of the topic to set the value.
39
+ * @param value - The value to set.
40
+ */
41
+ setValue(value: TPublic): void;
42
+ /** Internal: set wire-format value and notify subscribers. Subclasses may call this when encoding decoded values. */
43
+ protected setWireValue(value: TWire): void;
44
+ /** Called after setWireValue from subclasses that encode before setting. Runs prefix notify and updateServer. */
45
+ protected afterSetWireValue(): void;
46
+ /** Params for prefix notify; use real announce params when we have them, else minimal fallback. */
47
+ private getAnnounceParamsForNotify;
48
+ /**
49
+ * Resends the latest retained value after reconnect.
50
+ *
51
+ * This is intended to be called after reconnect, once publish frames have been re-sent.
52
+ * This ensures that if the server/robot restarted, it receives the current state.
53
+ */
54
+ resendLatestValue(): void;
55
+ /**
56
+ * Gets the value of the topic.
57
+ * @returns The value of the topic.
58
+ */
59
+ getValue(): TPublic | null;
60
+ /**
61
+ * Updates the value of the topic.
62
+ * This should only be called by the PubSubClient.
63
+ * @param value - The value to update (wire format).
64
+ * @param lastChangedTime - The server time of the last value change.
65
+ */
66
+ updateValue(value: TWire, lastChangedTime: number): void;
67
+ /** */
68
+ /** */
69
+ /**
70
+ * Marks the topic as announced. This should only be called by the PubSubClient.
71
+ * @param params - The parameters of the announcement.
72
+ */
73
+ announce(params: AnnounceMessageParams): void;
74
+ /** */
75
+ /** */
76
+ /**
77
+ * Creates a new subscriber.
78
+ * @param callback - The callback to call when the topic value changes.
79
+ * @param options - The options for the subscriber. `immediateNotify` is client-side only and is
80
+ * not sent to the NT server. `id` and `save` are not part of this public signature.
81
+ * @returns The UID of the subscriber.
82
+ */
83
+ subscribe(callback: CallbackFn<TPublic>, options?: Omit<SubscribeOptions, 'prefix'>): number;
84
+ /**
85
+ * Creates a new subscriber, optionally reusing a subscription UID.
86
+ * @internal Used by resubscribeAll. Does not honor `immediateNotify`.
87
+ * @param callback - The callback to call when the topic value changes.
88
+ * @param options - The options for the subscriber.
89
+ * @param id - The UID of the subscriber. You must verify that the ID is not already in use.
90
+ * @param save - Whether to save the subscriber.
91
+ * @returns The UID of the subscriber.
92
+ */
93
+ protected subscribeWithId(callback: CallbackFn<TPublic>, options?: Omit<SubscribeOptions, 'prefix'>, id?: number, save?: boolean): number;
94
+ resubscribeAll(client: PubSubClient): void;
95
+ /**
96
+ * Notifies all subscribers of the current value.
97
+ * Protected so derived classes (e.g. NetworkTablesProtobufTopic) can override
98
+ * and pass decoded/transformed values to callbacks.
99
+ */
100
+ protected notifySubscribers(): void;
101
+ /** */
102
+ /** */
103
+ /**
104
+ * Publishes the topic.
105
+ * @param properties - The properties to publish the topic with.
106
+ * @param id - The UID of the publisher. You must verify that the ID is not already in use.
107
+ * @returns A promise that resolves when the topic is published.
108
+ */
109
+ publish(properties?: TopicProperties, id?: number): Promise<AnnounceMessage | void>;
110
+ /**
111
+ * Unpublishes the topic.
112
+ */
113
+ unpublish(): void;
114
+ /**
115
+ * Republishes the topic.
116
+ * @param client - The client to republish with.
117
+ * @returns A promise that resolves when the topic is republished.
118
+ */
119
+ republish(client: PubSubClient): Promise<void | {
120
+ method: "announce";
121
+ params: {
122
+ name: string;
123
+ id: number;
124
+ type: string;
125
+ properties: {
126
+ persistent?: boolean | undefined;
127
+ retained?: boolean | undefined;
128
+ cached?: boolean | undefined;
129
+ };
130
+ pubuid?: number | undefined;
131
+ };
132
+ }>;
133
+ }
134
+ //# sourceMappingURL=topic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"topic.d.ts","sourceRoot":"","sources":["../../../src/lib/pubsub/topic.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAGlB,gBAAgB,EAChB,eAAe,EAChB,MAAM,gBAAgB,CAAC;AAExB,qBAAa,kBAAkB,CAC7B,KAAK,SAAS,kBAAkB,EAChC,OAAO,GAAG,KAAK,CACf,SAAQ,sBAAsB,CAAC,OAAO,CAAC;IACvC,QAAQ,CAAC,IAAI,aAAa;IAC1B,OAAO,CAAC,UAAU,CAAe;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAwB;IAClD,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC;IAC9B,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,kBAAkB,CAAC,EAAE,eAAe,CAAC;IAE/C;;;OAGG;IACH,IAAI,QAAQ,IAAI,qBAAqB,CAEpC;IAED;;;OAGG;IACH,IAAI,SAAS,YAEZ;IAED;;;OAGG;IACH,IAAI,MAAM,uBAET;IAED;;;;;;;OAOG;gBACS,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,qBAAqB,EAAE,YAAY,CAAC,EAAE,OAAO;IA0BvG;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO;IAWvB,qHAAqH;IACrH,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAK1C,iHAAiH;IACjH,SAAS,CAAC,iBAAiB,IAAI,IAAI;IAkBnC,mGAAmG;IACnG,OAAO,CAAC,0BAA0B;IAIlC;;;;;OAKG;IACH,iBAAiB;IAiBjB;;;OAGG;IACH,QAAQ,IAAI,OAAO,GAAG,IAAI;IAI1B;;;;;OAKG;IACH,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM;IAajD,MAAM;IAEN,MAAM;IAEN;;;OAGG;IACM,QAAQ,CAAC,MAAM,EAAE,qBAAqB;IAe/C,MAAM;IAEN,MAAM;IAEN;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,OAAO,GAAE,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAM;IAiBvF;;;;;;;;OAQG;IACH,SAAS,CAAC,eAAe,CACvB,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,EAC7B,OAAO,GAAE,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAM,EAC9C,EAAE,CAAC,EAAE,MAAM,EACX,IAAI,UAAO;IAuBb,cAAc,CAAC,MAAM,EAAE,YAAY;IASnC;;;;OAIG;IACH,SAAS,CAAC,iBAAiB;IA0B3B,MAAM;IAEN,MAAM;IAEN;;;;;OAKG;IACG,OAAO,CAAC,UAAU,GAAE,eAAoB,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IA0B7F;;OAEG;IACH,SAAS;IAiBT;;;;OAIG;IACG,SAAS,CAAC,MAAM,EAAE,YAAY;;;;;;;;;;;;;;CAWrC"}
@@ -0,0 +1,104 @@
1
+ import { NetworkTablesSocket } from './socket';
2
+ import type { NetworkTablesTopic } from '../pubsub/topic';
3
+ import type { PublishMessageParams, SetPropertiesMessageParams, SubscribeMessageParams, NetworkTablesTypes, BinaryMessageData, AnnounceMessageParams, UnannounceMessageParams, PropertiesMessageParams, AnnounceMessage, PropertiesMessage } from '../types/types';
4
+ /** NetworkTables client. */
5
+ export declare class Messenger {
6
+ private readonly _socket;
7
+ private readonly publications;
8
+ private readonly subscriptions;
9
+ private static _instances;
10
+ private _currentPubUID;
11
+ private _currentSubUID;
12
+ private readonly _onAnnounce;
13
+ /**
14
+ * Gets the NetworkTablesSocket used by the Messenger.
15
+ * @returns The NetworkTablesSocket used by the Messenger.
16
+ */
17
+ get socket(): NetworkTablesSocket;
18
+ /**
19
+ * Creates a new NetworkTables client.
20
+ * @param serverUrl - The URL of the server to connect to.
21
+ * @param onTopicUpdate - Called when a topic is updated.
22
+ * @param onAnnounce - Called when a topic is announced.
23
+ * @param onUnannounce - Called when a topic is unannounced.
24
+ * @param onTopicProperties - Called when a topic's properties are updated.
25
+ */
26
+ private constructor();
27
+ /**
28
+ * Gets the instance of the NetworkTables client.
29
+ * @param serverUrl - The URL of the server to connect to. This is not needed after the first call.
30
+ * @param onTopicUpdate - Called when a topic is updated.
31
+ * @param onAnnounce - Called when a topic is announced.
32
+ * @param onUnannounce - Called when a topic is unannounced.
33
+ * @param onTopicProperties - Called when a topic's properties are updated.
34
+ * @returns The instance of the NetworkTables client.
35
+ */
36
+ static getInstance(serverUrl: string, onTopicUpdate: (_: BinaryMessageData) => void, onAnnounce: (_: AnnounceMessageParams) => void, onUnannounce: (_: UnannounceMessageParams) => void, onTopicProperties: (_: PropertiesMessageParams) => void): Messenger;
37
+ /**
38
+ * Reinstantiates the messenger by resetting the socket with a new URL.
39
+ * @param serverUrl - The URL of the server to connect to.
40
+ */
41
+ reinstantiate(serverUrl: string): void;
42
+ /**
43
+ * Called when the socket opens.
44
+ */
45
+ onSocketOpen: () => void;
46
+ /**
47
+ * Called when the socket closes.
48
+ */
49
+ onSocketClose: () => void;
50
+ private parseAndFilterMessage;
51
+ /**
52
+ * Publishes a topic to the server.
53
+ * @param params - The publication parameters.
54
+ * @param force - Whether to force the publication.
55
+ * @returns The announcement parameters.
56
+ */
57
+ publish(params: PublishMessageParams, force?: boolean): Promise<AnnounceMessage>;
58
+ private sendPublishFrames;
59
+ /**
60
+ * Unpublishes a topic from the server.
61
+ * @param pubuid - The publication ID to unpublish.
62
+ */
63
+ unpublish(pubuid: number): void;
64
+ /**
65
+ * Subscribes to a topic.
66
+ * @param params - The subscription parameters.
67
+ * @param force - Whether to force the subscription.
68
+ */
69
+ subscribe(params: SubscribeMessageParams, force?: boolean): void;
70
+ /**
71
+ * Unsubscribes from a topic.
72
+ * @param subuid - The subscription ID to unsubscribe from.
73
+ */
74
+ unsubscribe(subuid: number): void;
75
+ /**
76
+ * Sets the properties of a topic.
77
+ * @param params - The parameters to set
78
+ * @returns The new properties of the topic.
79
+ */
80
+ setProperties(params: SetPropertiesMessageParams): Promise<PropertiesMessage>;
81
+ /**
82
+ * Send data to a topic.
83
+ * This should only be called by the PubSubClient.
84
+ * @param topic - The topic to update.
85
+ * @param value - The value to update the topic to.
86
+ * @returns The timestamp of the update, or -1 if the socket is not connected.
87
+ */
88
+ sendToTopic<TWire extends NetworkTablesTypes, TPublic = TWire>(topic: NetworkTablesTopic<TWire, TPublic>, value: TWire): number;
89
+ /**
90
+ * Gets the next available publisher UID.
91
+ * @returns The next available publisher UID.
92
+ */
93
+ getNextPubUID(): number;
94
+ /**
95
+ * Gets the next available subscriber UID.
96
+ * @returns The next available subscriber UID.
97
+ */
98
+ getNextSubUID(): number;
99
+ /**
100
+ * Removes this messenger and its socket from their singleton maps.
101
+ */
102
+ releaseInstance(): void;
103
+ }
104
+ //# sourceMappingURL=messenger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messenger.d.ts","sourceRoot":"","sources":["../../../src/lib/socket/messenger.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,KAAK,EAGV,oBAAoB,EAEpB,0BAA0B,EAE1B,s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KAAK,CAAC,EAAE,OAAO;IA2BzD;;;OAGG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM;IAoB1B;;;;OAIG;IACG,aAAa,CAAC,MAAM,EAAE,0BAA0B,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAmEnF;;;;;;OAMG;IACH,WAAW,CAAC,KAAK,SAAS,kBAAkB,EAAE,OAAO,GAAG,KAAK,EAC3D,KAAK,EAAE,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC,EACzC,KAAK,EAAE,KAAK;IAUd;;;OAGG;IACH,aAAa;IAMb;;;OAGG;IACH,aAAa;IAMb;;OAEG;IACH,eAAe,IAAI,IAAI;CAQxB"}
@@ -0,0 +1,193 @@
1
+ import WebSocket from 'isomorphic-ws';
2
+ import type { AnnounceMessageParams, Message, PropertiesMessageParams, UnannounceMessageParams, NetworkTablesTypes, NetworkTablesTypeInfo, BinaryMessageData } from '../types/types';
3
+ /** Socket for NetworkTables 4.1 */
4
+ export declare class NetworkTablesSocket {
5
+ private static instances;
6
+ private static readonly PROTOCOL_V4_0;
7
+ private static readonly PROTOCOL_V4_1;
8
+ private static readonly RECONNECT_TIMEOUT;
9
+ /** Timestamp keepalive period when WebSocket PING cannot be sent (NT 4.0 and JS 4.1). */
10
+ private static readonly RTT_PERIOD_MS;
11
+ /** Disconnect if no server frames arrive. Spec: ~3s when using timestamp messages for aliveness. */
12
+ private static readonly IDLE_TIMEOUT_MS;
13
+ private readonly connectionListeners;
14
+ private offset;
15
+ private bestRtt;
16
+ /** True after the first valid RTT reply; required before control frames and strong value publishes. */
17
+ private clockSynced;
18
+ private heartbeatInterval;
19
+ private idleTimer;
20
+ private reconnectTimer;
21
+ private connectionAttemptCount;
22
+ private lastConnectionLogTime;
23
+ private tearingDown;
24
+ private readonly connectionWaiters;
25
+ private static readonly CONNECTION_LOG_INTERVAL;
26
+ private _websocket;
27
+ get websocket(): WebSocket;
28
+ private serverUrl;
29
+ private readonly onSocketOpen;
30
+ private readonly onSocketClose;
31
+ private readonly onTopicUpdate;
32
+ private readonly onAnnounce;
33
+ private readonly onUnannounce;
34
+ private readonly onProperties;
35
+ private autoConnect;
36
+ private messageQueue;
37
+ /**
38
+ * Creates a new NetworkTables socket.
39
+ * @param serverUrl - The URL of the server to connect to.
40
+ * @param onSocketOpen - Called when the socket is opened.
41
+ * @param onSocketClose - Called when the socket is closed.
42
+ * @param onTopicUpdate - Called when a topic is updated.
43
+ * @param onAnnounce - Called when a topic is announced.
44
+ * @param onUnannounce - Called when a topic is unannounced.
45
+ * @param onProperties - Called when a topic's properties are updated.
46
+ * @param autoConnect - Whether to automatically connect to the server.
47
+ */
48
+ private constructor();
49
+ /**
50
+ * Gets the instance of the NetworkTables socket.
51
+ * @param serverUrl - The URL of the server to connect to.
52
+ * @param onSocketOpen - Called when the socket is opened.
53
+ * @param onSocketClose - Called when the socket is closed.
54
+ * @param onTopicUpdate - Called when a topic is updated.
55
+ * @param onAnnounce - Called when a topic is announced.
56
+ * @param onUnannounce - Called when a topic is unannounced.
57
+ * @param onProperties - Called when a topic's properties are updated.
58
+ * @param autoConnect - Whether to automatically connect to the server.
59
+ * @returns The instance of the NetworkTables socket.
60
+ */
61
+ static getInstance(serverUrl: string, onSocketOpen: () => void, onSocketClose: () => void, onTopicUpdate: (_: BinaryMessageData) => void, onAnnounce: (_: AnnounceMessageParams) => void, onUnannounce: (_: UnannounceMessageParams) => void, onProperties: (_: PropertiesMessageParams) => void, autoConnect?: boolean): NetworkTablesSocket;
62
+ /**
63
+ * Initialization. This is done outside of the constructor to allow for
64
+ * the socket to refresh itself.
65
+ */
66
+ private init;
67
+ /**
68
+ * Reset the socket and reconnect to the server.
69
+ * @param serverUrl - The URL of the server to connect to.
70
+ */
71
+ reinstantiate(serverUrl: string): void;
72
+ /**
73
+ * Returns whether the socket is open and the client clock is synchronized with the server.
74
+ * @returns Whether the robot connection is ready for control and value frames.
75
+ */
76
+ isConnected(): boolean;
77
+ /**
78
+ * Returns whether the socket is connecting (including waiting for the first RTT).
79
+ * @returns Whether the robot connection is not yet ready.
80
+ */
81
+ isConnecting(): boolean;
82
+ /**
83
+ * Wait for the socket to connect.
84
+ * @returns A promise that resolves when the socket is connected.
85
+ */
86
+ waitForConnection(): Promise<void>;
87
+ /**
88
+ * Create a connection listener.
89
+ * @param callback - Called when the connection state changes.
90
+ * @param immediateNotify - When true, the callback is also invoked with the current connection state
91
+ * on a microtask after this method returns, so the returned disposer can be used safely from that
92
+ * first invocation (unlike a synchronous notify before return).
93
+ * @returns A function that removes the listener.
94
+ */
95
+ addConnectionListener(callback: (_: boolean) => void, immediateNotify?: boolean): () => void;
96
+ /**
97
+ * Remove a connection listener.
98
+ * @param callback - The callback to remove.
99
+ */
100
+ removeConnectionListener(callback: (_: boolean) => void): void;
101
+ /**
102
+ * Get the best round-trip time to the server in milliseconds.
103
+ * @returns RTT in ms, or -1 if not connected or not yet measured.
104
+ */
105
+ getBestRttMs(): number;
106
+ /**
107
+ * Updates all connection listeners with the current connection state.
108
+ */
109
+ private updateConnectionListeners;
110
+ /**
111
+ * Stops auto-reconnecting to the server.
112
+ */
113
+ stopAutoConnect(): void;
114
+ /**
115
+ * Starts auto-reconnecting to the server. If the socket is closed, opens a new connection.
116
+ */
117
+ startAutoConnect(): void;
118
+ private clearReconnectTimer;
119
+ private rejectConnectionWaiters;
120
+ /**
121
+ * Handle a message from the websocket.
122
+ * @param event - The message event.
123
+ */
124
+ private onMessage;
125
+ /**
126
+ * Handle an error from the websocket.
127
+ * @param event - The error event.
128
+ */
129
+ private onError;
130
+ /**
131
+ * Handle a binary frame from the websocket.
132
+ * Uses sync decodeMulti (not async streams): we receive one complete frame per
133
+ * WebSocket message, so decodeMultiStream would add async overhead without benefit.
134
+ * @param frame - The frame.
135
+ */
136
+ private handleBinaryFrame;
137
+ /**
138
+ * Handle a text frame from the websocket.
139
+ * @param frame - The frame.
140
+ */
141
+ private handleTextFrame;
142
+ /**
143
+ * Send a text frame to the server.
144
+ * @param message - The message to send.
145
+ */
146
+ sendTextFrame(message: Message): void;
147
+ /**
148
+ * Function to send queued messages whenever the WebSocket connection is opened
149
+ */
150
+ private sendQueuedMessages;
151
+ /**
152
+ * Send a message to a topic.
153
+ * @param pubuid - The topic's publisher UID.
154
+ * @param value - The value to send.
155
+ * @param typeInfo - The type info for the value.
156
+ * @returns The time the message was sent, or -1 if not connected.
157
+ */
158
+ sendValueToTopic(pubuid: number, value: NetworkTablesTypes, typeInfo: NetworkTablesTypeInfo): number;
159
+ /**
160
+ * Send a timestamp ping to the server (topic id -1, timestamp 0, value = client microseconds).
161
+ */
162
+ private heartbeat;
163
+ /**
164
+ * Handle a round trip time message from the server.
165
+ *
166
+ * RTT is `now - echoed client time` (the MessagePack value). Clock offset is updated only when
167
+ * this RTT is the best so far (Cristian's algorithm / NT spec).
168
+ * @param serverTime - Server timestamp from the reply.
169
+ * @param clientEcho - Client time echoed back from the ping.
170
+ */
171
+ private handleRTT;
172
+ /**
173
+ * Get the current server time.
174
+ * @returns The current server time.
175
+ */
176
+ private getServerTime;
177
+ private isSocketOpen;
178
+ private resetClockSync;
179
+ private completeHandshakeIfNeeded;
180
+ private resetIdleTimer;
181
+ private clearIdleTimer;
182
+ private clearHeartbeatInterval;
183
+ /**
184
+ * Close the websocket connection.
185
+ */
186
+ close(): void;
187
+ /**
188
+ * Removes this socket from the singleton map so a later getInstance can create a new one.
189
+ */
190
+ releaseInstance(): void;
191
+ }
192
+ export default NetworkTablesSocket;
193
+ //# sourceMappingURL=socket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../../src/lib/socket/socket.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,eAAe,CAAC;AAOtC,OAAO,KAAK,EACV,qBAAqB,EACrB,OAAO,EACP,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAGxB,mCAAmC;AACnC,qBAAa,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OAAO,CAAC,kBAAkB;IAe1B;;;;;;OAMG;IACH,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,qBAAqB;IAwB3F;;OAEG;IACH,OAAO,CAAC,SAAS;IAWjB;;;;;;;OAOG;IACH,OAAO,CAAC,SAAS;IA2BjB;;;OAGG;IACH,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,yBAAyB;IAYjC,OAAO,CAAC,cAAc;IAetB,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,sBAAsB;IAO9B;;OAEG;IACH,KAAK;IAUL;;OAEG;IACH,eAAe,IAAI,IAAI;CAOxB;AAED,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { StructDescriptor } from './struct-descriptor';
2
+ declare const SCHEMAS: {
3
+ readonly Translation2d: "double x;double y";
4
+ readonly Rotation2d: "double value";
5
+ readonly Pose2d: "Translation2d translation;Rotation2d rotation";
6
+ readonly Transform2d: "Translation2d translation;Rotation2d rotation";
7
+ readonly Twist2d: "double dx;double dy;double dtheta";
8
+ readonly Translation3d: "double x;double y;double z";
9
+ readonly Quaternion: "double w;double x;double y;double z";
10
+ readonly Rotation3d: "Quaternion q";
11
+ readonly Pose3d: "Translation3d translation;Rotation3d rotation";
12
+ readonly Transform3d: "Translation3d translation;Rotation3d rotation";
13
+ readonly Twist3d: "double dx;double dy;double dz;double rx;double ry;double rz";
14
+ };
15
+ export declare function getBuiltInDescriptor(typeName: string): StructDescriptor | null;
16
+ /** All built-in struct type names (WPILib geometry). */
17
+ export declare const BUILT_IN_STRUCT_TYPE_NAMES: (keyof typeof SCHEMAS)[];
18
+ /** Returns the schema string for a built-in type, or undefined. */
19
+ export declare function getBuiltInSchemaString(typeName: string): string | undefined;
20
+ export {};
21
+ //# sourceMappingURL=built-in-schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"built-in-schemas.d.ts","sourceRoot":"","sources":["../../../src/lib/struct/built-in-schemas.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,QAAA,MAAM,OAAO;;;;;;;;;;;;CAYH,CAAC;AAkCX,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAU9E;AAED,wDAAwD;AACxD,eAAO,MAAM,0BAA0B,EAA2B,CAAC,MAAM,OAAO,OAAO,CAAC,EAAE,CAAC;AAE3F,mEAAmE;AACnE,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE3E"}
@@ -0,0 +1,129 @@
1
+ import { z } from 'zod';
2
+ import { BUILT_IN_STRUCT_TYPE_NAMES } from './built-in-schemas';
3
+ /** WPILib built-in struct type names (geometry). */
4
+ export type BuiltInStructTypeName = (typeof BUILT_IN_STRUCT_TYPE_NAMES)[number];
5
+ /**
6
+ * Struct type name accepted by getStructTopic.
7
+ * Built-in names, their array forms, or any custom type string.
8
+ */
9
+ export type StructTypeName = BuiltInStructTypeName | `${BuiltInStructTypeName}[]` | (string & {});
10
+ /**
11
+ * WPILib-style struct type descriptor (e.g. `Pose2d`) used to infer the topic value type.
12
+ * `schema` is a Zod schema matching the unpacked plain-object shape.
13
+ */
14
+ export interface StructTypeDescriptor<T extends object = object> {
15
+ readonly typeName: string;
16
+ readonly schema: z.ZodType<T>;
17
+ }
18
+ /**
19
+ * Returns true when the argument is a WPILib-style struct type descriptor (e.g. `Pose2d`).
20
+ * @param value - The value to check.
21
+ * @returns Whether the value is a struct type descriptor.
22
+ */
23
+ export declare function isStructTypeDescriptor(value: unknown): value is StructTypeDescriptor<object>;
24
+ /** Unpacked `Translation2d` (`double x; double y`). */
25
+ export interface Translation2d {
26
+ x: number;
27
+ y: number;
28
+ }
29
+ /** Zod schema for {@link Translation2d}. */
30
+ export declare const Translation2dSchema: z.ZodType<Translation2d>;
31
+ /** WPILib-style `Translation2d.struct` descriptor. */
32
+ export declare const Translation2d: StructTypeDescriptor<Translation2d>;
33
+ /** Unpacked `Rotation2d` (`double value`). */
34
+ export interface Rotation2d {
35
+ value: number;
36
+ }
37
+ /** Zod schema for {@link Rotation2d}. */
38
+ export declare const Rotation2dSchema: z.ZodType<Rotation2d>;
39
+ /** WPILib-style `Rotation2d.struct` descriptor. */
40
+ export declare const Rotation2d: StructTypeDescriptor<Rotation2d>;
41
+ /** Unpacked `Pose2d` (`Translation2d translation; Rotation2d rotation`). */
42
+ export interface Pose2d {
43
+ translation: Translation2d;
44
+ rotation: Rotation2d;
45
+ }
46
+ /** Zod schema for {@link Pose2d}. */
47
+ export declare const Pose2dSchema: z.ZodType<Pose2d>;
48
+ /** WPILib-style `Pose2d.struct` descriptor. */
49
+ export declare const Pose2d: StructTypeDescriptor<Pose2d>;
50
+ /** Unpacked `Transform2d` (`Translation2d translation; Rotation2d rotation`). */
51
+ export interface Transform2d {
52
+ translation: Translation2d;
53
+ rotation: Rotation2d;
54
+ }
55
+ /** Zod schema for {@link Transform2d}. */
56
+ export declare const Transform2dSchema: z.ZodType<Transform2d>;
57
+ /** WPILib-style `Transform2d.struct` descriptor. */
58
+ export declare const Transform2d: StructTypeDescriptor<Transform2d>;
59
+ /** Unpacked `Twist2d` (`double dx; double dy; double dtheta`). */
60
+ export interface Twist2d {
61
+ dx: number;
62
+ dy: number;
63
+ dtheta: number;
64
+ }
65
+ /** Zod schema for {@link Twist2d}. */
66
+ export declare const Twist2dSchema: z.ZodType<Twist2d>;
67
+ /** WPILib-style `Twist2d.struct` descriptor. */
68
+ export declare const Twist2d: StructTypeDescriptor<Twist2d>;
69
+ /** Unpacked `Translation3d` (`double x; double y; double z`). */
70
+ export interface Translation3d {
71
+ x: number;
72
+ y: number;
73
+ z: number;
74
+ }
75
+ /** Zod schema for {@link Translation3d}. */
76
+ export declare const Translation3dSchema: z.ZodType<Translation3d>;
77
+ /** WPILib-style `Translation3d.struct` descriptor. */
78
+ export declare const Translation3d: StructTypeDescriptor<Translation3d>;
79
+ /** Unpacked `Quaternion` (`double w; double x; double y; double z`). */
80
+ export interface Quaternion {
81
+ w: number;
82
+ x: number;
83
+ y: number;
84
+ z: number;
85
+ }
86
+ /** Zod schema for {@link Quaternion}. */
87
+ export declare const QuaternionSchema: z.ZodType<Quaternion>;
88
+ /** WPILib-style `Quaternion.struct` descriptor. */
89
+ export declare const Quaternion: StructTypeDescriptor<Quaternion>;
90
+ /** Unpacked `Rotation3d` (`Quaternion q`). */
91
+ export interface Rotation3d {
92
+ q: Quaternion;
93
+ }
94
+ /** Zod schema for {@link Rotation3d}. */
95
+ export declare const Rotation3dSchema: z.ZodType<Rotation3d>;
96
+ /** WPILib-style `Rotation3d.struct` descriptor. */
97
+ export declare const Rotation3d: StructTypeDescriptor<Rotation3d>;
98
+ /** Unpacked `Pose3d` (`Translation3d translation; Rotation3d rotation`). */
99
+ export interface Pose3d {
100
+ translation: Translation3d;
101
+ rotation: Rotation3d;
102
+ }
103
+ /** Zod schema for {@link Pose3d}. */
104
+ export declare const Pose3dSchema: z.ZodType<Pose3d>;
105
+ /** WPILib-style `Pose3d.struct` descriptor. */
106
+ export declare const Pose3d: StructTypeDescriptor<Pose3d>;
107
+ /** Unpacked `Transform3d` (`Translation3d translation; Rotation3d rotation`). */
108
+ export interface Transform3d {
109
+ translation: Translation3d;
110
+ rotation: Rotation3d;
111
+ }
112
+ /** Zod schema for {@link Transform3d}. */
113
+ export declare const Transform3dSchema: z.ZodType<Transform3d>;
114
+ /** WPILib-style `Transform3d.struct` descriptor. */
115
+ export declare const Transform3d: StructTypeDescriptor<Transform3d>;
116
+ /** Unpacked `Twist3d` (`double dx; double dy; double dz; double rx; double ry; double rz`). */
117
+ export interface Twist3d {
118
+ dx: number;
119
+ dy: number;
120
+ dz: number;
121
+ rx: number;
122
+ ry: number;
123
+ rz: number;
124
+ }
125
+ /** Zod schema for {@link Twist3d}. */
126
+ export declare const Twist3dSchema: z.ZodType<Twist3d>;
127
+ /** WPILib-style `Twist3d.struct` descriptor. */
128
+ export declare const Twist3d: StructTypeDescriptor<Twist3d>;
129
+ //# sourceMappingURL=geometry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../../src/lib/struct/geometry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAEhE,oDAAoD;AACpD,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhF;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,qBAAqB,GAAG,GAAG,qBAAqB,IAAI,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAElG;;;GAGG;AACH,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IAC7D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;CAC/B;AAMD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAO5F;AAMD,uDAAuD;AACvD,MAAM,WAAW,aAAa;IAC5B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,4CAA4C;AAC5C,eAAO,MAAM,mBAAmB,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAGvD,CAAC;AAEH,sDAAsD;AACtD,eAAO,MAAM,aAAa,EAAE,oBAAoB,CAAC,aAAa,CAG7D,CAAC;AAEF,8CAA8C;AAC9C,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,C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/F,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,sCAAsC;AACtC,eAAO,MAAM,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAO3C,CAAC;AAEH,gDAAgD;AAChD,eAAO,MAAM,OAAO,EAAE,oBAAoB,CAAC,OAAO,CAGjD,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { type StructDescriptor, type StructFieldDescriptor, type PrimitiveTypeName, PRIMITIVE_SIZES, getPrimitiveSize, isPrimitiveType, } from './struct-descriptor';
2
+ export { parseSchema, buildStructDescriptor, type ParsedField } from './struct-parser';
3
+ export { pack, unpack, type StructPlainObject } from './struct-codec';
4
+ export { getBuiltInDescriptor, BUILT_IN_STRUCT_TYPE_NAMES } from './built-in-schemas';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/struct/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,eAAe,EACf,gBAAgB,EAChB,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACvF,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { StructDescriptor } from './struct-descriptor';
2
+ /** Plain object representation of a struct (for pack input / unpack output). */
3
+ export type StructPlainObject = Record<string, unknown>;
4
+ /**
5
+ * Unpacks a little-endian binary buffer into a plain object using the struct descriptor.
6
+ * @throws Error if buffer is too small for the descriptor size.
7
+ */
8
+ export declare function unpack(buffer: Uint8Array, descriptor: StructDescriptor): StructPlainObject;
9
+ /**
10
+ * Packs a plain object into a little-endian Uint8Array using the struct descriptor.
11
+ * @throws Error if value is missing required fields or has invalid types.
12
+ */
13
+ export declare function pack(value: StructPlainObject, descriptor: StructDescriptor): Uint8Array;
14
+ //# sourceMappingURL=struct-codec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"struct-codec.d.ts","sourceRoot":"","sources":["../../../src/lib/struct/struct-codec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAyB,MAAM,qBAAqB,CAAC;AAGnF,gFAAgF;AAChF,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAExD;;;GAGG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,gBAAgB,GAAG,iBAAiB,CAY1F;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,gBAAgB,GAAG,UAAU,CAWvF"}