Build a WebSocket chat
A WebSocket endpoint is declared with ROUTE('SOCKET /path/', fn). Inside the handler this is the WebSocket controller: use self.on('message', ...) to receive data and self.send(...) to broadcast to all connected clients. client.send(...) answers only the sender. Objects are sent and received as JSON by default.
exports.install = function() {
ROUTE('SOCKET /chat/', socket);
};
function socket() {
var self = this;
self.on('message', function(client, message) {
self.send({ type: 'message', text: message.text });
});
}