提交 a75f560f 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

code clean

上级 6f222d08
...@@ -340,8 +340,8 @@ return (function(port) { ...@@ -340,8 +340,8 @@ return (function(port) {
function checkScan() { function checkScan() {
clog('checkScan()') clog('checkScan()')
if (isLogin()) { if (isLogin()) {
log('checkScan() - already login, no more check, but I will emit a login event') log('checkScan() - already login, no more check, and return(only)') //but I will emit a login event')
login('checkScan found already login') // login('checkScan found already login')
return return
} }
if (!Wechaty.glue.loginScope) { if (!Wechaty.glue.loginScope) {
...@@ -352,9 +352,9 @@ return (function(port) { ...@@ -352,9 +352,9 @@ return (function(port) {
// loginScope.code: // loginScope.code:
// 0: 显示二维码 // 0: 显示二维码
// 408: 未确认(显示二维码后30秒触发)
// 201: 扫描,未确认 // 201: 扫描,未确认
// 200: 登录成功 // 200: 登录成功
// 408: 未确认
var code = +Wechaty.glue.loginScope.code var code = +Wechaty.glue.loginScope.code
var url = Wechaty.glue.loginScope.qrcodeUrl var url = Wechaty.glue.loginScope.qrcodeUrl
if (url && code !== Wechaty.vars.scanCode) { if (url && code !== Wechaty.vars.scanCode) {
......
...@@ -64,15 +64,13 @@ class Wechaty extends EventEmitter { ...@@ -64,15 +64,13 @@ class Wechaty extends EventEmitter {
log.verbose('Wechaty', 'port: %d', this.port) log.verbose('Wechaty', 'port: %d', this.port)
} }
yield this.initIo() this.io = yield this.initIo()
.catch(e => { // fail safe .catch(e => { // fail safe
log.error('WechatyIo', 'initIo failed: %s', e.message) log.error('WechatyIo', 'initIo failed: %s', e.message)
this.emit('error', e) this.emit('error', e)
}) })
yield this.initPuppet() this.puppet = yield this.initPuppet()
yield this.initEventHook()
yield this.puppet.init()
this.inited = true this.inited = true
return this // for chaining return this // for chaining
...@@ -92,7 +90,7 @@ class Wechaty extends EventEmitter { ...@@ -92,7 +90,7 @@ class Wechaty extends EventEmitter {
} }
const WechatyIo = require('./wechaty-io') const WechatyIo = require('./wechaty-io')
const io = this.io = new WechatyIo({ const io = new WechatyIo({
wechaty: this wechaty: this
, token: this.token , token: this.token
, endpoint: this.endpoint , endpoint: this.endpoint
...@@ -106,9 +104,10 @@ class Wechaty extends EventEmitter { ...@@ -106,9 +104,10 @@ class Wechaty extends EventEmitter {
} }
initPuppet() { initPuppet() {
let puppet
switch (this.type) { switch (this.type) {
case 'web': case 'web':
this.puppet = new PuppetWeb( { puppet = new PuppetWeb( {
head: this.head head: this.head
, port: this.port , port: this.port
, profile: this.profile , profile: this.profile
...@@ -117,10 +116,7 @@ class Wechaty extends EventEmitter { ...@@ -117,10 +116,7 @@ class Wechaty extends EventEmitter {
default: default:
throw new Error('Puppet unsupport(yet): ' + this.type) throw new Error('Puppet unsupport(yet): ' + this.type)
} }
return Promise.resolve(this.puppet)
}
initEventHook() {
;[ ;[
'scan' 'scan'
, 'message' , 'message'
...@@ -129,26 +125,10 @@ class Wechaty extends EventEmitter { ...@@ -129,26 +125,10 @@ class Wechaty extends EventEmitter {
, 'error' , 'error'
, 'heartbeat' , 'heartbeat'
].map(e => { ].map(e => {
this.puppet.on(e, data => { puppet.on(e, data => {
this.emit(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: * TODO: support more events:
* 2. send * 2. send
...@@ -157,7 +137,7 @@ class Wechaty extends EventEmitter { ...@@ -157,7 +137,7 @@ class Wechaty extends EventEmitter {
* 5. ... * 5. ...
*/ */
return Promise.resolve() return puppet.init()
} }
quit() { quit() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册