@signalk/freeboard-sk 2.2.1 → 2.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG: Freeboard
2
2
 
3
+ ### v2.2.2
4
+
5
+ - **Fixed**: Update Anchor Watch to use `signalk-anchor-alarm` REST API to resolve incorrect state being displayed.
6
+ - **Fixed**: Switching to fixed location did not update map until a delta update had been parsed.
7
+
3
8
  ### v2.2.1
4
9
 
5
10
  - **Fixed**: Issue where waypoint was not centered on the screen when the center waypoint button was clicked from the entry in the waypoint list.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalk/freeboard-sk",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "Openlayers chart plotter implementation for Signal K",
5
5
  "keywords": [
6
6
  "signalk-webapp",
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initAnchorApi = void 0;
4
+ const fetch_1 = require("../lib/fetch");
5
+ let server;
6
+ let hostPath;
7
+ const apiBasePath = '/signalk/v2/api/vessels/self/navigation/anchor';
8
+ const anchorPlugin = {
9
+ has: false,
10
+ enabled: false,
11
+ version: ''
12
+ };
13
+ let pluginPath;
14
+ const msgPluginNotFound = 'signalk-anchor-alarm is not installed!';
15
+ const initAnchorApi = async (app) => {
16
+ server = app;
17
+ server.debug(`** initAnchorApi() **`);
18
+ // detect signalk-anchor-alarm plugin
19
+ let port = 3000;
20
+ if (typeof server.config?.getExternalPort === 'function') {
21
+ server.debug('*** getExternalPort()', server.config.getExternalPort());
22
+ port = server.config.getExternalPort();
23
+ }
24
+ hostPath = `${server.config.ssl ? 'https' : 'http'}://localhost:${port}`;
25
+ const url = `${hostPath}/plugins`;
26
+ const r = await (0, fetch_1.fetch)(url);
27
+ r.forEach((plugin) => {
28
+ if (plugin.id === 'anchoralarm') {
29
+ pluginPath = `/plugins/${plugin.id}`;
30
+ anchorPlugin.has = true;
31
+ anchorPlugin.version = plugin.version;
32
+ anchorPlugin.enabled = plugin.data.enabled;
33
+ }
34
+ });
35
+ server.debug('*** Anchor Alarm Plugin detected:', anchorPlugin.has);
36
+ server.debug('*** Anchor Alarm Plugin enabled:', anchorPlugin.enabled);
37
+ server.debug('*** Anchor Alarm Plugin API Path', `${hostPath}${pluginPath}`);
38
+ if (anchorPlugin.has) {
39
+ initApiEndpoints();
40
+ }
41
+ };
42
+ exports.initAnchorApi = initAnchorApi;
43
+ const initApiEndpoints = () => {
44
+ server.debug(`** Registering Anchor API endpoint(s) **`);
45
+ server.post(`${apiBasePath}/drop`, async (req, res) => {
46
+ server.debug(`** POST ${apiBasePath}/drop`);
47
+ if (!anchorPlugin.has) {
48
+ res.status(400).json({
49
+ state: 'COMPLETED',
50
+ statusCode: 400,
51
+ message: msgPluginNotFound
52
+ });
53
+ return;
54
+ }
55
+ try {
56
+ const r = await (0, fetch_1.post)(`${hostPath}${pluginPath}/dropAnchor`, '{}');
57
+ res.status(r.statusCode).json(r);
58
+ }
59
+ catch (e) {
60
+ res.status(e.statusCode).json(e);
61
+ }
62
+ });
63
+ server.post(`${apiBasePath}/raise`, async (req, res) => {
64
+ server.debug(`** POST ${apiBasePath}/raise`);
65
+ if (!anchorPlugin.has) {
66
+ res.status(400).json({
67
+ state: 'COMPLETED',
68
+ statusCode: 400,
69
+ message: msgPluginNotFound
70
+ });
71
+ return;
72
+ }
73
+ try {
74
+ const r = await (0, fetch_1.post)(`${hostPath}${pluginPath}/raiseAnchor`, '{}');
75
+ res.status(r.statusCode).json(r);
76
+ }
77
+ catch (e) {
78
+ res.status(e.statusCode).json(e);
79
+ }
80
+ });
81
+ server.post(`${apiBasePath}/radius`, async (req, res) => {
82
+ server.debug(`** POST ${apiBasePath}/radius`);
83
+ if (!anchorPlugin.has) {
84
+ res.status(400).json({
85
+ state: 'COMPLETED',
86
+ statusCode: 400,
87
+ message: msgPluginNotFound
88
+ });
89
+ return;
90
+ }
91
+ try {
92
+ const val = req.body.value && typeof req.body.value === 'number'
93
+ ? { radius: req.body.value }
94
+ : {};
95
+ const r = await (0, fetch_1.post)(`${hostPath}${pluginPath}/setRadius`, JSON.stringify(val));
96
+ res.status(r.statusCode).json(r);
97
+ }
98
+ catch (e) {
99
+ res.status(e.statusCode).json(e);
100
+ }
101
+ });
102
+ };
package/plugin/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const alarms_1 = require("./alarms/alarms");
4
+ const anchor_api_1 = require("./anchor/anchor-api");
4
5
  const weather_1 = require("./weather");
5
6
  const pypilot_1 = require("./pypilot");
6
7
  const openapi = require("./openApi.json");
@@ -162,6 +163,8 @@ module.exports = (server) => {
162
163
  if (settings.pypilot.enable) {
163
164
  (0, pypilot_1.initPyPilot)(server, plugin.id, settings.pypilot);
164
165
  }
166
+ // Anchor API facade
167
+ (0, anchor_api_1.initAnchorApi)(server);
165
168
  server.setPluginStatus(msg);
166
169
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
167
170
  }
@@ -1,13 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetch = void 0;
3
+ exports.post = exports.fetch = void 0;
4
4
  const https = require("https");
5
5
  const url = require("url");
6
+ const http = require("http");
7
+ // HTTP GET
6
8
  const fetch = (href) => {
7
9
  const opt = url.parse(href);
8
10
  opt.headers = { 'User-Agent': 'Mozilla/5.0' };
11
+ const req = href.indexOf('https') !== -1 ? https : http;
9
12
  return new Promise((resolve, reject) => {
10
- https
13
+ req
11
14
  .get(opt, (res) => {
12
15
  let data = '';
13
16
  res.on('data', (chunk) => {
@@ -29,3 +32,46 @@ const fetch = (href) => {
29
32
  });
30
33
  };
31
34
  exports.fetch = fetch;
35
+ // HTTP POST
36
+ const post = (href, data) => {
37
+ const opt = url.parse(href);
38
+ (opt.method = 'POST'),
39
+ (opt.headers = {
40
+ 'Content-Type': 'application/json'
41
+ });
42
+ const req = href.indexOf('https') !== -1 ? https : http;
43
+ return new Promise((resolve, reject) => {
44
+ const postReq = req
45
+ .request(opt, (res) => {
46
+ let resText = '';
47
+ res.on('data', (chunk) => {
48
+ resText += chunk;
49
+ });
50
+ res.on('end', () => {
51
+ if (Math.floor(res.statusCode / 100) === 2) {
52
+ resolve({
53
+ statusCode: res.statusCode,
54
+ state: 'COMPLETED'
55
+ });
56
+ }
57
+ else {
58
+ reject({
59
+ statusCode: res.statusCode,
60
+ state: 'FAILED',
61
+ message: resText
62
+ });
63
+ }
64
+ });
65
+ })
66
+ .on('error', (error) => {
67
+ reject({
68
+ statusCode: 400,
69
+ state: 'FAILED',
70
+ message: error.message
71
+ });
72
+ });
73
+ postReq.write(data);
74
+ postReq.end();
75
+ });
76
+ };
77
+ exports.post = post;
package/public/index.html CHANGED
@@ -74,5 +74,5 @@
74
74
  </div>
75
75
  </div>
76
76
  </app-root>
77
- <script src="runtime.d3c37bb0c0c8df86.js" type="module"></script><script src="polyfills.61cfd308b28d8fe0.js" type="module"></script><script src="main.5461196ce3d0ae77.js" type="module"></script></body>
77
+ <script src="runtime.d3c37bb0c0c8df86.js" type="module"></script><script src="polyfills.61cfd308b28d8fe0.js" type="module"></script><script src="main.b1d3ce26b87acfb4.js" type="module"></script></body>
78
78
  </html>