Answer the question
In order to leave comments, you need to log in
How to get socket in joinRoom (adonis.js) method?
I need to get the user's socket in the joinRoom method. I have already tried everything: I removed the generators, and launched the constructor in the method (nonsense, but I decided to try it), I already took the code from the documentation, but it still does not work. Guys who worked with this? How can I get at least a socket, preferably all properties defined in the constructor.
Code App/Ws/Controllers/ChatController.js
'use strict'
class ChatController {
constructor (socket) {
this.socket = socket
}
* leaveRoom (room) {
// Do cleanup if required
}
* joinRoom (room) {
this.room = room
this.socket.emit('server:message', {message: 'New connection!'})
}
}
module.exports = ChatController
'use strict'
const Ws = use('Ws')
Ws.channel('chat', 'ChatController')
.middleware('auth')
Answer the question
In order to leave comments, you need to log in
Found the answer by myself
* joinRoom (room, payload, socket) {
socket.emit('server:message', {message: 'New connection!'})
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question