mirror of
https://github.com/MetinSeylan/Vue-Socket.io.git
synced 2025-04-16 15:21:28 +02:00
Fix multiple namespaces implementation
This commit is contained in:
parent
640dfc044c
commit
7dc5367cdc
3 changed files with 26 additions and 14 deletions
8
dist/vue-socketio.js
vendored
8
dist/vue-socketio.js
vendored
File diff suppressed because one or more lines are too long
|
@ -33,6 +33,13 @@ export default class VueSocketIO {
|
|||
const namespace = this.namespaceName || this.io.nsp.replace("/", "");
|
||||
|
||||
if (this.useConnectionNamespace) {
|
||||
// update list of namespaces
|
||||
if (Array.isArray(Vue.prototype.VueSocketIONamepaces)) {
|
||||
Vue.prototype.VueSocketIONamepaces.push(namespace);
|
||||
} else {
|
||||
Vue.prototype.VueSocketIONamepaces = [namespace];
|
||||
}
|
||||
|
||||
if (typeof Vue.prototype.$socket === "object") {
|
||||
Vue.prototype.$socket = {
|
||||
...Vue.prototype.$socket,
|
||||
|
|
25
src/mixin.js
25
src/mixin.js
|
@ -7,8 +7,8 @@ export default {
|
|||
|
||||
if(!this.sockets) this.sockets = {};
|
||||
|
||||
if (typeof this.$vueSocketIo === 'object') {
|
||||
for (const namespace of Object.keys(this.$vueSocketIo)) {
|
||||
if (this.VueSocketIONamespaces && this.VueSocketIONamespaces.length) {
|
||||
for (const namespace of this.VueSocketIONamespaces) {
|
||||
this.sockets[namespace] = {
|
||||
subscribe: (event, callback) => {
|
||||
this.$vueSocketIo[namespace].emitter.addListener(event, callback, this);
|
||||
|
@ -19,8 +19,14 @@ 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);
|
||||
},
|
||||
unsubscribe: (event) => {
|
||||
this.$vueSocketIo.emitter.removeListener(event, this);
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -31,8 +37,8 @@ export default {
|
|||
|
||||
if(this.$options.sockets){
|
||||
|
||||
if (typeof this.$vueSocketIo === 'object') {
|
||||
for (const namespace of Object.keys(this.$vueSocketIo)) {
|
||||
if ( this.VueSocketIONamespaces && this.VueSocketIONamespaces.length ) {
|
||||
for (const namespace of this.VueSocketIONamespaces) {
|
||||
if (this.$options.sockets[namespace]) {
|
||||
Object.keys(this.$options.sockets[namespace]).forEach(event => {
|
||||
|
||||
|
@ -62,9 +68,8 @@ export default {
|
|||
beforeDestroy(){
|
||||
|
||||
if(this.$options.sockets){
|
||||
|
||||
if (typeof this.$vueSocketIo === 'object') {
|
||||
for (const namespace of Object.keys(this.$vueSocketIo)) {
|
||||
if (this.VueSocketIONamespaces && this.VueSocketIONamespaces.length) {
|
||||
for (const namespace of this.VueSocketIONamespaces) {
|
||||
if (this.$options.sockets[namespace]) {
|
||||
Object.keys(this.$options.sockets[namespace]).forEach(event => {
|
||||
|
||||
|
@ -85,4 +90,4 @@ export default {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue