libshv-js 3.9.0 → 3.10.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/ws-client.ts +5 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libshv-js",
3
- "version": "3.9.0",
3
+ "version": "3.10.0",
4
4
  "description": "Typescript implementation of libshv",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
package/src/ws-client.ts CHANGED
@@ -58,7 +58,7 @@ type WsClientOptionsLogin = WsClientOptionsCommon & {
58
58
  onConnected: () => void;
59
59
  onConnectionFailure: (error: Error) => void;
60
60
  onDisconnected: () => void;
61
- onRequest: (shvPath: string, method: string, param: RpcValue, delay: (progress: number) => void) => Promise<RpcValue>;
61
+ onRequest: (shvPath: string, method: string, param: RpcValue, delay: (progress: number) => void) => RpcValue | Promise<RpcValue>;
62
62
  };
63
63
 
64
64
  type WsClientOptionsWorkflows = WsClientOptionsCommon & {
@@ -139,10 +139,10 @@ export const NotImplemented = createErrorClass(ErrorCode.NotImplemented);
139
139
 
140
140
  class WsClient {
141
141
  private requestId = 1;
142
- private pingTimerId = -1;
142
+ private pingTimerId: ReturnType<typeof globalThis.setInterval> | undefined = undefined;
143
143
  private rpcHandlers: Array<{
144
144
  resolve: RpcResponseResolver;
145
- timeout_handle: number;
145
+ timeout_handle: ReturnType<typeof globalThis.setTimeout>;
146
146
  }> = [];
147
147
  private readonly subscriptions: Subscription[] = [];
148
148
  private readonly websocket: WebSocket;
@@ -193,8 +193,9 @@ class WsClient {
193
193
  }));
194
194
  };
195
195
 
196
+ const result = this.options.onRequest(rpcMsg.meta[RPC_MESSAGE_SHV_PATH], rpcMsg.meta[RPC_MESSAGE_METHOD], rpcMsg.value[RPC_MESSAGE_PARAMS], sendDelay);
196
197
  respond(makeIMap({
197
- [RPC_MESSAGE_RESULT]: await this.options.onRequest(rpcMsg.meta[RPC_MESSAGE_SHV_PATH], rpcMsg.meta[RPC_MESSAGE_METHOD], rpcMsg.value[RPC_MESSAGE_PARAMS], sendDelay),
198
+ [RPC_MESSAGE_RESULT]: result instanceof Promise ? await result : result,
198
199
  }));
199
200
  } catch (error: unknown) {
200
201
  const sendError = (error: RpcError) => {