socket.emit('message_receive',serverMsg(`Hello ${socket.username}, welcome to ARNweb Chat. The following people are currently online: ${users.join(', ')}`));
}else{
socket.emit('message_receive',serverMsg(`Hello ${socket.username}, welcome to ARNweb Chat. You are the only one here at the moment`));
}
io.emit('message_receive',serverMsg(`${socket.username} has connected`));
users.push(socket.username);
});
// Send disconnect broadcast to all clients
socket.on('disconnect',function(){
io.emit('message_receive',serverMsg(`${socket.username} has disconnected`));
users.splice(users.indexOf(socket.username),1);
});
// Handle messages
socket.on('message_send',function(message){
// Build message data for clients
varmessage=striptags(message,'<br />');
if(message!==''){
message=md.render(message);
message=message.replace(/\r?\n/g,'<br />');
varmsg={
'username':socket.username,
'mailHash':socket.mailHash,
'message':message
}
// Send message to clients
io.emit('message_receive',msg);
}else{
socket.emit('message_receive',serverMsg(`Empty messages will not be sent.`));