@blueyerobotics/blueye-ts 3.3.0 → 3.5.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.
@@ -0,0 +1,4 @@
1
+ export declare class AsyncQueue {
2
+ private lastPromise;
3
+ enqueue<T>(fn: () => Promise<T>): Promise<T>;
4
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AsyncQueue = void 0;
4
+ class AsyncQueue {
5
+ lastPromise = Promise.resolve();
6
+ enqueue(fn) {
7
+ const run = this.lastPromise.then(() => fn());
8
+ this.lastPromise = run.finally(() => { });
9
+ return run;
10
+ }
11
+ }
12
+ exports.AsyncQueue = AsyncQueue;
@@ -37,6 +37,7 @@ export declare class BlueyeClient extends Emitter<Events> {
37
37
  private sub;
38
38
  private rpc;
39
39
  private pub;
40
+ private queue;
40
41
  private logger;
41
42
  constructor({ subUrl, rpcUrl, pubUrl, timeout, logLevel, autoConnect, }?: Options);
42
43
  private updateState;
@@ -6,6 +6,7 @@ const buffer_1 = require("buffer");
6
6
  const consola_1 = require("consola");
7
7
  const jszmq_1 = require("jszmq");
8
8
  const strict_event_emitter_1 = require("strict-event-emitter");
9
+ const async_queue_1 = require("./async-queue");
9
10
  const schema_1 = require("./schema");
10
11
  const DEFAULT_SUB_URL = "ws://192.168.1.101:9985";
11
12
  const DEFAULT_RPC_URL = "ws://192.168.1.101:9986";
@@ -23,20 +24,22 @@ class BlueyeClient extends strict_event_emitter_1.Emitter {
23
24
  sub;
24
25
  rpc;
25
26
  pub;
27
+ queue;
26
28
  logger;
27
29
  constructor({ subUrl = DEFAULT_SUB_URL, rpcUrl = DEFAULT_RPC_URL, pubUrl = DEFAULT_PUB_URL, timeout = 2000, logLevel = consola_1.LogLevels.info, autoConnect = false, } = {}) {
28
30
  super();
29
31
  this.timeout = timeout;
30
- this.logger = (0, consola_1.createConsola)({
31
- level: logLevel,
32
- formatOptions: { colors: true, compact: false },
33
- });
34
32
  this.subUrl = subUrl;
35
33
  this.rpcUrl = rpcUrl;
36
34
  this.pubUrl = pubUrl;
37
35
  this.sub = new jszmq_1.Sub();
38
36
  this.rpc = new jszmq_1.Req();
39
37
  this.pub = new jszmq_1.Pub();
38
+ this.queue = new async_queue_1.AsyncQueue();
39
+ this.logger = (0, consola_1.createConsola)({
40
+ level: logLevel,
41
+ formatOptions: { colors: true, compact: false },
42
+ });
40
43
  // @ts-ignore
41
44
  this.sub.on("message", (topic, msg) => {
42
45
  const { key, data } = schema_1.responseSchema.parse({ key: topic, data: msg });
@@ -96,9 +99,8 @@ class BlueyeClient extends strict_event_emitter_1.Emitter {
96
99
  const protocol = protocol_definitions_1.blueye.protocol[req];
97
100
  const message = protocol.create(opts);
98
101
  const encoded = protocol.encode(message).finish();
99
- const { key, data } = await Promise.race([
100
- new Promise((_, reject) => setTimeout(() => reject(new Error("[rpc] request timed out")), this.timeout)),
101
- new Promise((resolve) => {
102
+ const request = () => {
103
+ return new Promise((resolve) => {
102
104
  // @ts-ignore
103
105
  this.rpc.once("message", (topic, msg) => {
104
106
  resolve({ key: topic.toString().split(".").at(-1), data: msg });
@@ -107,7 +109,11 @@ class BlueyeClient extends strict_event_emitter_1.Emitter {
107
109
  buffer_1.Buffer.from(`blueye.protocol.${req}`),
108
110
  buffer_1.Buffer.from(encoded),
109
111
  ]);
110
- }),
112
+ });
113
+ };
114
+ const { key, data } = await Promise.race([
115
+ new Promise((_, reject) => setTimeout(() => reject(new Error("[rpc] request timed out")), this.timeout)),
116
+ this.queue.enqueue(request),
111
117
  ]);
112
118
  if (key === "Empty") {
113
119
  return null;
@@ -1,34 +1,12 @@
1
1
  import { Buffer } from "buffer";
2
2
  import z from "zod";
3
3
  export declare const responseSchema: z.ZodObject<{
4
- key: z.ZodEffects<z.ZodType<Buffer, z.ZodTypeDef, Buffer>, string, Buffer>;
5
- data: z.ZodType<Buffer, z.ZodTypeDef, Buffer>;
6
- }, "strip", z.ZodTypeAny, {
7
- key: string;
8
- data: Buffer;
9
- }, {
10
- key: Buffer;
11
- data: Buffer;
12
- }>;
4
+ key: z.ZodPipe<z.ZodCustom<Buffer, Buffer>, z.ZodTransform<string, Buffer>>;
5
+ data: z.ZodCustom<Buffer, Buffer>;
6
+ }, z.core.$strip>;
13
7
  export declare const telemetrySchema: z.ZodObject<{
14
8
  payload: z.ZodObject<{
15
- typeUrl: z.ZodEffects<z.ZodString, string, string>;
16
- value: z.ZodEffects<z.ZodEffects<z.ZodAny, Buffer | Uint8Array<ArrayBufferLike>, any>, Buffer, any>;
17
- }, "strip", z.ZodTypeAny, {
18
- value: Buffer;
19
- typeUrl: string;
20
- }, {
21
- typeUrl: string;
22
- value?: any;
23
- }>;
24
- }, "strip", z.ZodTypeAny, {
25
- payload: {
26
- value: Buffer;
27
- typeUrl: string;
28
- };
29
- }, {
30
- payload: {
31
- typeUrl: string;
32
- value?: any;
33
- };
34
- }>;
9
+ typeUrl: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
10
+ value: z.ZodPipe<z.ZodAny, z.ZodTransform<Buffer, any>>;
11
+ }, z.core.$strip>;
12
+ }, z.core.$strip>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueyerobotics/blueye-ts",
3
- "version": "3.3.0",
3
+ "version": "3.5.0",
4
4
  "description": "A TypeScript client for interacting with Blueye underwater drones.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,15 +15,15 @@
15
15
  "author": "Blueye <contact@blueye.no> (https://blueye.no/)",
16
16
  "license": "LGPL-3.0-only",
17
17
  "dependencies": {
18
- "@blueyerobotics/protocol-definitions": "3.2.0-946df8e4",
18
+ "@blueyerobotics/protocol-definitions": "3.2.0-b1918def",
19
19
  "buffer": "^6.0.3",
20
20
  "consola": "^3.4.2",
21
21
  "jszmq": "^0.1.2",
22
22
  "strict-event-emitter": "^0.5.1",
23
- "zod": "^3.25.67"
23
+ "zod": "^4.1.12"
24
24
  },
25
25
  "devDependencies": {
26
- "typescript": "^5.9.2"
26
+ "typescript": "^5.9.3"
27
27
  },
28
28
  "scripts": {
29
29
  "start": "node dist/example.js",