[Vuejs]-Display message 'user typing…' to everyone, including sender, if I am typing a message, VUE JS and socket.io

1👍

Socket.io gives you lots of options to send messages across the board. What I always found very helpful is the Emit cheatsheet from the official docs (https://socket.io/docs/emit-cheatsheet/).

Here are some of the methods on how to broadcast messages to all clients including sender.

io.on('connect', onConnect);

function onConnect(socket) {

  // sending to all clients in 'chat' room, including sender
  io.in('chat').emit('typing', 'User xy is typing');

  // sending to all clients in namespace 'chatNamespace', including sender
  io.of('chatNamespace').emit('typing', 'User xy is typing');

  // sending to a specific room in a specific namespace, including sender
  io.of('chatNamespace').to('chat').emit('typing', 'User xy is typing');

}

Now this of course are just example methods. You would need to wrap this into your own business logic and probably register some socket event listeners to get this going.

Leave a comment