Files
meanTorrent/modules/chat/server/sockets/chat.server.socket.config.js
Ryan Hutchison ef3a3f9548 formatting reboot (space-2 and consistency)
JSCS fixes

update editorconfig
2015-07-31 10:04:02 -04:00

35 lines
1.0 KiB
JavaScript

'use strict';
// Create the chat configuration
module.exports = function (io, socket) {
// Emit the status event when a new socket client is connected
io.emit('chatMessage', {
type: 'status',
text: 'Is now connected',
created: Date.now(),
profileImageURL: socket.request.user.profileImageURL,
username: socket.request.user.username
});
// Send a chat messages to all connected sockets when a message is received
socket.on('chatMessage', function (message) {
message.type = 'message';
message.created = Date.now();
message.profileImageURL = socket.request.user.profileImageURL;
message.username = socket.request.user.username;
// Emit the 'chatMessage' event
io.emit('chatMessage', message);
});
// Emit the status event when a socket client is disconnected
socket.on('disconnect', function () {
io.emit('chatMessage', {
type: 'status',
text: 'disconnected',
created: Date.now(),
username: socket.request.user.username
});
});
};