[Vuejs]-How to connect node server with vue socket

1👍

To use (ack)nowledgements, you have to fire the function.

Client

socket.on('connect', function() {
  socket.emit("joinChat", {
    chatId: this.chatIdd,
    userId: this.userIdd
  }, function(confirmation) {
    //alert('Work');
    console.log(confirmation); // From server
  });
}.bind(this));

Server

socket.on('joinChat', (msg, ack) => {
  if (msg.chatId) {
    socket.join(msg.chatId);
    if (typeof ack === 'function') ack('From server')
  }
});

Leave a comment