# Event Methods
class ChatController {
onMessage () {
// same as: socket.on('message')
}
onClose () {
// same as: socket.on('close')
}
onError () {
// same as: socket.on('error')
}
}
Note: Event methods must be prefixed with the on keyword.
To keep things simple we won’t store user messages, just deliver them. Open the Routes/sockets.js file and paste the following code:
const Ws = require("@socket.io");
Ws.channel("chat", "chatController");
We can also bind a closure to the Ws.channel method, but having a dedicated controller is the recommended practice.