configurapi-runner-ws 1.3.0 → 1.4.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.
- package/README.md +4 -4
- package/package.json +1 -1
- package/src/wsAdapter.js +4 -4
package/README.md
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
- User `Response` for a regular response data.
|
|
5
5
|
- Use `StreamResponse` from `configurapi-handler-ws` for a stream response.
|
|
6
6
|
- With a stream response, data will be delivered from the server in chunks.
|
|
7
|
-
- A check will have `
|
|
8
|
-
- The last chunk will have `
|
|
9
|
-
- Check `
|
|
7
|
+
- A check will have `x-stream: chunk` header.
|
|
8
|
+
- The last chunk will have `x-stream: done` header.
|
|
9
|
+
- Check `x-stream-id: $id` header for the stream ID. A chunk belonging to the same stream will have the same stream ID.
|
|
10
10
|
- connectionId is available at `event.request.headers.connectionId`
|
|
11
11
|
- `on_connect` and `on_disconnect` will be called when a new connection is made or closed.
|
|
12
|
-
- Use `Request.headers
|
|
12
|
+
- Use `Request.headers['push-function']` to send an out-of-band message. The function is async and accepts an object to send back to the caller.
|
package/package.json
CHANGED
package/src/wsAdapter.js
CHANGED
|
@@ -48,7 +48,7 @@ module.exports = {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
const payload = { chunk: bucket };
|
|
51
|
-
const headers = { '
|
|
51
|
+
const headers = { 'x-stream': 'chunk', 'x-stream-id': streamId, 'Content-Type': 'application/json' };
|
|
52
52
|
const response = new Response(bucket, 200, headers);
|
|
53
53
|
|
|
54
54
|
ws.send(JSON.stringify(response), (err) =>
|
|
@@ -94,7 +94,7 @@ module.exports = {
|
|
|
94
94
|
|
|
95
95
|
if (ws.readyState === WebSocket.OPEN)
|
|
96
96
|
{
|
|
97
|
-
const headers = { '
|
|
97
|
+
const headers = { 'x-stream-id': streamId, 'x-stream': 'done' };
|
|
98
98
|
const response = new Response('', 204, headers);
|
|
99
99
|
|
|
100
100
|
ws.send(JSON.stringify(response), (err) =>
|
|
@@ -149,8 +149,8 @@ module.exports = {
|
|
|
149
149
|
request.params = data.params || {};
|
|
150
150
|
request.payload = data.payload || undefined;
|
|
151
151
|
|
|
152
|
-
request.headers['
|
|
153
|
-
request.headers['
|
|
152
|
+
request.headers['connection-id'] = ws.connectionId;
|
|
153
|
+
request.headers['push-function'] = async (data)=>await this.write(ws, data);
|
|
154
154
|
|
|
155
155
|
return request;
|
|
156
156
|
}
|