when I make a request to my API, my code is using a web socket (Ws https://www.npmjs.com/package/ws) that I have connected to another server (port 7777). The web socket is doing its job correctly, sending correctly and receiving correctly what I'm asking for, however once I get the message from the web socket I would like to send the data from the web socket via my API using response.ok but it doesn't return anything (screen below).
Code:
public async embed_builder ({ request, response }: HttpContextContract) {
const payload = request.body();
Ws.ws.on("open", () => {
Ws.ws.send(JSON.stringify({
socket_name: "embed-builder",
channel_id: payload.channel_id,
embed: payload.embed
}));
Ws.ws.on("message", (data: Buffer) => {
const message = JSON.parse(data.toString());
// ^ message is perfectly defined 👍
if (message.socket_name === "embed-builder") {
// everything is ok 👍
if (!message.ok) return response.badRequest({ error: { message: message.statusText }, code: message.status });
// everything is ok 👍
return response.ok("OK")
// ^ I don't receive anything and I don't know if it works 👎
}
});
});
}
