Skip to content

Close websocket connection? #32

Open
@uLan08

Description

@uLan08

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions