configurapi-handler-ws 1.2.0 → 1.3.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/README.md +3 -1
- package/package.json +1 -1
- package/src/webSocketClient.d.ts +1 -0
- package/src/webSocketClient.js +17 -6
package/README.md
CHANGED
|
@@ -35,8 +35,10 @@ Configurapi request handlers for websocket
|
|
|
35
35
|
|
|
36
36
|
* Use WebSocketClient to connect to a WebSocket runner, send data over the connection, and disconnect from the runner when finished.
|
|
37
37
|
* To pass data (such as a protocol or authentication token) when establishing the WebSocket connection, provide it as the second parameter to the constructor.
|
|
38
|
+
* If a connection could not be made (e.g. the on_connect route returns 400+ status code), an error will be sent to onPush().
|
|
39
|
+
* The client has a default timeout of 27 seconds. To increase the wait time for results, set the `replyTimeoutMs` parameter in the constructor's second argument.
|
|
38
40
|
|
|
39
41
|
```
|
|
40
42
|
const { WebSocketClient } = require("configurapi-handler-ws");
|
|
41
|
-
let client = new WebSocketClient(WEBSOCKET_BASE_URL, {onPush: (data:IResponse)=>console.log(data)});
|
|
43
|
+
let client = new WebSocketClient(WEBSOCKET_BASE_URL, {replyTimeoutMs: 300000, onPush: (data:IResponse)=>console.log(data)});
|
|
42
44
|
```
|
package/package.json
CHANGED
package/src/webSocketClient.d.ts
CHANGED
package/src/webSocketClient.js
CHANGED
|
@@ -199,7 +199,7 @@ module.exports = class WebSocketClient
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
const id = this.getHeaderCaseInsensitive(msg.headers, MessageIdHeaderName);
|
|
202
|
-
|
|
202
|
+
|
|
203
203
|
if (msg?.statusCode && msg.statusCode !== 202 && id && this.inflight.has(id))
|
|
204
204
|
{
|
|
205
205
|
const waiter = this.inflight.get(id);
|
|
@@ -222,14 +222,25 @@ module.exports = class WebSocketClient
|
|
|
222
222
|
}
|
|
223
223
|
else
|
|
224
224
|
{
|
|
225
|
+
//no inflight ws connections.
|
|
225
226
|
if(msg?.statusCode > 299)
|
|
226
227
|
{
|
|
227
|
-
const error = new Error(`${msg.message} - (${msg.statusCode})`)
|
|
228
|
-
|
|
228
|
+
const error = new Error(`${msg.message} - (${msg.statusCode})`);
|
|
229
|
+
|
|
230
|
+
if(this.onPush)
|
|
231
|
+
{
|
|
232
|
+
this.onPush(msg)
|
|
233
|
+
}
|
|
234
|
+
else
|
|
235
|
+
{
|
|
236
|
+
throw error;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else
|
|
240
|
+
{
|
|
241
|
+
// No id or unknown id. Treat as push/unsolicited.
|
|
242
|
+
if (this.onPush) this.onPush(msg);
|
|
229
243
|
}
|
|
230
|
-
|
|
231
|
-
// No id or unknown id. Treat as push/unsolicited.
|
|
232
|
-
if (this.onPush) this.onPush(msg);
|
|
233
244
|
}
|
|
234
245
|
}
|
|
235
246
|
|