mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-01-17 12:52:22 +01:00
35 lines
1.1 KiB
JavaScript
35 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(),
|
|
username: socket.request.user.username
|
|
});
|
|
});
|
|
};
|