Namespaces
Remember how we set up our original websocket
server? For that take a look at the following code:
// [snip] // Connect the websocket handler to our server var websocket = require('socket.io')(server); // Create a handler for incoming websocket connections websocket.on('UserConnectedEvent', function (socket) { console.log("New user connected"); // Tell others a new user connected socket.broadcast.emit('UserConnectedEvent', null); // Bind event handler for incoming messages socket.on('MessageSentEvent', function (chatData) { console.log('Received new chat message'); // By using the 'broadcast' connector, we will // send the message to everyone except the sender. socket.broadcast.emit('MessageReceivedEvent', chatData); }); });
Here, we simply used the main socket.io
instance in order to directly register socket connections and their respective callbacks. However, looking a...