Vue-Socket.io icon indicating copy to clipboard operation
Vue-Socket.io copied to clipboard

Socket message listener receives all values on first parameter

Open stefa168 opened this issue 4 years ago • 2 comments

I have written a small component that listens to an event. This event is expected to receive two values:

sockets: {
  my_listener(firstObject, secondObject) {
    console.log(firstObject);
    console.log(secondObject);
  }
}

When the listener is triggered, firstObject receives an object that contains both firstObject and secondObject, which isn't what I expect to happen. secondObject instead is undefined.

From the socket.io client documentation it is sufficently clear that multiple parameters can be expected and should be bound to different function parameters.

This problem is driving me crazy; I don't know if this is an error of the library or if I am using it in the wrong way. Is there any one more experienced that could clarify this problem for me?

stefa168 avatar Dec 15 '20 17:12 stefa168

Would it have something to do with this library still using socket.io v2.x instead of v3.x?

thely avatar Apr 04 '21 16:04 thely

what you should do is:

    sockets: {
      my_listener({firstObject, secondObject}) {
        console.log(firstObject);
        console.log(secondObject);
      }
    }

farena avatar Dec 20 '21 12:12 farena