aes70 1.3.2 → 1.3.6

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.
@@ -25,8 +25,7 @@ async function waitForKeepalive(socket, options) {
25
25
 
26
26
  pos = decodeMessage(new DataView(data.buffer), 0, pdus);
27
27
 
28
- if (pdus.length !== 1)
29
- throw new Error('Expected keepalive response.');
28
+ if (pdus.length !== 1) throw new Error('Expected keepalive response.');
30
29
 
31
30
  socket.off('message', onMessage);
32
31
  socket.off('error', reject);
@@ -43,8 +42,7 @@ async function waitForKeepalive(socket, options) {
43
42
  for (let i = 0; i < 3; i++) {
44
43
  socket.send(msg);
45
44
 
46
- if (await Promise.race([ waiter, delay(t) ]))
47
- return;
45
+ if (await Promise.race([waiter, delay(t)])) return;
48
46
  }
49
47
 
50
48
  throw new Error('Failed to connect.');
@@ -101,8 +99,10 @@ export class UDPConnection extends ClientConnection {
101
99
  this._write_out_id = -1;
102
100
  this._write_out();
103
101
  };
104
- this._retry_id = (this.retry_interval > 0) ?
105
- setInterval(() => this._retryCommands(), this.retry_interval) : -1;
102
+ this._retry_id =
103
+ this.retry_interval > 0
104
+ ? setInterval(() => this._retryCommands(), this.retry_interval)
105
+ : -1;
106
106
  this.q = [];
107
107
  socket.on('message', (data, rinfo) => {
108
108
  try {
@@ -176,16 +176,13 @@ export class UDPConnection extends ClientConnection {
176
176
  write(buf) {
177
177
  this.q.push(buf);
178
178
 
179
- if (this.tx_idle_time() >= this.delay)
180
- this._write_out();
181
- else
182
- this._schedule_write_out();
179
+ if (this.tx_idle_time() >= this.delay) this._write_out();
180
+ else this._schedule_write_out();
183
181
  }
184
182
 
185
183
  flush() {
186
184
  super.flush();
187
- if (this.tx_idle_time() > this.delay)
188
- this._write_out();
185
+ if (this.tx_idle_time() > this.delay) this._write_out();
189
186
  }
190
187
 
191
188
  cleanup() {
@@ -219,8 +216,7 @@ export class UDPConnection extends ClientConnection {
219
216
  this.socket.send(Buffer.from(buf));
220
217
  super.write(buf);
221
218
 
222
- if (q.length)
223
- this._schedule_write_out();
219
+ if (q.length) this._schedule_write_out();
224
220
  }
225
221
 
226
222
  _schedule_write_out() {
@@ -233,10 +229,12 @@ export class UDPConnection extends ClientConnection {
233
229
  }
234
230
 
235
231
  // Already scheduled.
236
- if (this._write_out_id !== -1)
237
- return;
232
+ if (this._write_out_id !== -1) return;
238
233
 
239
- this._write_out_id = setTimeout(this._write_out_callback, delay - tx_idle_time);
234
+ this._write_out_id = setTimeout(
235
+ this._write_out_callback,
236
+ delay - tx_idle_time
237
+ );
240
238
  }
241
239
 
242
240
  _retryCommands() {
@@ -251,7 +249,7 @@ export class UDPConnection extends ClientConnection {
251
249
  const failed = [];
252
250
 
253
251
  for (const entry of pendingCommands) {
254
- const [ handle, pendingCommand ] = entry;
252
+ const [handle, pendingCommand] = entry;
255
253
 
256
254
  // All later commands are newer than the cutoff.
257
255
  if (pendingCommand.lastSent > retryTime) break;
@@ -265,13 +263,13 @@ export class UDPConnection extends ClientConnection {
265
263
  if (failed.length) {
266
264
  const timeoutError = new Error('Timeout.');
267
265
 
268
- failed.forEach(([ handle, pendingCommand ]) => {
266
+ failed.forEach(([handle, pendingCommand]) => {
269
267
  pendingCommands.delete(handle);
270
268
  pendingCommand.reject(timeoutError);
271
269
  });
272
270
  }
273
271
 
274
- retries.forEach(([ handle, pendingCommand ]) => {
272
+ retries.forEach(([handle, pendingCommand]) => {
275
273
  pendingCommands.delete(handle);
276
274
  pendingCommands.set(handle, pendingCommand);
277
275
  this.send(pendingCommand.command);
@@ -52,7 +52,9 @@ export class WebSocketConnection extends ClientConnection {
52
52
  cleanup() {
53
53
  super.cleanup();
54
54
  if (this.ws) {
55
- try { this.ws.close(); } catch (err) {}
55
+ try {
56
+ this.ws.close();
57
+ } catch (err) {}
56
58
  this.ws = null;
57
59
  }
58
60
  }
@@ -1,6 +1,6 @@
1
1
  /* eslint-env node */
2
2
 
3
- import * as WebSocket from 'ws';
3
+ import WebSocket from 'ws';
4
4
  import { performance } from 'perf_hooks';
5
5
 
6
6
  import { ClientConnection } from './client_connection.js';
@@ -54,7 +54,10 @@ export class WebSocketConnection extends ClientConnection {
54
54
  cleanup() {
55
55
  super.cleanup();
56
56
  if (this.ws) {
57
- try { this.ws.close(); } catch (err) {}
57
+ try {
58
+ this.ws.close();
59
+ } catch (err) {}
60
+ this.ws.removeAllListeners();
58
61
  this.ws = null;
59
62
  }
60
63
  }
@@ -48,6 +48,7 @@ export class Test {
48
48
  {
49
49
  if (this.device !== null)
50
50
  {
51
+ this.device.connection.emit('test_done');
51
52
  this.device.close();
52
53
  this.device = null;
53
54
  }
package/tests/device.js CHANGED
@@ -187,12 +187,23 @@ function timeout(n)
187
187
 
188
188
  async function run_tests(type, target)
189
189
  {
190
+ let onClose = null;
191
+
192
+ const close_p = new Promise((resolve, reject) => {
193
+ onClose = () => setTimeout(() => reject(new Error('Closed.')), 1000);
194
+ });
195
+
190
196
  const get_device = async () => {
191
197
  const connection = await type.connect(connect_options(target));
192
198
  const device = new RemoteDevice(connection);
193
199
 
194
200
  device.set_keepalive_interval(1);
195
201
 
202
+ connection.on('close', onClose);
203
+ connection.on('test_done', () => {
204
+ connection.removeEventListener('close', onClose);
205
+ });
206
+
196
207
  return device;
197
208
  };
198
209
 
@@ -203,7 +214,7 @@ async function run_tests(type, target)
203
214
  const timeout_p = timeout(60*1000);
204
215
  const test_p = test_runner.run();
205
216
 
206
- await Promise.race([ timeout_p.then(() => { timed_out = true; }), test_p ]);
217
+ await Promise.race([ timeout_p.then(() => { timed_out = true; }), test_p, close_p ]);
207
218
 
208
219
  if (timed_out)
209
220
  {
Binary file
@@ -1,16 +0,0 @@
1
- /*
2
- * This file has been generated.
3
- */
4
- import { Struct } from './Struct.js';
5
- import { FieldType } from './FieldType.js';
6
- import { OcaUint16 } from './OcaUint16.js';
7
-
8
- import { OcaClassID as type } from '../types/OcaClassID.js';
9
-
10
- export const OcaClassID = Struct(
11
- {
12
- FieldCount: OcaUint16,
13
- Fields: FieldType,
14
- },
15
- type
16
- );