From 78bce76930b2c3583952916b37f4c45a7a0706be Mon Sep 17 00:00:00 2001 From: Ian Charlesworth Date: Tue, 12 May 2020 16:56:41 -0400 Subject: [PATCH] [FIX] mixin.js without namespaces Mixin behaviour was incorrect when namespaces were not being used. Now it should work as described in the documentation. --- src/mixin.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/mixin.js b/src/mixin.js index 93ae7fe..d723e37 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 (this.$vueSocketIo.useConnectionNamespace) { for (const namespace of Object.keys(this.$vueSocketIo)) { this.sockets[namespace] = { subscribe: (event, callback) => { @@ -19,8 +19,12 @@ export default { } } } else { - this.$vueSocketIo.emitter.addListener(event, callback, this); - this.$vueSocketIo.emitter.removeListener(event, this); + this.sockets.subscribe = (event, callback) => { + this.$vueSocketIo.emitter.addListener(event, callback, this); + }; + this.sockets.unsubscribe = (event) => { + this.$vueSocketIo.emitter.removeListener(event, this); + }; } }, @@ -31,7 +35,7 @@ export default { if(this.$options.sockets){ - if (typeof this.$vueSocketIo === 'object') { + if (this.$vueSocketIo.useConnectionNamespace) { for (const namespace of Object.keys(this.$vueSocketIo)) { if (this.$options.sockets[namespace]) { Object.keys(this.$options.sockets[namespace]).forEach(event => { @@ -63,7 +67,7 @@ export default { if(this.$options.sockets){ - if (typeof this.$vueSocketIo === 'object') { + if (this.$vueSocketIo.useConnectionNamespace) { for (const namespace of Object.keys(this.$vueSocketIo)) { if (this.$options.sockets[namespace]) { Object.keys(this.$options.sockets[namespace]).forEach(event => { @@ -85,4 +89,4 @@ export default { } -} \ No newline at end of file +}