Search code examples
vue.jswebsocketvuexvue-socket.io

Connection to two websockets (via vue-socket.io) in one vue/vuex app


so I have a web application using vue with vuex which has a connection to a websocket via vue-socket-io like this:

Vue.use(new VueSocketIO({
  debug: true,
  connection: SocketIO('http://192.168.0.31:5000'),
  vuex: {
    store,
    actionPrefix: 'SOCKET_',
  },
}));

new Vue({
  router,
  store,
  vuetify,
  render: (h) => h(App),
}).$mount('#app');

My problem is, that besides this websocket, I now need to communicate with yet another server also via websocket. How can I have two websockets with different servers at the same time?

I found a similar question here but I am not sure, if the answer to "just not use vue-socket-io because it won't work" is correct or if there is a way to accomplish this? In this question the user tried to use two stores which I also don't know if it is a food idea?

Thanks for any hint on how I can solve this problem!


Solution

  • Apparently with vuex and the way shown above only one websocket can be connected like this. The only way to connect another on was to locally do it in the components.