How would you properly close a websocket connection? Basically what I am trying to do is check if correct query string parameters are not present then I close the connection.
Here's what I am trying to do right now.
app.ws.use(route.get('/ws', (ctx) => {
const { foo, bar } = ctx.query
if (!foo && !bar) {
ctx.websocket.close(1000, 'Wrong or missing parameters')
ctx.websocket.terminate()
return
}
}))
I am not really sure if this is correct because I keep on getting socket hang up messages and if I remove the return everything after the if statement still gets executed. I also tried using onclose event on the client but it never triggers.
How would you properly close a websocket connection? Basically what I am trying to do is check if correct query string parameters are not present then I close the connection.
Here's what I am trying to do right now.
I am not really sure if this is correct because I keep on getting
socket hang upmessages and if I remove thereturneverything after the if statement still gets executed. I also tried usingoncloseevent on the client but it never triggers.