UNPKG

gb_utils

Version:
25 lines (18 loc) 660 B
// Dependencies Import const socketIO = require("socket.io"); const io = socketIO(app); //Utils Import const constantUtils = require("gb_utils/constantUtils"); // Create a namespace called '/chat' const chatNamespace = io.of("/chat"); const chatIds = []; chatNamespace.on("connection", (socket) => { console.log("A user connected to the chat namespace"); // Handle custom events for the chat namespace socket.on("chat message", (msg) => { chatNamespace.emit("chat message", msg); // Broadcast the message to all clients in the chat namespace }); socket.on("disconnect", () => { console.log("User disconnected from the chat namespace"); }); });