|
|
@ -33,9 +33,10 @@ class Lines { |
|
|
|
} |
|
|
|
|
|
|
|
module.exports = class Logger extends EventEmitter { |
|
|
|
constructor(host, { debug = false, quiet = false } = {}) { |
|
|
|
constructor(host, token, { debug = false, quiet = false } = {}) { |
|
|
|
super(); |
|
|
|
this.host = host; |
|
|
|
this.token = token; |
|
|
|
this.debug = debug; |
|
|
|
this.quiet = quiet; |
|
|
|
|
|
|
@ -44,6 +45,7 @@ module.exports = class Logger extends EventEmitter { |
|
|
|
|
|
|
|
this.socket = io(`https://io.now.sh/states?host=${host}&v=2`); |
|
|
|
this.socket.once('error', this.onSocketError.bind(this)); |
|
|
|
this.socket.on('auth', this.onAuth.bind(this)); |
|
|
|
this.socket.on('state', this.onState.bind(this)); |
|
|
|
this.socket.on('logs', this.onLog.bind(this)); |
|
|
|
this.socket.on('backend', this.onComplete.bind(this)); |
|
|
@ -54,6 +56,13 @@ module.exports = class Logger extends EventEmitter { |
|
|
|
this.buf = []; |
|
|
|
} |
|
|
|
|
|
|
|
onAuth(callback) { |
|
|
|
if (this.debug) { |
|
|
|
console.log('> [debug] authenticate'); |
|
|
|
} |
|
|
|
callback(this.token); |
|
|
|
} |
|
|
|
|
|
|
|
onState(state) { |
|
|
|
// Console.log(state)
|
|
|
|
if (!state.id) { |
|
|
|