signalk-ais-navionics-converter 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.
@@ -0,0 +1,21 @@
1
+ name: Manual npm Publish
2
+
3
+ on:
4
+ workflow_dispatch: # nur manuell auslösbar
5
+
6
+ jobs:
7
+ publish:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/checkout@v4
11
+
12
+ - uses: actions/setup-node@v4
13
+ with:
14
+ node-version: 20
15
+ registry-url: 'https://registry.npmjs.org'
16
+
17
+ - run: npm ci
18
+
19
+ - run: npm publish
20
+ env:
21
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/index.js CHANGED
@@ -21,6 +21,8 @@ module.exports = function(app) {
21
21
  let ownMMSI = null;
22
22
  let vesselFinderLastUpdate = 0;
23
23
  let signalkApiUrl = null;
24
+ let cloudVesselsCache = null;
25
+ let cloudVesselsLastFetch = 0;
24
26
 
25
27
  plugin.schema = {
26
28
  type: 'object',
@@ -143,6 +145,12 @@ module.exports = function(app) {
143
145
  description: 'Beside vessels available in SignalK vessels from aisfleet.com will taken into account',
144
146
  default: true
145
147
  },
148
+ cloudVesselsUpdateInterval: {
149
+ type: 'number',
150
+ title: 'Cloud vessels update interval (seconds)',
151
+ description: 'How often to fetch vessels from AISFleet.com (default: 60, recommended: 60-300)',
152
+ default: 60
153
+ },
146
154
  cloudVesselsRadius: {
147
155
  type: 'number',
148
156
  title: 'Radius (from own vessel) to include vessels from AISFleet.com (nautical miles)',
@@ -199,6 +207,8 @@ module.exports = function(app) {
199
207
 
200
208
  previousVesselsState.clear();
201
209
  lastTCPBroadcast.clear();
210
+ cloudVesselsCache = null; // ← NEU
211
+ cloudVesselsLastFetch = 0; // ← NEU
202
212
  };
203
213
 
204
214
  function getOwnMMSI() {
@@ -299,19 +309,26 @@ module.exports = function(app) {
299
309
  app.debug(`Map sizes - previousVesselsState: ${previousVesselsState.size}, lastTCPBroadcast: ${lastTCPBroadcast.size}`);
300
310
  }
301
311
 
302
- function fetchFromURL(url) {
312
+ function fetchVesselsFromAPI() {
303
313
  return new Promise((resolve, reject) => {
314
+ if (!signalkApiUrl) {
315
+ app.error('signalkApiUrl not initialized yet');
316
+ resolve(null);
317
+ return;
318
+ }
319
+
320
+ const url = `${signalkApiUrl}/vessels`;
304
321
  app.debug(`Fetching SignalK vessels from URL: ${url}`);
305
322
 
306
323
  const http = require('http');
307
324
 
308
325
  http.get(url, (res) => {
326
+ app.debug(`HTTP Response Status: ${res.statusCode}`);
309
327
  let data = '';
310
328
 
311
- // Prüfe HTTP Status Code
312
329
  if (res.statusCode !== 200) {
313
330
  app.error(`HTTP ${res.statusCode} from ${url}`);
314
- reject(new Error(`HTTP ${res.statusCode}`));
331
+ resolve(null); // ← Wichtig: resolve(null) statt reject()
315
332
  return;
316
333
  }
317
334
 
@@ -320,26 +337,24 @@ module.exports = function(app) {
320
337
  });
321
338
 
322
339
  res.on('end', () => {
340
+ app.debug(`HTTP Response received, length: ${data.length} bytes`);
323
341
  try {
324
342
  const result = JSON.parse(data);
343
+ app.debug(`Parsed JSON, ${Object.keys(result).length} vessels from SignalK API`);
325
344
  resolve(result);
326
345
  } catch (err) {
327
346
  app.error(`Invalid JSON from ${url}: ${err.message}`);
328
347
  app.error(`Data preview: ${data.substring(0, 200)}`);
329
- reject(err);
348
+ resolve(null); // ← Wichtig: resolve(null) statt reject()
330
349
  }
331
350
  });
332
351
  }).on('error', (err) => {
333
352
  app.error(`HTTP request error for ${url}: ${err.message}`);
334
- reject(err);
353
+ resolve(null); // ← Wichtig: resolve(null) statt reject()
335
354
  });
336
355
  });
337
356
  }
338
357
 
339
- function fetchVesselsFromAPI() {
340
- return fetchFromURL(`${signalkApiUrl}/vessels`);
341
- }
342
-
343
358
  function fetchCloudVessels(options) {
344
359
  if (!options.cloudVesselsEnabled) {
345
360
  return Promise.resolve(null);
@@ -694,18 +709,34 @@ module.exports = function(app) {
694
709
  return merged;
695
710
  }
696
711
 
697
- function getVessels(options) {
712
+ function getVessels(options) {
713
+ const now = Date.now();
714
+ const cloudUpdateInterval = (options.cloudVesselsUpdateInterval || 60) * 1000; // Default 60 Sekunden
715
+
716
+ // Entscheide ob Cloud Vessels neu geholt werden müssen
717
+ const needsCloudUpdate = options.cloudVesselsEnabled &&
718
+ (now - cloudVesselsLastFetch >= cloudUpdateInterval);
719
+
720
+ const cloudPromise = needsCloudUpdate
721
+ ? fetchCloudVessels(options).then(result => {
722
+ if (result) {
723
+ cloudVesselsCache = result;
724
+ cloudVesselsLastFetch = now;
725
+ }
726
+ return cloudVesselsCache;
727
+ })
728
+ : Promise.resolve(cloudVesselsCache);
729
+
698
730
  return Promise.all([
699
731
  fetchVesselsFromAPI(),
700
- fetchCloudVessels(options)
732
+ cloudPromise
701
733
  ]).then(([signalkVessels, cloudVessels]) => {
702
734
  const vessels = [];
703
735
 
704
736
  // Merge beide Datenquellen
705
737
  const allVessels = mergeVesselSources(signalkVessels, cloudVessels, options);
706
738
 
707
- if (!allVessels) return vessels;
708
-
739
+ if (!allVessels) return vessels;
709
740
  for (const [vesselId, vessel] of Object.entries(allVessels)) {
710
741
  if (vesselId === 'self') continue;
711
742
 
@@ -897,7 +928,6 @@ module.exports = function(app) {
897
928
  if (shouldLogDebug) {
898
929
  app.debug(`[${vessel.mmsi}] Type 1: ${sentence1}`);
899
930
  }
900
-
901
931
  if (sendToTCP) {
902
932
  broadcastTCP(sentence1);
903
933
  sentCount++;
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "signalk-ais-navionics-converter",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "SignalK plugin to convert AIS data to NMEA 0183 sentences to TCP clients (e.g. Navionics boating app, OpenCpn) and optional to vesselfinder.com",
5
5
  "main": "index.js",
6
6
  "keywords": [
7
7
  "signalk-node-server-plugin",
8
8
  "signalk-category-utility",
9
- "signalk-category-ais"
9
+ "signalk-category-ais",
10
+ "signalk-category-nmea-0183"
10
11
  ],
11
12
  "author": "Dirk Behrendt",
12
13
  "license": "MIT",