add: handle more than one namespace

This commit is contained in:
Leonardo Dominguez 2019-04-13 19:32:19 -04:00
parent ee1e7ed1ee
commit a715ee1ae7

View file

@ -13,10 +13,11 @@ export default class VueSocketIO {
* @param debug * @param debug
* @param options * @param options
*/ */
constructor({connection, vuex, debug, options}){ constructor({connection, vuex, debug, options, useConnectionNamespace}){
Logger.debug = debug; Logger.debug = debug;
this.io = this.connect(connection, options); this.io = this.connect(connection, options);
this.useConnectionNamespace = useConnectionNamespace;
this.emitter = new Emitter(vuex); this.emitter = new Emitter(vuex);
this.listener = new Listener(this.io, this.emitter); this.listener = new Listener(this.io, this.emitter);
@ -28,7 +29,23 @@ export default class VueSocketIO {
*/ */
install(Vue){ install(Vue){
const namespace = this.io.nsp.replace("/", "");
if (this.useConnectionNamespace) {
if (typeof Vue.prototype.$socket === "object") {
Vue.prototype.$socket = {
...Vue.prototype.$socket,
[namespace]: this.io
};
} else {
Vue.prototype.$socket = {
[namespace]: this.io
};
}
} else {
Vue.prototype.$socket = this.io; Vue.prototype.$socket = this.io;
}
Vue.prototype.$vueSocketIo = this; Vue.prototype.$vueSocketIo = this;
Vue.mixin(Mixin); Vue.mixin(Mixin);