Files
meanTorrent/modules/chat/server/sockets/chat.server.socket.config.js
9ac345a5509a 24b6e3a3cb fix(chat): fixed profile image not displaying properly on disconnect
hotfix to make sure that the profileImageURL is sent on disconnect
2016-08-06 23:04:57 -04:00

36 lines
1.1 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(),
profileImageURL: socket.request.user.profileImageURL,
username: socket.request.user.username
});
});
};