The provider must be registered inside start/app.js
file.
const providers = [
'@adonisjs/websocket/providers/WsProvider'
]
The next step is to open start/socket.js
and register websocket channels.
const Ws = use('Ws')
Ws.channel('chat', ({ socket }) => {
console.log('new socket joined %s', socket.id)
})
The middleware for websocket are kept in the start/wsKernel.js
file.
const Ws = use('Ws')
const globalMiddleware = []
const namedMiddleware = {}
Ws
.registerGlobal(globalMiddleware)
.registerNamed(namedMiddleware)