@2702rebels/ntcore 1.0.0 → 1.0.1
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.
- package/dist/index.cjs +18 -0
- package/dist/index.d.cts +193 -193
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +193 -193
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +18 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/NT4Client.ts +4 -0
- package/src/NT4Topic.ts +33 -0
package/dist/index.d.mts
CHANGED
|
@@ -6,26 +6,26 @@
|
|
|
6
6
|
*/
|
|
7
7
|
type TopicProperties = Record<string, unknown> & {
|
|
8
8
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
* **Persistent flag**
|
|
10
|
+
*
|
|
11
|
+
* If `true`, the last set value will be periodically saved to persistent storage on the server
|
|
12
|
+
* and be restored during server startup. Topics with this property set to `true` will not
|
|
13
|
+
* be deleted by the server when the last publisher stops publishing.
|
|
14
|
+
*/
|
|
15
15
|
persistent?: boolean;
|
|
16
16
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
* **Retained flag**
|
|
18
|
+
*
|
|
19
|
+
* Topics with this property set to `true` will not be deleted by the server when
|
|
20
|
+
* the last publisher stops publishing.
|
|
21
|
+
*/
|
|
22
22
|
retained?: boolean;
|
|
23
23
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
* **Cached flag**
|
|
25
|
+
*
|
|
26
|
+
* If `false`, the server and clients will not store the value of the topic.
|
|
27
|
+
* This means that only value updates will be available for the topic.
|
|
28
|
+
*/
|
|
29
29
|
cached?: boolean;
|
|
30
30
|
};
|
|
31
31
|
/**
|
|
@@ -33,34 +33,34 @@ type TopicProperties = Record<string, unknown> & {
|
|
|
33
33
|
*/
|
|
34
34
|
type SubscriptionOptions = Record<string, unknown> & {
|
|
35
35
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
* **Periodic sweep time (in seconds)**
|
|
37
|
+
*
|
|
38
|
+
* How frequently the server should send changes. The server may send more frequently than this
|
|
39
|
+
* (e.g. use a combined minimum period for all values) or apply a restricted range to this value
|
|
40
|
+
* The default if unspecified is 100 ms (same as NT 3.0).
|
|
41
|
+
*/
|
|
42
42
|
periodic?: number;
|
|
43
43
|
/**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
* **All changes flag**
|
|
45
|
+
*
|
|
46
|
+
* If `true`, the server should send all value changes over the wire. If `false`, only
|
|
47
|
+
* the most recent value is sent (same as NT 3.0 behavior). If not specified, defaults to `false`.
|
|
48
|
+
*/
|
|
49
49
|
all?: boolean;
|
|
50
50
|
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
* **No value changes flag**
|
|
52
|
+
*
|
|
53
|
+
* If `true`, the server should not send any value changes over the wire regardless of other options.
|
|
54
|
+
* This is useful for only getting topic announcements. If `false`, value changes are sent in accordance
|
|
55
|
+
* with other options. If not specified, defaults to `false`.
|
|
56
|
+
*/
|
|
57
57
|
topicsonly?: boolean;
|
|
58
58
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
* **Prefix flag**
|
|
60
|
+
*
|
|
61
|
+
* If `true`, any topic starting with the name in the subscription topics list is subscribed to,
|
|
62
|
+
* not just exact matches. If not specified, defaults to `false`.
|
|
63
|
+
*/
|
|
64
64
|
prefix?: boolean;
|
|
65
65
|
};
|
|
66
66
|
//#endregion
|
|
@@ -102,12 +102,13 @@ declare class NT4Topic {
|
|
|
102
102
|
removeRetainedValue(): void;
|
|
103
103
|
/** Resets retained value timestamp except for "weak" default value. */
|
|
104
104
|
resetRetainedTimestamp(): void;
|
|
105
|
+
/** Determines whether topic can accept the specified value. */
|
|
106
|
+
canAccept(value: unknown): boolean;
|
|
105
107
|
/** Topic type code. For internal use only. */
|
|
106
108
|
readonly typeCode: number;
|
|
107
109
|
}
|
|
108
110
|
//#endregion
|
|
109
111
|
//#region src/NT4Spec.d.ts
|
|
110
|
-
|
|
111
112
|
/**
|
|
112
113
|
* Supported data types mapped to protocol identifiers.
|
|
113
114
|
*
|
|
@@ -135,57 +136,56 @@ type DataType = keyof typeof DataTypeCodes;
|
|
|
135
136
|
//#region src/NT4Client.d.ts
|
|
136
137
|
type NT4ClientConnectionState = "disconnected" | "connecting" | "connected";
|
|
137
138
|
type NT4ClientOptions = {
|
|
138
|
-
/** Indicates that secure channel should be used. */
|
|
139
|
-
secure?: boolean;
|
|
139
|
+
/** Indicates that secure channel should be used. */secure?: boolean;
|
|
140
140
|
/**
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
* Invoked when the client connects.
|
|
142
|
+
*/
|
|
143
143
|
onConnect?: () => void;
|
|
144
144
|
/**
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
* Invoked when the client disconnects.
|
|
146
|
+
*/
|
|
147
147
|
onDisconnect?: () => void;
|
|
148
148
|
/**
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
149
|
+
* Invoked when new topic is announced by the server.
|
|
150
|
+
*
|
|
151
|
+
* @param topic topic announced
|
|
152
|
+
*/
|
|
153
153
|
onTopicAnnounced?: (topic: NT4Topic) => void;
|
|
154
154
|
/**
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
* Invoked when a topic is removed by the server.
|
|
156
|
+
*
|
|
157
|
+
* @param topic topic removed
|
|
158
|
+
*/
|
|
159
159
|
onTopicRemoved?: (topic: NT4Topic) => void;
|
|
160
160
|
/**
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
161
|
+
* Invoked when a topic properties are updated by the server.
|
|
162
|
+
*
|
|
163
|
+
* @param topic topic updated
|
|
164
|
+
*/
|
|
165
165
|
onTopicUpdated?: (topic: NT4Topic) => void;
|
|
166
166
|
/**
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
167
|
+
* Invoked when the topic receives new data.
|
|
168
|
+
*
|
|
169
|
+
* @param topic topic receiving data
|
|
170
|
+
* @param value value received
|
|
171
|
+
* @param timestamp server timestamp in microseconds
|
|
172
|
+
*/
|
|
173
173
|
onDataReceived?: (topic: NT4Topic, value: unknown, timestamp: number) => void;
|
|
174
174
|
/**
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
175
|
+
* Retry policy that accepts the current number of connection attempts
|
|
176
|
+
* and returns the timeout in milliseconds or -1 to abort.
|
|
177
|
+
*
|
|
178
|
+
* @param attempts number of subsequent connection attempts
|
|
179
|
+
* @returns timeout in milliseconds or -1 to abort
|
|
180
|
+
*/
|
|
181
181
|
retryPolicy?: (attempts: number) => number;
|
|
182
182
|
/**
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
183
|
+
* Overrides default timeout for ping-pong packets.
|
|
184
|
+
*
|
|
185
|
+
* Defaults:
|
|
186
|
+
* - NT 4.0: 3000 milliseconds
|
|
187
|
+
* - NT 4.1: 1000 milliseconds
|
|
188
|
+
*/
|
|
189
189
|
pingTimeoutMilliseconds?: number;
|
|
190
190
|
};
|
|
191
191
|
/**
|
|
@@ -251,14 +251,14 @@ declare class NT4Client {
|
|
|
251
251
|
/** Sends data frame to update topic value. */
|
|
252
252
|
private sendValueCore;
|
|
253
253
|
/**
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
254
|
+
* Sends RTT measurement binary frame.
|
|
255
|
+
* Uses RTT channel if available, falls back to data channel in NT4.0.
|
|
256
|
+
*/
|
|
257
257
|
private sendRTT;
|
|
258
258
|
/**
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
259
|
+
* Determines whether connection times out if no message has been received
|
|
260
|
+
* within the timeout interval since the last pong.
|
|
261
|
+
*/
|
|
262
262
|
private checkTimeout;
|
|
263
263
|
/** Generates random UID. */
|
|
264
264
|
private generateUID;
|
|
@@ -269,158 +269,158 @@ declare class NT4Client {
|
|
|
269
269
|
/** Determines whether subscription with the specified identifier exists. */
|
|
270
270
|
private readonly hasSubscriptionWithId;
|
|
271
271
|
/**
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
272
|
+
* Constructs an instance of NT4Client without initiating a connection.
|
|
273
|
+
*
|
|
274
|
+
* @param serverAddress NT4 server network address
|
|
275
|
+
* @param clientId this client identifier (cannot contain '@')
|
|
276
|
+
* @param options options
|
|
277
|
+
*/
|
|
278
278
|
constructor(serverAddress: string, clientId: string, options: NT4ClientOptions);
|
|
279
279
|
/**
|
|
280
|
-
|
|
281
|
-
|
|
280
|
+
* Returns NT4 server network address the client is using.
|
|
281
|
+
*/
|
|
282
282
|
readonly serverAddress: string;
|
|
283
283
|
/**
|
|
284
|
-
|
|
285
|
-
|
|
284
|
+
* Returns current connection state.
|
|
285
|
+
*/
|
|
286
286
|
get state(): NT4ClientConnectionState;
|
|
287
287
|
/**
|
|
288
|
-
|
|
289
|
-
|
|
288
|
+
* Returns current network latency in microseconds if known.
|
|
289
|
+
*/
|
|
290
290
|
get networkLatencyMicroseconds(): number | null;
|
|
291
291
|
/**
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
292
|
+
* Returns server time in microseconds that is current or
|
|
293
|
+
* based on the specified client (local) time.
|
|
294
|
+
*
|
|
295
|
+
* Returns `null` if the server time offset is not established.
|
|
296
|
+
*/
|
|
297
297
|
serverTimeMicroseconds(clientTimeMicroseconds?: number): number | null;
|
|
298
298
|
/**
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
299
|
+
* Initiates the connection.
|
|
300
|
+
* Once established the connection will be automatically kept alive by reconnecting.
|
|
301
|
+
*/
|
|
302
302
|
connect(): void;
|
|
303
303
|
/**
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
304
|
+
* Terminates the connection.
|
|
305
|
+
* The client can be reconnected manually by calling {@link connect} again.
|
|
306
|
+
*/
|
|
307
307
|
disconnect(): void;
|
|
308
308
|
/**
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
309
|
+
* Creates a new subscription.
|
|
310
|
+
*
|
|
311
|
+
* The subscription can be created regardless of connectivity state.
|
|
312
|
+
* All client subscriptions are automatically restored once connection
|
|
313
|
+
* has been established. This is also true for reconnects following
|
|
314
|
+
* loss of connectivity or deliberate disconnects.
|
|
315
|
+
*
|
|
316
|
+
* Caller can {@link unsubscribe} by passing the return value of this call or
|
|
317
|
+
* invoke {@link unsubscribeAll} to remove all existing client subscriptions.
|
|
318
|
+
*
|
|
319
|
+
* @param topics topics or prefixes to include in the subscription
|
|
320
|
+
* @param options subscription options
|
|
321
|
+
* @returns A subscription instance
|
|
322
|
+
*/
|
|
323
323
|
subscribe(topics: Iterable<string>, options: SubscriptionOptions): NT4Subscription;
|
|
324
324
|
/**
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
325
|
+
* Unsubscribes an existing subscription.
|
|
326
|
+
*
|
|
327
|
+
* @param arg subscription or subscription identifier
|
|
328
|
+
* @returns `true` if the subscription was successfully unsubscribed, `false` if the subscription was not found
|
|
329
|
+
*/
|
|
330
330
|
unsubscribe(arg: NT4Subscription | number): boolean;
|
|
331
331
|
/**
|
|
332
|
-
|
|
333
|
-
|
|
332
|
+
* Unsubscribes all existing subscriptions.
|
|
333
|
+
*/
|
|
334
334
|
unsubscribeAll(): void;
|
|
335
335
|
/**
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
336
|
+
* Publishes a topic with the specified name and type.
|
|
337
|
+
*
|
|
338
|
+
* This method registers this client as a publisher for the topic.
|
|
339
|
+
* It should be called before {@link setValue} or {@link setValueAt}
|
|
340
|
+
* can be used.
|
|
341
|
+
*
|
|
342
|
+
* Publishing a topic on a disconnected client is allowed.
|
|
343
|
+
* Client will automatically register such publishers once the connection
|
|
344
|
+
* has been established and send default or retained value as appropriate.
|
|
345
|
+
*
|
|
346
|
+
* @param topic topic name
|
|
347
|
+
* @param type data type
|
|
348
|
+
* @param properties properties
|
|
349
|
+
*/
|
|
350
350
|
publishTopic(topic: string, type: DataType | string, properties?: TopicProperties): NT4Topic;
|
|
351
351
|
/**
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
352
|
+
* Un-publishes previously published topic.
|
|
353
|
+
*
|
|
354
|
+
* @param topic topic name
|
|
355
|
+
* @returns `true` if the topic was successfully unpublished, `false` if the topic was not published
|
|
356
|
+
*/
|
|
357
357
|
unpublishTopic(topic: string): boolean;
|
|
358
358
|
/**
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
359
|
+
* Determines whether client already publishes the topic.
|
|
360
|
+
*
|
|
361
|
+
* @param topic topic name
|
|
362
|
+
*/
|
|
363
363
|
isTopicPublished(topic: string): boolean;
|
|
364
364
|
/**
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
365
|
+
* Sets properties for the specified topic.
|
|
366
|
+
*
|
|
367
|
+
* @param topic topic name
|
|
368
|
+
* @param properties new properties
|
|
369
|
+
*/
|
|
370
370
|
setTopicProperties(topic: string, properties: TopicProperties): void;
|
|
371
371
|
/**
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
372
|
+
* Sets persistent flag for the topic.
|
|
373
|
+
*
|
|
374
|
+
* @param topic topic name
|
|
375
|
+
* @param value value to set
|
|
376
|
+
*/
|
|
377
377
|
setTopicPersistent(topic: string, value: boolean): void;
|
|
378
378
|
/**
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
379
|
+
* Sets retained flag for the topic.
|
|
380
|
+
*
|
|
381
|
+
* @param topic topic name
|
|
382
|
+
* @param value value to set
|
|
383
|
+
*/
|
|
384
384
|
setTopicRetained(topic: string, value: boolean): void;
|
|
385
385
|
/**
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
386
|
+
* Sends a value to the published topic using the current time.
|
|
387
|
+
*
|
|
388
|
+
* This client must publish the topic with {@link publishTopic} first.
|
|
389
|
+
*
|
|
390
|
+
* @param topic topic name
|
|
391
|
+
* @param value value to send
|
|
392
|
+
*/
|
|
393
393
|
setValue(topic: string, value: unknown): void;
|
|
394
394
|
/**
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
395
|
+
* Sends a default ("weak") value to the published topic.
|
|
396
|
+
*
|
|
397
|
+
* This client must publish the topic with {@link publishTopic} first.
|
|
398
|
+
*
|
|
399
|
+
* @param topic topic name
|
|
400
|
+
* @param value value to send
|
|
401
|
+
*/
|
|
402
402
|
setDefaultValue(topic: string, value: unknown): void;
|
|
403
403
|
/**
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
404
|
+
* Sends a value to the published topic using the specified timestamp.
|
|
405
|
+
*
|
|
406
|
+
* This client must publish the topic with {@link publishTopic} first.
|
|
407
|
+
*
|
|
408
|
+
* @param topic topic name
|
|
409
|
+
* @param value value to send
|
|
410
|
+
* @param timestamp timestamp
|
|
411
|
+
*/
|
|
412
412
|
setValueAt(topic: string, value: unknown, timestamp: number): void;
|
|
413
413
|
/**
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
414
|
+
* Returns current ping timeout.
|
|
415
|
+
*
|
|
416
|
+
* @returns A value in milliseconds or 0 if the timeout has not been set yet.
|
|
417
|
+
*/
|
|
418
418
|
get pingTimeoutMilliseconds(): number;
|
|
419
419
|
/**
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
420
|
+
* Sets ping timeout.
|
|
421
|
+
*
|
|
422
|
+
* @param value Timeout in milliseconds or `undefined` to use default protocol timeout value.
|
|
423
|
+
*/
|
|
424
424
|
setPingTimeoutMilliseconds(value: number | undefined): void;
|
|
425
425
|
}
|
|
426
426
|
//#endregion
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/NT4Types.ts","../src/NT4Subscription.ts","../src/NT4Topic.ts","../src/NT4Spec.ts","../src/NT4Client.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/NT4Types.ts","../src/NT4Subscription.ts","../src/NT4Topic.ts","../src/NT4Spec.ts","../src/NT4Client.ts"],"mappings":";;AAKA;AA8BA;;;KA9BY,eAAA,GAAkB,MAAA;EAAA;AA8B9B;;;;AChCA;;EDE8B,UAAA;EAAA;AA8B9B;;;;AChCA;EDE8B,QAAA;EAAA;AA8B9B;;;;AChCA;EDE8B,MAAA;AAAA;AA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AAA,QAAA,OAAA;EAAA;;;;EAAA,QAAA,YAAA;EAAA;EAAA,QAAA,WAAA;EAAA;EAAA,QAAA,eAAA;EAAA;EAAA,iBAAA,uBAAA;EAAA;EAAA,iBAAA,qBAAA;EAAA;;;;;;;EAAA,YAAA,aAAA,UAAA,QAAA,UAAA,OAAA,EA+emD,gBAAA;EAAA;;;EAAA,SAAA,aAAA;EAAA;;;EAAA,IAAA,MAAA,GA+C9C,wBAAA;EAAA;;;EAAA,IAAA,2BAAA;EAAA;;;;;;EAAA,uBAAA,sBAAA;EAAA;;;;EAAA,QAAA;EAAA;;;;EAAA,WAAA;EAAA;;;;;;;;;;;;;;;EAAA,UAAA,MAAA,EAsES,QAAA,UAAA,OAAA,EAA2B,mBAAA,GAAmB,eAAA;EAAA;;;;;;EAAA,YAAA,GAAA,EAkB/C,eAAA;EAAA;;;EAAA,eAAA;EAAA;;;;;;;;;;;;;;;EAAA,aAAA,KAAA,UAAA,IAAA,EAsCiB,QAAA,WAAA,UAAA,GAAgC,eAAA,GAAe,QAAA;EAAA;;;;;;EAAA,eAAA,KAAA;EAAA;;;;;EAAA,iBAAA,KAAA;EAAA;;;;;;EAAA,mBAAA,KAAA,UAAA,UAAA,EAoDnC,eAAA;EAAA;;;;;;EAAA,mBAAA,KAAA,UAAA,KAAA;EAAA;;;;;;EAAA,iBAAA,KAAA,UAAA,KAAA;EAAA;;;;;;;;EAAA,SAAA,KAAA,UAAA,KAAA;EAAA;;;;;;;;EAAA,gBAAA,KAAA,UAAA,KAAA;EAAA;;;;;;;;;EAAA,WAAA,KAAA,UAAA,KAAA,WAAA,SAAA;EAAA;;;;;EAAA,IAAA,wBAAA;EAAA;;;;;EAAA,2BAAA,KAAA;AAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -107,6 +107,23 @@ var NT4Topic = class {
|
|
|
107
107
|
resetRetainedTimestamp() {
|
|
108
108
|
if (this.retainedTimestamp != null && this.retainedTimestamp > 1) this.retainedTimestamp = 1;
|
|
109
109
|
}
|
|
110
|
+
/** Determines whether topic can accept the specified value. */
|
|
111
|
+
canAccept(value) {
|
|
112
|
+
switch (this.typeCode) {
|
|
113
|
+
case DataTypeCodes.boolean: return typeof value === "boolean";
|
|
114
|
+
case DataTypeCodes.double:
|
|
115
|
+
case DataTypeCodes.float: return typeof value === "number";
|
|
116
|
+
case DataTypeCodes.int: return typeof value === "number" && Number.isInteger(value);
|
|
117
|
+
case DataTypeCodes.string: return typeof value === "string";
|
|
118
|
+
case DataTypeCodes["boolean[]"]: return Array.isArray(value) && value.every((v) => typeof v === "boolean");
|
|
119
|
+
case DataTypeCodes["double[]"]:
|
|
120
|
+
case DataTypeCodes["float[]"]: return Array.isArray(value) && value.every((v) => typeof v === "number");
|
|
121
|
+
case DataTypeCodes["int[]"]: return Array.isArray(value) && value.every((v) => typeof v === "number" && Number.isInteger(v));
|
|
122
|
+
case DataTypeCodes["string[]"]: return Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
123
|
+
case DataTypeCodes.json: return value !== null && (typeof value === "object" || typeof value === "string");
|
|
124
|
+
default: return true;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
110
127
|
/** Topic type code. For internal use only. */
|
|
111
128
|
typeCode;
|
|
112
129
|
};
|
|
@@ -783,6 +800,7 @@ var NT4Client = class NT4Client {
|
|
|
783
800
|
setValueAt(topic, value, timestamp) {
|
|
784
801
|
const publishedTopic = this.publishedTopics.get(topic);
|
|
785
802
|
if (!publishedTopic) throw new Error("Topic must be published first");
|
|
803
|
+
if (!publishedTopic.canAccept(value)) throw new Error("Value is not compatible with topic underlying type");
|
|
786
804
|
publishedTopic.updateRetainedValue(value, timestamp);
|
|
787
805
|
if (this.onDataReceived) {
|
|
788
806
|
const announcedTopic = this.announcedTopics.get(topic);
|