From 1c55f1a4e39cf54b72b182647c3c6088120aa892 Mon Sep 17 00:00:00 2001 From: David Vezzani Date: Mon, 27 Jul 2020 12:08:28 -0600 Subject: [PATCH] allow default namespace to still be used --- src/index.js | 2 ++ src/mixin.js | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index cea8ef0..a53d1a7 100644 --- a/src/index.js +++ b/src/index.js @@ -51,6 +51,7 @@ export default class VueSocketIO { Vue.prototype.$vueSocketIo = this; } + Vue.prototype.$useConnectionNamespace = this.useConnectionNamespace Vue.mixin(Mixin); Logger.info('Vue-Socket.io plugin enabled'); @@ -75,3 +76,4 @@ export default class VueSocketIO { } } } + diff --git a/src/mixin.js b/src/mixin.js index 93ae7fe..ef48020 100644 --- a/src/mixin.js +++ b/src/mixin.js @@ -7,7 +7,7 @@ export default { if(!this.sockets) this.sockets = {}; - if (typeof this.$vueSocketIo === 'object') { + if (typeof this.$vueSocketIo === 'object' && this.$useConnectionNamespace) { for (const namespace of Object.keys(this.$vueSocketIo)) { this.sockets[namespace] = { subscribe: (event, callback) => { @@ -31,7 +31,7 @@ export default { if(this.$options.sockets){ - if (typeof this.$vueSocketIo === 'object') { + if (typeof this.$vueSocketIo === 'object' && this.$useConnectionNamespace) { for (const namespace of Object.keys(this.$vueSocketIo)) { if (this.$options.sockets[namespace]) { Object.keys(this.$options.sockets[namespace]).forEach(event => { @@ -45,7 +45,6 @@ export default { } } else { Object.keys(this.$options.sockets).forEach(event => { - if(event !== 'subscribe' && event !== 'unsubscribe') { this.$vueSocketIo.emitter.addListener(event, this.$options.sockets[event], this); } @@ -63,7 +62,7 @@ export default { if(this.$options.sockets){ - if (typeof this.$vueSocketIo === 'object') { + if (typeof this.$vueSocketIo === 'object' && this.$useConnectionNamespace) { for (const namespace of Object.keys(this.$vueSocketIo)) { if (this.$options.sockets[namespace]) { Object.keys(this.$options.sockets[namespace]).forEach(event => { @@ -85,4 +84,5 @@ export default { } -} \ No newline at end of file +} +