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

Merge branch 'master' of github.com:zixia/wechaty

......@@ -260,9 +260,9 @@ class Browser extends EventEmitter{
cleanSession(session) {
log.verbose('Browser', `cleanSession(${session})`)
if (this.dead()) { return Promise.reject('cleanSession() - browser dead')}
if (this.dead()) { return Promise.reject('cleanSession() - browser dead')}
if (!session) { return Promise.reject('cleanSession() no session') }
if (!session) { return Promise.reject('cleanSession() no session') }
const filename = session
return new Promise((resolve, reject) => {
require('fs').unlink(filename, err => {
......
......@@ -211,7 +211,11 @@ class PuppetWeb extends Puppet {
onServerScan(data) {
log.verbose('PuppetWeb', 'onServerScan: %s', Object.keys(data).join(','))
this.browser.cleanSession().catch(() => {/* fall safe */})
if (this.session) {
this.browser.cleanSession(this.session)
.catch(() => {/* fall safe */})
}
this.emit('scan', data)
}
......@@ -272,14 +276,23 @@ class PuppetWeb extends Puppet {
log.warn('PuppetWeb', 'server received unload event')
// this.onServerLogout(data) // XXX: should emit event[logout] from browser
if (!this.browser || !this.bridge) {
log.verbose('PuppetWeb', 'bridge gone, should be quiting now')
if (!this.browser) {
log.verbose('PuppetWeb', 'onServerUnload() found browser gone, should be quiting now')
return
}
if (this.browser.dead()) {
log.warn('PuppetWeb', 'onServerUnload() found browser dead. wait deadguard to restore')
return
}
if (!this.bridge) {
log.verbose('PuppetWeb', 'onServerUnload() found bridge gone, should be quiting now')
return
}
return process.nextTick(() => {
this.bridge.init()
.then(r => log.verbose('PuppetWeb', 'bridge.re-init()ed:' + r))
.then(r => log.verbose('PuppetWeb', 'onServerUnload() bridge.re-init()ed:' + r))
.catch(e => log.error('PuppetWeb', 'onServerUnload() err: ' + e.message))
})
......
......@@ -7,7 +7,6 @@
*
*/
const log = require('./npmlog-env')
const Contact = require('./contact')
class Room {
constructor(id) {
......@@ -61,7 +60,7 @@ class Room {
}
return memberList.map(m => {
return {
contact: Contact.load(m.UserName)
id: m.UserName
, name: m.DisplayName
}
})
......
......@@ -9,6 +9,7 @@
*
*/
const EventEmitter = require('events')
const co = require('co')
const log = require('./npmlog-env')
......@@ -25,7 +26,7 @@ class Wechaty extends EventEmitter {
this.options = options || {}
this.options.puppet = this.options.puppet || process.env.WECHATY_PUPPET || 'web'
this.options.head = this.options.head || process.env.WECHATY_HEAD || false
this.options.session = this.options.session || process.env.WECHATY_SESSION // no session, no session restore
this.options.session = this.options.session || process.env.WECHATY_SESSION // no session, no session save/estore
this.VERSION = require('../package.json').version
}
......@@ -36,12 +37,16 @@ class Wechaty extends EventEmitter {
log.verbose('Wechaty', 'head: %s' , this.options.head)
log.verbose('Wechaty', 'session: %s', this.options.session)
this.initPuppet()
this.initEventHook()
return co.call(this, function* () {
yield this.initPuppet()
yield this.initEventHook()
yield this.puppet.init()
return this.puppet.init()
.then(r => {
return this // for chaining
}).catch(e => {
log.error('Wechaty', 'init() be rejected: %s', e)
throw e
})
}
initPuppet() {
......@@ -85,7 +90,8 @@ class Wechaty extends EventEmitter {
return Promise.resolve()
}
quit() { return this.puppet.quit() }
quit() { return this.puppet.quit() }
logout() { return this.puppet.logout() }
send(message) { return this.puppet.send(message) }
reply(message, reply) { return this.puppet.reply(message, reply) }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册