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

code clean

上级 6f222d08
......@@ -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) {
......
......@@ -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() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册