Rolled back changes from 8988085bef
due to numerous breaking changes.
parent
bcd466a22e
commit
977f56102b
File diff suppressed because one or more lines are too long
@ -1,35 +1,27 @@
|
|||||||
/**
|
/**
|
||||||
* shitty logger class
|
* shitty logger class
|
||||||
*/
|
*/
|
||||||
export default new class VueSocketIOLogger {
|
export default new (class VueSocketIOLogger {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.debug = false;
|
this.debug = false;
|
||||||
this.prefix = '%cVue-Socket.io: ';
|
this.prefix = '%cVue-Socket.io: ';
|
||||||
}
|
}
|
||||||
|
|
||||||
info(text, data = '') {
|
info(text, data = '') {
|
||||||
|
if (this.debug)
|
||||||
if(this.debug) window.console.info(this.prefix+`%c${text}`, 'color: blue; font-weight: 600', 'color: #333333', data);
|
window.console.info(this.prefix + `%c${text}`, 'color: blue; font-weight: 600', 'color: #333333', data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error() {
|
error() {
|
||||||
|
|
||||||
if (this.debug) window.console.error(this.prefix, ...arguments);
|
if (this.debug) window.console.error(this.prefix, ...arguments);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
warn() {
|
warn() {
|
||||||
|
|
||||||
if (this.debug) window.console.warn(this.prefix, ...arguments);
|
if (this.debug) window.console.warn(this.prefix, ...arguments);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
event(text, data = '') {
|
event(text, data = '') {
|
||||||
|
if (this.debug)
|
||||||
if(this.debug) window.console.info(this.prefix+`%c${text}`, 'color: blue; font-weight: 600', 'color: #333333', data);
|
window.console.info(this.prefix + `%c${text}`, 'color: blue; font-weight: 600', 'color: #333333', data);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
})();
|
||||||
|
@ -1,88 +1,40 @@
|
|||||||
export default {
|
export default {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign runtime callbacks
|
* Assign runtime callbacks
|
||||||
*/
|
*/
|
||||||
beforeCreate() {
|
beforeCreate() {
|
||||||
|
|
||||||
if (!this.sockets) this.sockets = {};
|
if (!this.sockets) this.sockets = {};
|
||||||
|
|
||||||
if (typeof this.$vueSocketIo === 'object') {
|
this.sockets.subscribe = (event, callback) => {
|
||||||
for (const namespace of Object.keys(this.$vueSocketIo)) {
|
|
||||||
this.sockets[namespace] = {
|
|
||||||
subscribe: (event, callback) => {
|
|
||||||
this.$vueSocketIo[namespace].emitter.addListener(event, callback, this);
|
|
||||||
},
|
|
||||||
unsubscribe: (event) => {
|
|
||||||
this.$vueSocketIo[namespace].emitter.removeListener(event, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.$vueSocketIo.emitter.addListener(event, callback, this);
|
this.$vueSocketIo.emitter.addListener(event, callback, this);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.sockets.unsubscribe = event => {
|
||||||
this.$vueSocketIo.emitter.removeListener(event, this);
|
this.$vueSocketIo.emitter.removeListener(event, this);
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register all socket events
|
* Register all socket events
|
||||||
*/
|
*/
|
||||||
mounted() {
|
mounted() {
|
||||||
|
|
||||||
if (this.$options.sockets) {
|
if (this.$options.sockets) {
|
||||||
|
|
||||||
if (typeof this.$vueSocketIo === 'object') {
|
|
||||||
for (const namespace of Object.keys(this.$vueSocketIo)) {
|
|
||||||
if (this.$options.sockets[namespace]) {
|
|
||||||
Object.keys(this.$options.sockets[namespace]).forEach(event => {
|
|
||||||
|
|
||||||
if(event !== 'subscribe' && event !== 'unsubscribe') {
|
|
||||||
this.$vueSocketIo[namespace].emitter.addListener(event, this.$options.sockets[namespace][event], this);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Object.keys(this.$options.sockets).forEach(event => {
|
Object.keys(this.$options.sockets).forEach(event => {
|
||||||
|
|
||||||
if (event !== 'subscribe' && event !== 'unsubscribe') {
|
if (event !== 'subscribe' && event !== 'unsubscribe') {
|
||||||
this.$vueSocketIo.emitter.addListener(event, this.$options.sockets[event], this);
|
this.$vueSocketIo.emitter.addListener(event, this.$options.sockets[event], this);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unsubscribe when component unmounting
|
* unsubscribe when component unmounting
|
||||||
*/
|
*/
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
|
|
||||||
if (this.$options.sockets) {
|
if (this.$options.sockets) {
|
||||||
|
|
||||||
if (typeof this.$vueSocketIo === 'object') {
|
|
||||||
for (const namespace of Object.keys(this.$vueSocketIo)) {
|
|
||||||
if (this.$options.sockets[namespace]) {
|
|
||||||
Object.keys(this.$options.sockets[namespace]).forEach(event => {
|
|
||||||
|
|
||||||
this.$vueSocketIo[namespace].emitter.removeListener(event, this);
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Object.keys(this.$options.sockets).forEach(event => {
|
Object.keys(this.$options.sockets).forEach(event => {
|
||||||
|
|
||||||
this.$vueSocketIo.emitter.removeListener(event, this);
|
this.$vueSocketIo.emitter.removeListener(event, this);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue