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

bug fix

上级 62e46ce1
......@@ -18,13 +18,13 @@ import log from './brolog-env'
export type MessageRawObj = {
MsgId: string
MsgType: string
MsgType: number
MMActualSender: string
ToUserName: string
MMActualContent: string // Content has @id prefix added by wx
Status: string
MMDigest: string
MMDisplayTime: string // Javascript timestamp of milliseconds
MMDisplayTime: number // Javascript timestamp of milliseconds
Url: string
RecommendInfo?: RecommendInfo
......
......@@ -37,37 +37,48 @@ class Bridge {
public async init(): Promise<Bridge> {
log.verbose('PuppetWebBridge', 'init()')
const max = 15
const backoff = 100
// max = (2*totalTime/backoff) ^ (1/2)
// timeout = 11,250 for {max: 15, backoff: 100}
// timeout = 45,000 for {max: 30, backoff: 100}
// timeout = 30,6250 for {max: 35, backoff: 500}
const timeout = max * (backoff * max) / 2
return retryPromise({ max: max, backoff: backoff }, attempt => {
log.silly('PuppetWebBridge', 'init() retryPromise: attampt %s/%s times for timeout %s'
, attempt, max, timeout)
return this.inject()
.then(r => {
log.silly('PuppetWebBridge', 'init() inject() return %s at attempt %d', r, attempt)
return this
})
.catch(e => {
log.silly('PuppetWebBridge', 'init() inject() attempt %d exception: %s', attempt, e.message)
throw e
})
})
.then(_ => {
log.silly('PuppetWebBridge', 'init()-ed')
// log.silly('PuppetWebBridge', 'init() inject() return %s at attempt %d', r, attempt)
return this
})
.catch(e => {
log.warn('PuppetWebBridge', 'init() inject FINAL fail: %s', e.message)
log.silly('PuppetWebBridge', 'init() inject() exception: %s', e && e.message || e)
throw e
})
// const max = 15
// const backoff = 100
// max = (2*totalTime/backoff) ^ (1/2)
// timeout = 11,250 for {max: 15, backoff: 100}
// timeout = 45,000 for {max: 30, backoff: 100}
// timeout = 30,6250 for {max: 35, backoff: 500}
// const timeout = max * (backoff * max) / 2
// return retryPromise({ max: max, backoff: backoff }, attempt => {
// log.silly('PuppetWebBridge', 'init() retryPromise: attampt %s/%s times for timeout %s'
// , attempt, max, timeout)
// return this.inject()
// .then(r => {
// log.silly('PuppetWebBridge', 'init() inject() return %s at attempt %d', r, attempt)
// return this
// })
// .catch(e => {
// log.silly('PuppetWebBridge', 'init() inject() attempt %d exception: %s', attempt, e.message)
// throw e
// })
// })
// .then(_ => {
// log.silly('PuppetWebBridge', 'init()-ed')
// return this
// })
// .catch(e => {
// log.warn('PuppetWebBridge', 'init() inject FINAL fail: %s', e.message)
// throw e
// })
}
public async inject(): Promise<any> {
......@@ -116,12 +127,13 @@ class Bridge {
* Do not insert `return` in front of the code.
* because the new line `\n` will cause return nothing at all
*/
return 'injectioReturnValue = '
const code = 'injectioReturnValue = '
+ fs.readFileSync(
path.join(__dirname, 'wechaty-bro.js')
, 'utf8'
)
+ '; return injectioReturnValue'
return code.replace(/[\n\s]/, ' ')
}
public logout(): Promise<any> {
......@@ -137,8 +149,9 @@ class Bridge {
log.verbose('PuppetWebBridge', 'quit()')
return this.proxyWechaty('quit')
.catch(e => {
log.error('PuppetWebBridge', 'quit() exception: %s', e.message)
throw e
log.warn('PuppetWebBridge', 'quit() exception: %s', e && e.message || e)
// throw e
/* fail safe */
})
}
......
......@@ -325,6 +325,8 @@ class Browser extends EventEmitter {
// XXX fail safe to `close` ?
this.currentState('close')
/* fail safe */
}
return
......
......@@ -2,7 +2,7 @@
*
* Wechaty: Wechat for Bot. and for human who talk to bot/robot
*
* Class Io
* Class StateMonitor
* http://www.wechaty.io
*
* Licenst: ISC
......@@ -16,7 +16,7 @@
* B - State B
*/
class StateMonitor <A, B>{
export class StateMonitor <A, B>{
private _target: A|B
private _current: A|B
private _stable: boolean
......@@ -51,4 +51,3 @@ class StateMonitor <A, B>{
}
export default StateMonitor
export { StateMonitor }
......@@ -142,15 +142,11 @@ export class Wechaty extends EventEmitter {
return Promise.resolve(this)
}
// return co.call(this, function* () {
try {
await this.initPuppet()
this.inited = true
// return this // for chaining
// }).catch(e => {
} catch (e) {
log.error('Wechaty', 'init() exception: %s', e.message)
log.error('Wechaty', 'init() exception: %s', e && e.message)
throw e
}
return this
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册