@signalk/streams 6.0.0 → 6.2.0

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/mdns-ws.d.ts CHANGED
@@ -16,6 +16,7 @@ interface MdnsWsOptions {
16
16
  type?: string;
17
17
  subscription?: string;
18
18
  selfHandling?: string;
19
+ token?: string;
19
20
  remoteSelf?: string;
20
21
  ignoreServers?: string[];
21
22
  selfsignedcert?: boolean;
@@ -29,8 +30,12 @@ export default class MdnsWs extends Transform {
29
30
  private readonly dataDebug;
30
31
  private handleContext;
31
32
  private signalkClient?;
33
+ private fetchedMetaPaths;
32
34
  constructor(options: MdnsWsOptions);
35
+ private verifyRemoteToken;
36
+ private setProviderStatus;
33
37
  private connectClient;
38
+ private fetchMetaIfNeeded;
34
39
  _transform(chunk: unknown, encoding: BufferEncoding, done: TransformCallback): void;
35
40
  }
36
41
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"mdns-ws.d.ts","sourceRoot":"","sources":["../src/mdns-ws.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAA;AAErD,OAAO,EAAE,WAAW,EAAe,MAAM,SAAS,CAAA;AAElD,UAAU,aAAa;IACrB,GAAG,EAAE;QACH,MAAM,EAAE;YACN,mBAAmB,IAAI,MAAM,CAAA;YAC7B,eAAe,IAAI,MAAM,CAAA;SAC1B,CAAA;QACD,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;QAChD,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;KAChD,CAAA;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE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AChD,CAAA;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;IACxB,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAOD,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,SAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IACvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IACjC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA6B;IAC3D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IACnC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAa;IACvC,OAAO,CAAC,aAAa,CAA+B;IACpD,OAAO,CAAC,aAAa,CAAC,CAAQ;IAC9B,OAAO,CAAC,gBAAgB,CAAoB;gBAEhC,OAAO,EAAE,aAAa;IAuDlC,OAAO,CAAC,iBAAiB;IAyBzB,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,aAAa;IAmIrB,OAAO,CAAC,iBAAiB;IA0BzB,UAAU,CACR,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,iBAAiB,GACtB,IAAI;CAGR"}
package/dist/mdns-ws.js CHANGED
@@ -14,9 +14,15 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
17
20
  Object.defineProperty(exports, "__esModule", { value: true });
18
21
  const stream_1 = require("stream");
22
+ const http_1 = __importDefault(require("http"));
23
+ const https_1 = __importDefault(require("https"));
19
24
  const client_1 = require("@signalk/client");
25
+ const signalk_schema_1 = require("@signalk/signalk-schema");
20
26
  class MdnsWs extends stream_1.Transform {
21
27
  options;
22
28
  selfHost;
@@ -26,6 +32,7 @@ class MdnsWs extends stream_1.Transform {
26
32
  dataDebug;
27
33
  handleContext;
28
34
  signalkClient;
35
+ fetchedMetaPaths = new Set();
29
36
  constructor(options) {
30
37
  super({ objectMode: true });
31
38
  this.options = options;
@@ -74,13 +81,64 @@ class MdnsWs extends stream_1.Transform {
74
81
  this.options.app.setProviderError(this.options.providerId, 'This connection is deprecated and must be deleted');
75
82
  }
76
83
  }
84
+ verifyRemoteToken() {
85
+ const protocol = this.options.type === 'wss' ? https_1.default : http_1.default;
86
+ return new Promise((resolve, reject) => {
87
+ const reqOptions = {
88
+ hostname: this.options.host,
89
+ port: this.options.port,
90
+ path: '/signalk/v1/api/self',
91
+ method: 'GET',
92
+ headers: {
93
+ Authorization: `JWT ${this.options.token}`
94
+ },
95
+ rejectUnauthorized: !(this.options.selfsignedcert === true)
96
+ };
97
+ const req = protocol.request(reqOptions, (response) => {
98
+ response.resume();
99
+ resolve(response.statusCode === 200);
100
+ });
101
+ req.on('error', (err) => reject(err));
102
+ req.setTimeout(10000, () => {
103
+ req.destroy(new Error('Token verification timed out'));
104
+ });
105
+ req.end();
106
+ });
107
+ }
108
+ setProviderStatus(message, isError) {
109
+ if (!isError) {
110
+ this.options.app.setProviderStatus(this.options.providerId, message);
111
+ }
112
+ else {
113
+ this.options.app.setProviderError(this.options.providerId, message);
114
+ }
115
+ }
77
116
  connectClient(client) {
117
+ this.fetchedMetaPaths.clear();
78
118
  client
79
119
  .connect()
80
120
  .then(() => {
81
121
  this.options.app.setProviderStatus(this.options.providerId, `ws connection connected to ${client.options.hostname}:${client.options.port}`);
82
122
  console.log(`ws connection connected to ${client.options.hostname}:${client.options.port}`);
83
- if (this.options.selfHandling === 'useRemoteSelf') {
123
+ if (this.options.token) {
124
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
125
+ const conn = client.connection;
126
+ conn.send(JSON.stringify({ token: this.options.token }));
127
+ conn.setAuthenticated(this.options.token, 'JWT');
128
+ this.debug('Sent authentication token to remote server');
129
+ this.verifyRemoteToken()
130
+ .then((isValid) => {
131
+ if (!isValid) {
132
+ this.setProviderStatus(`Authentication failed for ${client.options.hostname}:${client.options.port} — token may be invalid or revoked`, true);
133
+ conn.disconnect();
134
+ }
135
+ })
136
+ .catch((err) => {
137
+ this.debug('Token verification error: ' + err.message);
138
+ });
139
+ }
140
+ if (this.options.selfHandling !== 'manualSelf' &&
141
+ this.options.selfHandling !== 'noSelf') {
84
142
  client
85
143
  .API()
86
144
  .then((api) => api.get('/self'))
@@ -135,6 +193,48 @@ class MdnsWs extends stream_1.Transform {
135
193
  });
136
194
  }
137
195
  this.push(data);
196
+ if (data?.updates) {
197
+ for (const update of data.updates) {
198
+ const values = update.values;
199
+ if (values) {
200
+ for (const pv of values) {
201
+ if (!this.fetchedMetaPaths.has(pv.path)) {
202
+ this.fetchedMetaPaths.add(pv.path);
203
+ this.fetchMetaIfNeeded(client, data.context, pv.path);
204
+ }
205
+ }
206
+ }
207
+ }
208
+ }
209
+ });
210
+ client.on('disconnect', () => {
211
+ const hint = this.options.token
212
+ ? ' — check that the token is valid on the remote server'
213
+ : ' — the remote server may require authentication';
214
+ this.setProviderStatus(`Disconnected from ${client.options.hostname}:${client.options.port}${hint}`, true);
215
+ });
216
+ client.on('error', (err) => {
217
+ this.setProviderStatus(`Connection error: ${err.message}`, true);
218
+ });
219
+ }
220
+ fetchMetaIfNeeded(client, context, path) {
221
+ if ((0, signalk_schema_1.getMetadata)('vessels.self.' + path)) {
222
+ return;
223
+ }
224
+ client
225
+ .API()
226
+ .then((api) => api.getMeta(`/vessels/self/${path.replace(/\./g, '/')}`))
227
+ .then((meta) => {
228
+ if (meta) {
229
+ this.debug(`fetched meta for ${path} from remote`);
230
+ this.push({
231
+ context,
232
+ updates: [{ meta: [{ path, value: meta }] }]
233
+ });
234
+ }
235
+ })
236
+ .catch((err) => {
237
+ this.debug(`failed to fetch meta for ${path}: ${err.message}`);
138
238
  });
139
239
  }
140
240
  _transform(chunk, encoding, done) {
@@ -1 +1 @@
1
- {"version":3,"file":"serialport.d.ts","sourceRoot":"","sources":["../src/serialport.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAA;AAErD,OAAO,KAAK,EAAE,WAAW,EAAe,MAAM,SAAS,CAAA;AAEvD,UAAU,mBAAmB;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE;QAEH,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI,CAAA;QACrD,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;QAC7C,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAA;QACrD,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;QAChD,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;KAChD,CAAA;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,WAAW,CAAC,EAAE,WAAW,CAAA;CAC1B;AAED,MAAM,CAAC,OAAO,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AM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;KAChD,CAAA;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,WAAW,CAAC,EAAE,WAAW,CAAA;CAC1B;AAED,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,SAAS;IACjD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IACnC,OAAO,CAAC,MAAM,CAA+C;IAC7D,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,cAAc,CAAO;IAC7B,OAAO,CAAC,YAAY,CAAO;IAC3B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAQ;IACzC,OAAO,CAAC,gBAAgB,CAA6C;gBAEzD,OAAO,EAAE,mBAAmB;IAyDxC,KAAK,IAAI,IAAI;IAwDb,GAAG,IAAI,IAAI;IAWX,UAAU,CACR,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,iBAAiB,GACtB,IAAI;IAKP,OAAO,CAAC,iBAAiB;CAS1B"}
@@ -28,29 +28,33 @@ class SerialStream extends stream_1.Transform {
28
28
  : [this.options.toStdout].filter(Boolean);
29
29
  const standardOutEventName = `serial-${this.options.providerId}-toStdout`;
30
30
  stdOutEvents.push(standardOutEventName);
31
- const onDrain = () => {
32
- pendingWrites--;
33
- };
34
31
  for (const event of stdOutEvents) {
35
32
  this.options.app.on(event, (d) => {
33
+ if (!this.serial) {
34
+ return;
35
+ }
36
36
  if (pendingWrites > this.maxPendingWrites) {
37
37
  this.debug('Buffer overflow, not writing:' + d);
38
38
  return;
39
39
  }
40
40
  this.debug('Writing:' + d);
41
- if (Buffer.isBuffer(d)) {
42
- this.serial?.write(d);
43
- }
44
- else {
45
- this.serial?.write(d + '\r\n');
46
- }
41
+ const data = Buffer.isBuffer(d) ? d : d + '\r\n';
42
+ const flushed = this.serial.write(data, (err) => {
43
+ if (err) {
44
+ this.debug('Write error: ' + err.message);
45
+ }
46
+ });
47
47
  setImmediate(() => {
48
48
  this.options.app.emit('connectionwrite', {
49
49
  providerId: this.options.providerId
50
50
  });
51
51
  });
52
- pendingWrites++;
53
- this.serial?.drain(onDrain);
52
+ if (!flushed) {
53
+ pendingWrites++;
54
+ this.serial.once('drain', () => {
55
+ pendingWrites--;
56
+ });
57
+ }
54
58
  });
55
59
  }
56
60
  this.options.app.emitPropertyValue('serialport', {
package/dist/tcp.d.ts CHANGED
@@ -20,6 +20,7 @@ export default class TcpStream extends Transform {
20
20
  private readonly options;
21
21
  private readonly debug;
22
22
  private readonly debugData;
23
+ private static readonly DEFAULT_TIMEOUT_SECONDS;
23
24
  private readonly noDataReceivedTimeout;
24
25
  private tcpStream;
25
26
  private reconnector;
package/dist/tcp.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"tcp.d.ts","sourceRoot":"","sources":["../src/tcp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAA;AAErD,OAAO,KAAK,EAAE,WAAW,EAAe,MAAM,SAAS,CAAA;AAEvD,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE;QAEH,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI,CAAA;QACrD,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;QAC7C,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;QAChD,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ends stream_1.Transform {
10
10
  options;
11
11
  debug;
12
12
  debugData;
13
+ static DEFAULT_TIMEOUT_SECONDS = 60;
13
14
  noDataReceivedTimeout;
14
15
  tcpStream;
15
16
  reconnector = null;
16
17
  constructor(options) {
17
18
  super();
18
19
  this.options = options;
20
+ const parsedTimeout = Number.parseInt((this.options.noDataReceivedTimeout + '').trim());
19
21
  this.noDataReceivedTimeout =
20
- Number.parseInt((this.options.noDataReceivedTimeout + '').trim()) * 1000;
22
+ (isNaN(parsedTimeout)
23
+ ? TcpStream.DEFAULT_TIMEOUT_SECONDS
24
+ : parsedTimeout) * 1000;
21
25
  const createDebug = options.createDebug ?? require('debug');
22
26
  this.debug = createDebug('signalk:streams:tcp');
23
27
  this.debug(`noDataReceivedTimeout:${this.noDataReceivedTimeout}`);
@@ -52,7 +56,7 @@ class TcpStream extends stream_1.Transform {
52
56
  this.reconnector = (0, reconnect_core_1.default)((opts) => {
53
57
  return net_1.default.connect(opts);
54
58
  })({ maxDelay: 5 * 1000 }, (tcpStream) => {
55
- if (!isNaN(this.noDataReceivedTimeout)) {
59
+ if (this.noDataReceivedTimeout > 0) {
56
60
  tcpStream.setTimeout(this.noDataReceivedTimeout);
57
61
  this.debug(`Setting socket idle timeout ${this.options.host}:${this.options.port} ${this.noDataReceivedTimeout}`);
58
62
  tcpStream.on('timeout', () => {
package/dist/udp.d.ts CHANGED
@@ -5,6 +5,7 @@ interface UdpOptions {
5
5
  host?: string;
6
6
  app: {
7
7
  on(event: string, cb: (...args: any[]) => void): void;
8
+ setProviderStatus(id: string, msg: string): void;
8
9
  setProviderError(id: string, msg: string): void;
9
10
  };
10
11
  providerId: string;
package/dist/udp.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"udp.d.ts","sourceRoot":"","sources":["../src/udp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAY,MAAM,QAAQ,CAAA;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAe,MAA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,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI,CAAA;QACrD,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;QAChD,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;KAChD,CAAA;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,MAAM,CAAC,OAAO,OAAO,GAAI,SAAQ,SAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAY;IACpC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IACnC,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,MAAM,CAAwB;gBAE1B,OAAO,EAAE,UAAU;IAO/B,IAAI,CAAC,CAAC,SAAS,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC;IA0CnD,UAAU,CACR,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,iBAAiB,GACtB,IAAI;IAIP,GAAG,IAAI,IAAI;CASZ"}
package/dist/udp.js CHANGED
@@ -34,6 +34,8 @@ class Udp extends stream_1.Transform {
34
34
  });
35
35
  socket.bind(this.options.port, () => {
36
36
  socket.setBroadcast(true);
37
+ const addr = socket.address();
38
+ this.options.app.setProviderStatus(this.options.providerId, `Listening on UDP port ${addr.port}`);
37
39
  });
38
40
  return pipeTo;
39
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalk/streams",
3
- "version": "6.0.0",
3
+ "version": "6.2.0",
4
4
  "description": "Utilities for handling streams of Signal K data",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -51,7 +51,8 @@
51
51
  },
52
52
  "repository": {
53
53
  "type": "git",
54
- "url": "git+https://github.com/SignalK/signalk-server-node.git"
54
+ "url": "git+https://github.com/SignalK/signalk-server.git",
55
+ "directory": "packages/streams"
55
56
  },
56
57
  "keywords": [
57
58
  "Signal",