@blueyerobotics/blueye-ts 1.1.0 → 1.2.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.
- package/dist/src/client.d.ts +2 -1
- package/dist/src/client.js +6 -4
- package/package.json +1 -1
package/dist/src/client.d.ts
CHANGED
|
@@ -16,13 +16,14 @@ export type Events = {
|
|
|
16
16
|
};
|
|
17
17
|
export declare const isInProtocol: (key: string) => key is keyof typeof blueye.protocol;
|
|
18
18
|
export declare class BlueyeClient {
|
|
19
|
+
timeout: number;
|
|
19
20
|
private wsPubSub;
|
|
20
21
|
private wsReqRep;
|
|
21
22
|
private isReqRepConnected;
|
|
22
23
|
private logger;
|
|
23
24
|
private pendingRequests;
|
|
24
25
|
sub: Emitter<Events>;
|
|
25
|
-
constructor(logLevel?: LogLevel);
|
|
26
|
+
constructor(timeout?: number, logLevel?: LogLevel);
|
|
26
27
|
sendRequest<T extends Req>(req: T, opts?: CreateArgs<T>): Promise<DecodedOutput<T> | null>;
|
|
27
28
|
getTelemetry<T extends Tel>(type: T): Promise<DecodedTelOutput<T>>;
|
|
28
29
|
}
|
package/dist/src/client.js
CHANGED
|
@@ -14,13 +14,15 @@ const isInProtocol = (key) => {
|
|
|
14
14
|
};
|
|
15
15
|
exports.isInProtocol = isInProtocol;
|
|
16
16
|
class BlueyeClient {
|
|
17
|
+
timeout;
|
|
17
18
|
wsPubSub;
|
|
18
19
|
wsReqRep;
|
|
19
20
|
isReqRepConnected = false;
|
|
20
21
|
logger;
|
|
21
22
|
pendingRequests = new Map();
|
|
22
23
|
sub = new strict_event_emitter_1.Emitter();
|
|
23
|
-
constructor(logLevel = consola_1.LogLevels.info) {
|
|
24
|
+
constructor(timeout = 2000, logLevel = consola_1.LogLevels.info) {
|
|
25
|
+
this.timeout = timeout;
|
|
24
26
|
this.logger = (0, consola_1.createConsola)({ level: logLevel, formatOptions: { colors: true, compact: false } });
|
|
25
27
|
this.wsPubSub = new WebSocket(WS_PUBSUB_URL);
|
|
26
28
|
this.wsReqRep = new WebSocket(WS_REQREP_URL);
|
|
@@ -44,7 +46,6 @@ class BlueyeClient {
|
|
|
44
46
|
if (!id)
|
|
45
47
|
throw new Error("Response id is missing");
|
|
46
48
|
this.pendingRequests.get(id)?.({ key, data });
|
|
47
|
-
this.pendingRequests.delete(id);
|
|
48
49
|
});
|
|
49
50
|
}
|
|
50
51
|
async sendRequest(req, opts = {}) {
|
|
@@ -55,10 +56,10 @@ class BlueyeClient {
|
|
|
55
56
|
this.logger.debug("Waiting...");
|
|
56
57
|
await new Promise(res => setTimeout(res, 50));
|
|
57
58
|
}
|
|
59
|
+
const id = (0, uuid_1.v4)();
|
|
58
60
|
const { key, data } = await Promise.race([
|
|
59
|
-
new Promise((_, reject) => setTimeout(() => reject(new Error("Request timed out")),
|
|
61
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("Request timed out")), this.timeout)),
|
|
60
62
|
new Promise(resolve => {
|
|
61
|
-
const id = (0, uuid_1.v4)();
|
|
62
63
|
const request = JSON.stringify({
|
|
63
64
|
id,
|
|
64
65
|
key: `blueye.protocol.${req}`,
|
|
@@ -68,6 +69,7 @@ class BlueyeClient {
|
|
|
68
69
|
this.wsReqRep.send(request);
|
|
69
70
|
})
|
|
70
71
|
]);
|
|
72
|
+
this.pendingRequests.delete(id);
|
|
71
73
|
if (key === "Empty") {
|
|
72
74
|
return null;
|
|
73
75
|
}
|