Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Socket.io: Using JS functions

Im creating a chat application and I'm trying to encrypt messages send. I have a function encrypt(arg1,arg2), it takes two arguments and returns an encrypted text. Here I'm trying to emit an object with the function and the handle on the client side

$('#send').on('click', function(){
  socket.emit('chat',{                
    message: encrypt(message.value,key1),              
    handle: handle.value,
  });

here is the server side

  socket.on('chat',function(data){
    console.log(data.message);
    socket.username = data.handle;

    io.sockets.emit('chat', data); //data being sent back to all sockets
  });

I tried this and every message sent is blank. What is the correct way for doing this? Im using JavaScript,node.js,express

Comments