configurapi-runner-ws 1.6.1 → 1.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "configurapi-runner-ws",
3
- "version": "1.6.1",
3
+ "version": "1.8.0",
4
4
  "description": "Websocket runner for configurapi.",
5
5
  "bin": {
6
6
  "configurapi-runner-ws": "src/app.mjs"
package/src/index.js CHANGED
@@ -79,18 +79,20 @@ module.exports = class HttpRunner extends events.EventEmitter
79
79
 
80
80
  this.emit("trace", `[connect] ${connectionId}`);
81
81
 
82
- this._requestListener(ws, undefined, 'on_connect');
82
+ let onConnectPromise = this._requestListener(ws, undefined, 'on_connect');
83
83
 
84
84
  ws.on("message", async (data) =>
85
85
  {
86
+ await onConnectPromise;
87
+
86
88
  const incomingMessage = typeof data === "string" ? data : data.toString("utf8");
87
89
 
88
- this._requestListener(ws, incomingMessage);
90
+ await this._requestListener(ws, incomingMessage);
89
91
  });
90
92
 
91
- ws.on("close", (code, reason) =>
93
+ ws.on("close", async(code, reason) =>
92
94
  {
93
- this._requestListener(ws, undefined, 'on_disconnect');
95
+ await this._requestListener(ws, undefined, 'on_disconnect');
94
96
 
95
97
  const reasonMessage = reason && reason.length ? reason.toString("utf8") : "";
96
98
 
@@ -126,6 +128,8 @@ module.exports = class HttpRunner extends events.EventEmitter
126
128
  {
127
129
  event = new Configurapi.Event(await WsAdapter.toRequest(ws, incomingMessage));
128
130
 
131
+ event.identity = event.identity || ws.identity;
132
+
129
133
  if(customEventName)
130
134
  {
131
135
  event.name = customEventName;
@@ -141,8 +145,9 @@ module.exports = class HttpRunner extends events.EventEmitter
141
145
  }
142
146
 
143
147
  event.response.headers['Sec-WebSocket-Protocol'] = protocol;
148
+ ws.identity = event.identity;
144
149
  }
145
-
150
+
146
151
  await WsAdapter.write(ws, event.response);
147
152
  }
148
153
  else
package/src/wsAdapter.js CHANGED
@@ -47,8 +47,7 @@ module.exports = {
47
47
  setTimeout(check, 100);
48
48
  }
49
49
 
50
- const payload = { chunk: bucket };
51
- const headers = { 'message-id': streamId, 'x-stream': 'chunk', 'x-stream-id': streamId, 'Content-Type': 'application/json' };
50
+ const headers = { 'message-id': streamId, 'x-stream': 'chunk', 'x-stream-id': streamId, 'Content-Type': 'text/plain' };
52
51
  const response = new Response(bucket, 200, headers);
53
52
 
54
53
  ws.send(JSON.stringify(response), (err) =>