adonis-websocket icon indicating copy to clipboard operation
adonis-websocket copied to clipboard

How to close socket connection via middleware?

Open phambinh217 opened this issue 5 years ago • 1 comments

Dear, I do the example follow: https://adonisjs.com/docs/4.1/websocket-server#_creating_middleware, and I modify some code like bellow

'use strict'

class CustomMiddleware {
  // for HTTP
  async handle (ctx, next) {
  }

  // for WebSocket
  async wsHandle (ctx, next) {
    ctx.socket.close() // I wan to close socket connection before it go to my ChatController
  }
}

module.exports = CustomMiddleware

But it not woking, socket never close. Is it bugs or what am I doing wrong?

I using adonisjs 4.1. my node version is 10.x

phambinh217 avatar Mar 30 '19 01:03 phambinh217

You have to use throw error like this to stop the process and catch it from the client side throw new Error('Some authentication error')

fokoz avatar May 29 '19 09:05 fokoz