How to give an answer to the message sender that the user is not online?

create messenger...
there is code which sends the message to the user and is triggered when the user is online
clicking on the book. send
$(document).on('click','#sendmsg',function(e){
 if($('.textarea[data='+$(this).attr('data')+']').val() !== ") {
 socket.emit('send', {usr:$(this).attr('data'), msg:$('.textarea[data='+$(this).attr('data')+']').val()});
 $('.messageBlock[data="'+$(this).attr('data')+'"]').append('<p class="msgTo">'+$('.textarea[data="'+$(this).attr('data')+'"]').val()+'</p>');
$('.textarea[data="'+$(this).attr('data')+'"]').val(");
}
 });


welcome to the server
socket.on('send', function (data) {
 if (io.sockets.connected[users_login_list[data.usr]]===undefined) {
//the question here is how to tell that USER2 user 1 is not in the network??
 socket.emit('sendmsg', {msg:'User is offline'});
 } else {
//it's all good
 io.sockets.connected[users_login_list[data.usr]].emit('sendmsg', {msg:data.msg, usr:socket.user_id});
 } 
 });


the output messages to a window users
socket.on('sendmsg', function (data) {
 if($('.messageBlock[data='+data.usr+']').length !== 0) { // here I check if dialog box is open in order to add messages
 $('.messageBlock[data='+data.usr+']').append('<p class="msgFrom">'+data.msg+'</p>');
}
 });
March 23rd 20 at 19:44
0 answer

Find more questions by tags Node.jsJavaScript