signalk-flags 1.0.0 → 1.0.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/package.json +4 -8
- package/plugin/index.d.ts +1 -12
- package/plugin/index.js +27 -28
- package/CHANGELOG.md +0 -7
- package/signalk-flags-1.0.0.tgz +0 -0
package/package.json
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "signalk-flags",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Country Flags plugin for Signal K server.",
|
|
5
5
|
"main": "plugin/index.js",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"signalk-node-server-plugin"
|
|
8
8
|
],
|
|
9
|
-
"repository": "https://github.com/panaaj/signalk-
|
|
9
|
+
"repository": "https://github.com/panaaj/signalk-flags",
|
|
10
10
|
"author": "AdrianP",
|
|
11
|
-
"contributors": [
|
|
12
|
-
{
|
|
13
|
-
"name": "panaaj@hotmail.com"
|
|
14
|
-
}
|
|
15
|
-
],
|
|
16
11
|
"license": "Apache-20",
|
|
17
12
|
"scripts": {
|
|
18
13
|
"build": "tsc",
|
|
@@ -23,10 +18,11 @@
|
|
|
23
18
|
"format": "prettier --write src/*"
|
|
24
19
|
},
|
|
25
20
|
"dependencies": {
|
|
26
|
-
"@signalk/server-api": "^2.
|
|
21
|
+
"@signalk/server-api": "^2.9.0",
|
|
27
22
|
"flag-icons": "^7.3.2"
|
|
28
23
|
},
|
|
29
24
|
"devDependencies": {
|
|
25
|
+
"@types/baconjs": "^0.7.34",
|
|
30
26
|
"@types/express": "^4.17.6",
|
|
31
27
|
"prettier": "^2.5.1",
|
|
32
28
|
"typescript": "^4.5.4"
|
package/plugin/index.d.ts
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
import { Application } from 'express';
|
|
2
|
-
import {
|
|
3
|
-
interface SKDeltaSubscription {
|
|
4
|
-
context: string;
|
|
5
|
-
subscribe: Array<{
|
|
6
|
-
path: string;
|
|
7
|
-
period: number;
|
|
8
|
-
}>;
|
|
9
|
-
}
|
|
2
|
+
import { ServerAPI } from '@signalk/server-api';
|
|
10
3
|
export interface FlagsApp extends ServerAPI, Application {
|
|
11
|
-
subscriptionmanager: {
|
|
12
|
-
subscribe: (subscribe: SKDeltaSubscription, unsubscribes: Array<any>, errorCallback: (error: any) => void, deltaCallback: (delta: Delta) => void) => void;
|
|
13
|
-
};
|
|
14
4
|
}
|
|
15
|
-
export {};
|
package/plugin/index.js
CHANGED
|
@@ -40,7 +40,6 @@ const promises_1 = require("fs/promises");
|
|
|
40
40
|
const path_1 = __importDefault(require("path"));
|
|
41
41
|
const server_api_1 = require("@signalk/server-api");
|
|
42
42
|
const openapi = __importStar(require("./openApi.json"));
|
|
43
|
-
const mid_1 = require("./mid");
|
|
44
43
|
const CONFIG_SCHEMA = {
|
|
45
44
|
properties: {}
|
|
46
45
|
};
|
|
@@ -132,26 +131,30 @@ module.exports = (server) => {
|
|
|
132
131
|
return;
|
|
133
132
|
}
|
|
134
133
|
u.values.forEach((v) => {
|
|
135
|
-
if (v.path === '' && 'mmsi' in v.value) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
134
|
+
if (v.path === '' && v.value && 'mmsi' in v.value) {
|
|
135
|
+
// if doesn't already have flag property
|
|
136
|
+
const vf = server.getPath(`${context}.flag`);
|
|
137
|
+
if (!vf) {
|
|
138
|
+
const country = countryFromMmsi(v.value.mmsi);
|
|
139
|
+
if (country) {
|
|
140
|
+
server.handleMessage(plugin.id, {
|
|
141
|
+
context: context,
|
|
142
|
+
updates: [
|
|
143
|
+
{
|
|
144
|
+
values: [
|
|
145
|
+
{
|
|
146
|
+
path: 'flag',
|
|
147
|
+
value: country.alpha2
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
path: 'port',
|
|
151
|
+
value: country.name
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
]
|
|
156
|
+
});
|
|
157
|
+
}
|
|
155
158
|
}
|
|
156
159
|
}
|
|
157
160
|
});
|
|
@@ -237,7 +240,7 @@ module.exports = (server) => {
|
|
|
237
240
|
const iconFromMmsi = (mmsi, aspect = '4x3', res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
238
241
|
try {
|
|
239
242
|
const country = countryFromMmsi(mmsi);
|
|
240
|
-
const flag = `${IMG_BASE_PATH}/${aspect}/${country
|
|
243
|
+
const flag = `${IMG_BASE_PATH}/${aspect}/${country === null || country === void 0 ? void 0 : country.alpha2.toLowerCase()}.svg`;
|
|
241
244
|
// check flag file exists
|
|
242
245
|
yield (0, promises_1.access)(flag, fs_1.constants.R_OK);
|
|
243
246
|
res.sendFile(flag, (err) => {
|
|
@@ -262,14 +265,10 @@ module.exports = (server) => {
|
|
|
262
265
|
/**
|
|
263
266
|
* Get country details from supplied MMSI
|
|
264
267
|
* @param mmsi Maritime mobile service identifier
|
|
265
|
-
* @returns
|
|
268
|
+
* @returns Object containing country details
|
|
266
269
|
*/
|
|
267
270
|
const countryFromMmsi = (mmsi) => {
|
|
268
|
-
|
|
269
|
-
mmsi = mmsi.toString();
|
|
270
|
-
}
|
|
271
|
-
const mid = mmsi.slice(0, 3);
|
|
272
|
-
return mid_1.MID[mid];
|
|
271
|
+
return (0, server_api_1.getFlagCountry)(mmsi);
|
|
273
272
|
};
|
|
274
273
|
return plugin;
|
|
275
274
|
};
|
package/CHANGELOG.md
DELETED
package/signalk-flags-1.0.0.tgz
DELETED
|
Binary file
|