configurapi-runner-ws 1.11.0 → 1.13.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 +1 -1
- package/src/index.js +15 -5
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -58,7 +58,7 @@ module.exports = class HttpRunner extends events.EventEmitter
|
|
|
58
58
|
e.response.body = Object.keys(connections);
|
|
59
59
|
});
|
|
60
60
|
loader.handlers.set('post_@connection', async (e)=>
|
|
61
|
-
{
|
|
61
|
+
{
|
|
62
62
|
e.response.headers['Content-Type'] = 'application/json';
|
|
63
63
|
|
|
64
64
|
const connectionId = e.params?.['@connection'];
|
|
@@ -142,12 +142,8 @@ module.exports = class HttpRunner extends events.EventEmitter
|
|
|
142
142
|
}
|
|
143
143
|
this.emit("trace", `[connect] ${connectionId}`);
|
|
144
144
|
|
|
145
|
-
let onConnectPromise = config.events.has('on_connect') ? this._requestListener(ws, undefined, 'on_connect') : undefined;
|
|
146
|
-
|
|
147
145
|
ws.on("message", async (data) =>
|
|
148
146
|
{
|
|
149
|
-
await onConnectPromise;
|
|
150
|
-
|
|
151
147
|
const incomingMessage = typeof data === "string" ? data : data.toString("utf8");
|
|
152
148
|
|
|
153
149
|
await this._requestListener(ws, incomingMessage);
|
|
@@ -170,6 +166,16 @@ module.exports = class HttpRunner extends events.EventEmitter
|
|
|
170
166
|
const message = err instanceof Error ? err.message : err;
|
|
171
167
|
this.emit("error", `${connectionId} - ${message}`);
|
|
172
168
|
});
|
|
169
|
+
|
|
170
|
+
if (config.events.has('on_connect'))
|
|
171
|
+
{
|
|
172
|
+
const response = await this._requestListener(ws, undefined, 'on_connect');
|
|
173
|
+
|
|
174
|
+
if (response.statusCode >= 400)
|
|
175
|
+
{
|
|
176
|
+
return ws.close(1008, 'Policy Violation');
|
|
177
|
+
}
|
|
178
|
+
}
|
|
173
179
|
});
|
|
174
180
|
}
|
|
175
181
|
|
|
@@ -225,6 +231,8 @@ module.exports = class HttpRunner extends events.EventEmitter
|
|
|
225
231
|
|
|
226
232
|
await WsAdapter.write(ws, event.response); // Send response back to the caller.
|
|
227
233
|
}
|
|
234
|
+
|
|
235
|
+
return event.response;
|
|
228
236
|
}
|
|
229
237
|
catch (error)
|
|
230
238
|
{
|
|
@@ -251,6 +259,8 @@ module.exports = class HttpRunner extends events.EventEmitter
|
|
|
251
259
|
console.log(errorFromListner);
|
|
252
260
|
}
|
|
253
261
|
}
|
|
262
|
+
|
|
263
|
+
return response;
|
|
254
264
|
}
|
|
255
265
|
}
|
|
256
266
|
|