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

add shutdown to io event

上级 fb5e36bd
......@@ -110,6 +110,11 @@ class Io {
this.wechaty.reset()
break
case 'shutdown':
log.warn('Io', 'on(shutdown): %s', ioEvent.payload)
process.exit(0)
break
case 'update':
log.verbose('Io', 'on(report): %s', ioEvent.payload)
const user = this.wechaty.user()
......@@ -121,7 +126,7 @@ class Io {
this.send(loginEvent)
}
const scan = this.wechaty.puppet.scan
const scan = this.wechaty && this.wechaty.puppet && this.wechaty.puppet.scan
if (scan) {
const scanEvent = {
name: 'scan'
......@@ -192,10 +197,6 @@ class Io {
]
hookEvents.map(event => {
wechaty.on(event, data => {
if (!this.connected()) {
log.verbose('Io', 'initEventHook() on event[%s] without a connected websocket', event)
return
}
const ioEvent = {
name: event
, payload: data
......@@ -217,11 +218,28 @@ class Io {
})
})
wechaty.on('message', m => {
const text = (m.room() ? '['+m.room().name()+']' : '')
+ '<'+m.from().name()+'>'
+ ':' + m.toStringDigest()
const messageEvent = {
name: 'message'
, payload: text
}
this.send(messageEvent)
})
return Promise.resolve()
}
send(ioEvent) {
log.silly('Io', 'send(%s: %s)', ioEvent.name, ioEvent.payload)
if (!this.connected()) {
log.verbose('Io', 'send() without a connected websocket, dropped(ToBeQueue)')
return
}
this.ws.send(
JSON.stringify(
ioEvent
......
......@@ -55,6 +55,8 @@ function onBrowserDead(e) {
}
}
this.scan = null
return co.call(this, function* () {
log.verbose('PuppetWebEvent', 'onBrowserDead() co() set isBrowserBirthing true')
this.isBrowserBirthing = true
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册