Pass Parameters on Subsribing Channels

Hi I want to pass parameters on subscribing channels

i did it like this
‘const chat = ws.subscribe(channel, {options: ‘dasda’})’

but nothing happens, any idea how to implement this thing, thanks

1 Like

Why not simply emit the event after subscribing to the channel? There is no API to pass options to the subscription

hi thanks for replying, with that, how can middlewares can be used in websocket? as i what i observed the middleware for websocket only happen once it is subscribed, what i am planning is for every web socket event, a middleware will be triggered, is that possible sir ?

1 Like

Can u share what exactly you trying to do?

// in my chat.js
const chat = ws.subscribe(channel, {options: ‘dasda’})

//in my middleware/Websocket.js

‘use strict’

class Websocket {
async wsHandle ({request}, next) {
// call next to advance the request
// console.log(request.body)
// throw new Error(‘dsada’)
await next()

module.exports = Websocket
// my middleware setup in wsKernel.js
const globalMiddleware = [


Named middleware
Named middleware are defined as key/value pairs. Later you can use the
keys to run selected middleware on a given channel.
// define
auth: ‘Adonis/Middleware/Auth’
// use‘chat’, ‘ChatController’).middleware([‘auth’])

const namedMiddleware = {
ws: ‘App/Middleware/Websocket’,


// my routes in middleware

const Ws = use(‘Ws’)‘chat’, ‘ChatController’).middleware([‘ws’])‘chat:*’, ‘ChatController’).middleware([‘ws’])

1 Like

I am trying to get the options value on, so that i can check then throw error for some reasons

I am trying to understand what you are trying to do conceptually? Why u need data during subscription?

If you can share what you are trying to achieve conceptually, I maybe to help

okok maybe ill finish setuping those things, ill upload it in github,

here i want to get the options value from public/chat.js
i want to get the data from middleware websocket set on

here’s my chat.js

1 Like

or maybe you can give some advice how to handle websocket authentications using jwt tokens

1 Like

Great info thanks for sharing this stuff! :grinning: