probil / vue-socket.io-extended

:v::zap: Socket.io bindings for Vue.js and Vuex (inspired by Vue-Socket.io)
MIT License
628 stars 38 forks source link

How to connect multiple sockets in a single vuejs project? #532

Open allenshaji opened 3 years ago

allenshaji commented 3 years ago

import VueSocketIOExt from 'vue-socket.io-extended'; import { io } from 'socket.io-client';

const socket = io('http://localhost:3200/'); const socket1 = io('http://localhost:3100/');

Vue.use(VueSocketIOExt, socket); Vue.use(VueSocketIOExt, socket1);

I tried using the above code. But only only socket is working. Is it possible to connect both the sockets simultaneously. Thanks for the help in advance

jnt0r commented 3 years ago

I don't think this is possible yet. First, you should not be able to register the same Plugin twice. Currently, the plugin registers one global property $socket that directly controls the one socket. So you can only have one socket instance at a time managed by the plugin. For multiple sockets, it would need to register an array $sockets for example. So you could access your sockets like $sockets[1]. I could think about many use cases where this could be useful. Interesting idea you supposed 👍🏽

allenshaji commented 3 years ago

Thanks jnt0r. Is it possible to register array of sockets?

jnt0r commented 3 years ago

Not yet

EvEloBE commented 3 years ago

Would be interested in this as well. Built a performance monitoring app without realizing i could only connect 1 socket 😅