This commit is contained in:
Phantas Weng 2020-12-15 13:13:10 +08:00 committed by GitHub
commit b608d10c9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 9 deletions

View file

@ -87,6 +87,7 @@ new Vue({
**Parameters**|**Type's**|**Default**|**Required**|**Description**
-----|-----|-----|-----|-----
debug|Boolean|`false`|Optional|Enable logging for debug
darkMode|Boolean|prefers-color-scheme|Optional|Enable console dark mode for debug
connection|String/Socket.io-client|`null`|Required|Websocket server url or socket.io-client instance
vuex.store|Vuex|`null`|Optional|Vuex store instance
vuex.actionPrefix|String|`null`|Optional|Prefix for emitting server side vuex actions

10
dist/vue-socketio.js vendored

File diff suppressed because one or more lines are too long

View file

@ -11,11 +11,13 @@ export default class VueSocketIO {
* @param io
* @param vuex
* @param debug
* @param darkMode
* @param options
*/
constructor({connection, vuex, debug, options}){
constructor({connection, vuex, debug, darkMode, options}){
Logger.debug = debug;
Logger.darkMode = darkMode || window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
this.io = this.connect(connection, options);
this.emitter = new Emitter(vuex);
this.listener = new Listener(this.io, this.emitter);

View file

@ -4,13 +4,19 @@
export default new class VueSocketIOLogger {
constructor() {
this.darkMode = false;
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) {
if (this.darkMode) {
window.console.info(this.prefix+`%c${text}`, 'color: #A9D341; font-weight: 600', 'color: #F7AC15', data);
} else {
window.console.info(this.prefix+`%c${text}`, 'color: blue; font-weight: 600', 'color: #333333', data);
}
}
}
@ -28,8 +34,14 @@ export default new class VueSocketIOLogger {
event(text, data = ''){
if(this.debug) window.console.info(this.prefix+`%c${text}`, 'color: blue; font-weight: 600', 'color: #333333', data);
if(this.debug) {
if (this.darkMode) {
window.console.info(this.prefix+`%c${text}`, 'color: #A9D341; font-weight: 600', 'color: #F7AC15', data);
} else {
window.console.info(this.prefix+`%c${text}`, 'color: blue; font-weight: 600', 'color: #333333', data);
}
}
}
}
}