signalk-siparu 0.2.23 → 0.2.24

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "signalk-siparu",
3
- "version": "0.2.23",
3
+ "version": "0.2.24",
4
4
  "description": "Kept aboard, proven ashore. Position, wind, depth and voyage history, recorded on the boat and readable from anywhere: sealed to the devices you name, signed on the way out. A read-only Signal K plugin with a built-in dashboard.",
5
5
  "keywords": [
6
6
  "signalk-node-server-plugin",
@@ -360,6 +360,13 @@ export interface ApiError {
360
360
  message: string;
361
361
  };
362
362
  }
363
+ export interface UnreadableAskReply {
364
+ id: string;
365
+ error: {
366
+ code: 'UNREADABLE';
367
+ message: string;
368
+ };
369
+ }
363
370
  export interface WrappedKey {
364
371
  kid: string;
365
372
  wrap: string;
@@ -117,4 +117,7 @@ export declare function rpcEnvelope(data: string): {
117
117
  id: string;
118
118
  } | null;
119
119
  export declare function isWatchingNote(data: string): boolean;
120
+ export declare function unopenedAsk(data: string): {
121
+ id: string;
122
+ } | null;
120
123
  export {};
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LiveUplink = exports.SHORE_MESSAGE_MAX_BYTES = exports.PING_EVERY_MS = exports.REPORTING_STALE_MS = exports.PROMPTED_FRAME_FLOOR_MS = exports.STILL_FRAME_EVERY_MS = exports.FRAME_EVERY_MS = void 0;
4
4
  exports.rpcEnvelope = rpcEnvelope;
5
5
  exports.isWatchingNote = isWatchingNote;
6
+ exports.unopenedAsk = unopenedAsk;
6
7
  exports.FRAME_EVERY_MS = 2_000;
7
8
  exports.STILL_FRAME_EVERY_MS = 60_000;
8
9
  exports.PROMPTED_FRAME_FLOOR_MS = 5_000;
@@ -14,6 +15,11 @@ const STILL_NAV_STATES = new Set(['anchored', 'moored', 'aground']);
14
15
  exports.PING_EVERY_MS = 25_000;
15
16
  const RECONNECT_BASE_MS = 5_000;
16
17
  const RECONNECT_CEILING_MS = 15 * 60_000;
18
+ const UNREADABLE_ASK = {
19
+ code: 'UNREADABLE',
20
+ message: 'This boat could not open the question as it was sealed. Open this screen again; if it ' +
21
+ 'keeps happening, update the Siparu plugin aboard and the app.'
22
+ };
17
23
  const STAND_OFF_MS = 15 * 60_000;
18
24
  const UNPAIRED_RECHECK_MS = 60_000;
19
25
  const CLOSE_UNKNOWN_TOKEN = 1008;
@@ -150,6 +156,11 @@ class LiveUplink {
150
156
  this.dispatch(gen, opened.plaintext);
151
157
  return;
152
158
  }
159
+ const unread = unopenedAsk(data);
160
+ if (unread) {
161
+ this.reply(gen, { id: unread.id, error: UNREADABLE_ASK });
162
+ return;
163
+ }
153
164
  const asked = rpcEnvelope(data);
154
165
  if (asked) {
155
166
  const refusal = {
@@ -684,3 +695,16 @@ function isWatchingNote(data) {
684
695
  return false;
685
696
  return msg.type === 'watching';
686
697
  }
698
+ function unopenedAsk(data) {
699
+ let msg;
700
+ try {
701
+ msg = JSON.parse(data);
702
+ }
703
+ catch {
704
+ return null;
705
+ }
706
+ if (!msg || typeof msg !== 'object')
707
+ return null;
708
+ const { type, id } = msg;
709
+ return type === 'ask' && typeof id === 'string' && id.length > 0 ? { id } : null;
710
+ }