MetinSeylan / Vue-Socket.io

😻 Socket.io implementation for Vuejs and Vuex
https://metin.sh
MIT License
3.95k stars 499 forks source link

Socket message listener receives all values on first parameter #298

Open stefa168 opened 3 years ago

stefa168 commented 3 years ago

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?

thely commented 3 years ago

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

farena commented 2 years ago

what you should do is:

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