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
|
||||
*/
|
||||
export default new class VueSocketIOLogger {
|
||||
|
||||
export default new (class VueSocketIOLogger {
|
||||
constructor() {
|
||||
this.debug = false;
|
||||
this.prefix = '%cVue-Socket.io: ';
|
||||
}
|
||||
|
||||
info(text, data = '') {
|
||||
|
||||
if(this.debug) window.console.info(this.prefix+`%c${text}`, 'color: blue; font-weight: 600', 'color: #333333', data);
|
||||
|
||||
if (this.debug)
|
||||
window.console.info(this.prefix + `%c${text}`, 'color: blue; font-weight: 600', 'color: #333333', data);
|
||||
}
|
||||
|
||||
error() {
|
||||
|
||||
if(this.debug) window.console.error(this.prefix, ...arguments);
|
||||
|
||||
if (this.debug) window.console.error(this.prefix, ...arguments);
|
||||
}
|
||||
|
||||
warn() {
|
||||
|
||||
if(this.debug) window.console.warn(this.prefix, ...arguments);
|
||||
|
||||
if (this.debug) window.console.warn(this.prefix, ...arguments);
|
||||
}
|
||||
|
||||
event(text, data = ''){
|
||||
|
||||
if(this.debug) window.console.info(this.prefix+`%c${text}`, 'color: blue; font-weight: 600', 'color: #333333', data);
|
||||
|
||||
event(text, data = '') {
|
||||
if (this.debug)
|
||||
window.console.info(this.prefix + `%c${text}`, 'color: blue; font-weight: 600', 'color: #333333', data);
|
||||
}
|
||||
|
||||
}
|
||||
})();
|
||||
|
@ -1,88 +1,40 @@
|
||||
export default {
|
||||
|
||||
/**
|
||||
* Assign runtime callbacks
|
||||
*/
|
||||
beforeCreate(){
|
||||
|
||||
if(!this.sockets) this.sockets = {};
|
||||
beforeCreate() {
|
||||
if (!this.sockets) this.sockets = {};
|
||||
|
||||
if (typeof this.$vueSocketIo === 'object') {
|
||||
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.sockets.subscribe = (event, callback) => {
|
||||
this.$vueSocketIo.emitter.addListener(event, callback, this);
|
||||
};
|
||||
|
||||
this.sockets.unsubscribe = event => {
|
||||
this.$vueSocketIo.emitter.removeListener(event, this);
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Register all socket events
|
||||
*/
|
||||
mounted(){
|
||||
|
||||
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 {
|
||||
mounted() {
|
||||
if (this.$options.sockets) {
|
||||
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);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* unsubscribe when component unmounting
|
||||
*/
|
||||
beforeDestroy(){
|
||||
|
||||
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 {
|
||||
beforeDestroy() {
|
||||
if (this.$options.sockets) {
|
||||
Object.keys(this.$options.sockets).forEach(event => {
|
||||
|
||||
this.$vueSocketIo.emitter.removeListener(event, this);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue