Namespaces - ArtFXDev/silex-socket-service GitHub Wiki
For explanation about namespace usage for Socket.io see: Socket.io/namespaces
In simple way : Namespaces in like a route for your request, to sort them.
Files Structure
📦namespaces
┣ 📂dcc
┃ ┣ 📜action.js
┃ ┗ 📜dcc.js
┗ 📂ui
┃ ┣ 📜action.js
┃ ┗ 📜ui.js
To add a new namespaces your have create a file .js under the namespaces directory of the project, in the files structure example we have 4 namespaces:
- /dcc
- /dcc/action
- /ui
- /ui/action
Code example
const ui = (io) => {
return io.of("/ui")
}
module.exports = ui
this will simply return the output object of io.of("/ui")
Usage:
// listeners/dcc.js
/** NAMEPSACE */
const dccNamespace = require("../namespaces/dcc/dcc") <== Import Here
const dccActionNamespace = require("../namespaces/dcc/action")
module.exports = function (io) {
dccNamespace(io).on("connection", function (socket) { <== Use Here
dccRoomJoin(socket)
...
side client for Namespace connection:
clientDcc = new Client(http://localhost:${port}/dcc)