libshv-js 3.0.0 → 3.0.1

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 +4 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libshv-js",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
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
@@ -40,6 +40,7 @@ type WsClientOptions = {
40
40
  timeout?: number;
41
41
  wsUri: string;
42
42
  onConnected: () => void;
43
+ onDisconnected: () => void;
43
44
  onRequest: (rpc_msg: RpcMessage) => void;
44
45
  };
45
46
 
@@ -85,6 +86,7 @@ class WsClient {
85
86
  password: WsClientOptions['password'];
86
87
  loginType: WsClientOptions['loginType'];
87
88
  onConnected: WsClientOptions['onConnected'];
89
+ onDisconnected: WsClientOptions['onDisconnected'];
88
90
  onRequest: WsClientOptions['onRequest'];
89
91
  timeout: WsClientOptions['timeout'];
90
92
 
@@ -104,6 +106,7 @@ class WsClient {
104
106
  this.websocket.binaryType = 'arraybuffer';
105
107
 
106
108
  this.onConnected = options.onConnected ?? (() => {/* nothing */});
109
+ this.onDisconnected = options.onDisconnected ?? (() => {/* nothing */});
107
110
  this.onRequest = options.onRequest ?? (() => {/* nothing */});
108
111
 
109
112
  this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
@@ -132,6 +135,7 @@ class WsClient {
132
135
 
133
136
  this.websocket.addEventListener('close', () => {
134
137
  this.logDebug('DISCONNECTED');
138
+ this.onDisconnected();
135
139
  });
136
140
 
137
141
  this.websocket.addEventListener('message', evt => {
@@ -170,10 +174,6 @@ class WsClient {
170
174
  console.log('WebSocket ERROR', evt);
171
175
  this.logDebug('WebSocket ERROR');
172
176
  });
173
-
174
- this.websocket.addEventListener('close', evt => {
175
- this.logDebug(`socket close code: ${evt.code}`);
176
- });
177
177
  }
178
178
 
179
179
  callRpcMethod(shv_path: string | undefined, method: 'dir', params?: RpcValue): Promise<RpcResponse<DirResult>>;