diff --git a/src/puppet-web-injectio.js b/src/puppet-web-injectio.js index 2969783e7e545c90095b9deae38bca8cc1c20081..7a9c901ed65e7263a9754af7ffc8e486778a2efc 100644 --- a/src/puppet-web-injectio.js +++ b/src/puppet-web-injectio.js @@ -340,8 +340,8 @@ return (function(port) { function checkScan() { clog('checkScan()') if (isLogin()) { - log('checkScan() - already login, no more check, but I will emit a login event') - login('checkScan found already login') + log('checkScan() - already login, no more check, and return(only)') //but I will emit a login event') + // login('checkScan found already login') return } if (!Wechaty.glue.loginScope) { @@ -352,9 +352,9 @@ return (function(port) { // loginScope.code: // 0: 显示二维码 + // 408: 未确认(显示二维码后30秒触发) // 201: 扫描,未确认 // 200: 登录成功 - // 408: 未确认 var code = +Wechaty.glue.loginScope.code var url = Wechaty.glue.loginScope.qrcodeUrl if (url && code !== Wechaty.vars.scanCode) { diff --git a/src/wechaty.js b/src/wechaty.js index bb27c6ecdf351a9c982e5d04cf9668d799092d77..b45c1c5a0a40e1232d716716e79232ab85eeb30f 100644 --- a/src/wechaty.js +++ b/src/wechaty.js @@ -64,15 +64,13 @@ class Wechaty extends EventEmitter { log.verbose('Wechaty', 'port: %d', this.port) } - yield this.initIo() + this.io = yield this.initIo() .catch(e => { // fail safe log.error('WechatyIo', 'initIo failed: %s', e.message) this.emit('error', e) }) - yield this.initPuppet() - yield this.initEventHook() - yield this.puppet.init() + this.puppet = yield this.initPuppet() this.inited = true return this // for chaining @@ -92,7 +90,7 @@ class Wechaty extends EventEmitter { } const WechatyIo = require('./wechaty-io') - const io = this.io = new WechatyIo({ + const io = new WechatyIo({ wechaty: this , token: this.token , endpoint: this.endpoint @@ -106,9 +104,10 @@ class Wechaty extends EventEmitter { } initPuppet() { + let puppet switch (this.type) { case 'web': - this.puppet = new PuppetWeb( { + puppet = new PuppetWeb( { head: this.head , port: this.port , profile: this.profile @@ -117,10 +116,7 @@ class Wechaty extends EventEmitter { default: throw new Error('Puppet unsupport(yet): ' + this.type) } - return Promise.resolve(this.puppet) - } - initEventHook() { ;[ 'scan' , 'message' @@ -129,26 +125,10 @@ class Wechaty extends EventEmitter { , 'error' , 'heartbeat' ].map(e => { - this.puppet.on(e, data => { + puppet.on(e, data => { this.emit(e, data) }) }) - // this.puppet.on('scan', data => { - // this.emit('scan', data) // Scan QRCode - // }) - // this.puppet.on('message', data => { - // this.emit('message', data) // Receive Message - // }) - // this.puppet.on('login', data => { - // this.emit('login', data) - // }) - // this.puppet.on('logout', data => { - // this.emit('logout', data) - // }) - // this.puppet.on('error', data => { - // this.emit('error', data) - // }) - /** * TODO: support more events: * 2. send @@ -157,7 +137,7 @@ class Wechaty extends EventEmitter { * 5. ... */ - return Promise.resolve() + return puppet.init() } quit() {