-
Notifications
You must be signed in to change notification settings - Fork 1
Listeners
OlivierArgentieri edited this page Sep 24, 2021
·
3 revisions
They are automatically execute from index.js. So, if you want to add a new listeners, you just have to create a new.js files under listener directory
📦listeners
┣ 📜dcc.js
┣ 📜index.js
┗ 📜ui.js
module.exports = function (io) { // <== the code start here
myNamespace(io).on("connection", function (socket) { // <== dccNamespace(io)... will be executed by index.js
myevent(socket) // On "connection"event, we execute on socket object all the bellow events
mySecondEvent(socket, io)
myLastEvent(socket, io)
})Second example with a real usage :
/** NAMEPSACE */
const dccNamespace = require("../namespaces/dcc/dcc")
const dccActionNamespace = require("../namespaces/dcc/action")
/** EVENTS */
const initializationEvent = require("../events/dcc/initialization")
const queryEvent = require("../events/dcc/actions/query")
const requestEvent = require("../events/dcc/actions/request")
const updateEvent = require("../events/dcc/actions/update")
const diconnectEvent = require("../events/dcc/disconnect")
/** ROOMS */
const { dccRoomJoin } = require("../rooms/dcc")
module.exports = function (io) {
dccNamespace(io).on("connection", function (socket) {
dccRoomJoin(socket)
initializationEvent(socket, io)
diconnectEvent(socket, io)
})
dccActionNamespace(io).on("connection", function (socket) {
queryEvent(socket, io)
requestEvent(socket, io)
updateEvent(socket, io)
})
}📚 Doc
🔧 Introduction:
🚀 Development: