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

code clean

上级 04cd6e17
...@@ -46,45 +46,11 @@ class Bridge { ...@@ -46,45 +46,11 @@ class Bridge {
log.silly('PuppetWebBridge', 'init() inject() exception: %s', e && e.message || e) log.silly('PuppetWebBridge', 'init() inject() exception: %s', e && e.message || e)
throw 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> { public async inject(): Promise<any> {
log.verbose('PuppetWebBridge', 'inject()') log.verbose('PuppetWebBridge', 'inject()')
// return co.call(this, function* () {
try { try {
const injectio = this.getInjectio() const injectio = this.getInjectio()
...@@ -112,7 +78,7 @@ class Bridge { ...@@ -112,7 +78,7 @@ class Bridge {
log.silly('PuppetWebBridge', 'inject() ding success') log.silly('PuppetWebBridge', 'inject() ding success')
return true return true
// }).catch (e => {
} catch (e) { } catch (e) {
log.verbose('PuppetWebBridge', 'inject() exception: %s. stack: %s', e.message, e.stack) log.verbose('PuppetWebBridge', 'inject() exception: %s. stack: %s', e.message, e.stack)
throw e throw e
...@@ -347,8 +313,9 @@ class Bridge { ...@@ -347,8 +313,9 @@ class Bridge {
) )
`.replace(/[\n\s]+/, ' ') `.replace(/[\n\s]+/, ' ')
// log.silly('PuppetWebBridge', 'proxyWechaty(%s, ...args) %s', wechatyFunc, wechatyScript) // log.silly('PuppetWebBridge', 'proxyWechaty(%s, ...args) %s', wechatyFunc, wechatyScript)
// console.log('proxyWechaty wechatyFunc args[0]: ') // console.log('proxyWechaty wechatyFunc args[0]: ')
// console.log(args[0]) // console.log(args[0])
/** /**
* *
* WechatyBro method named end with "Async", will be treated as a Async function * WechatyBro method named end with "Async", will be treated as a Async function
......
...@@ -358,7 +358,7 @@ export class PuppetWeb extends Puppet { ...@@ -358,7 +358,7 @@ export class PuppetWeb extends Puppet {
}) })
} }
public logined() { return !!(this.user) } public logined() { return !!(this.user) }
public ding(data?: any): Promise<any> { public ding(data?: any): Promise<string> {
if (!this.bridge) { if (!this.bridge) {
return Promise.reject(new Error('ding fail: no bridge(yet)!')) return Promise.reject(new Error('ding fail: no bridge(yet)!'))
} }
......
...@@ -82,7 +82,7 @@ export abstract class Puppet extends EventEmitter implements Sayable { ...@@ -82,7 +82,7 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public abstract reset(reason?: string) public abstract reset(reason?: string)
public abstract logout(): Promise<any> public abstract logout(): Promise<any>
public abstract quit(): Promise<any> public abstract quit(): Promise<any>
public abstract ding(data?: string): Promise<any> public abstract ding(): Promise<string>
/** /**
* FriendRequest * FriendRequest
......
...@@ -296,12 +296,12 @@ export class Wechaty extends EventEmitter implements Sayable { ...@@ -296,12 +296,12 @@ export class Wechaty extends EventEmitter implements Sayable {
}) })
} }
public ding(data: string) { public ding() {
if (!this.puppet) { if (!this.puppet) {
return Promise.reject(new Error('wechaty cant ding coz no puppet')) return Promise.reject(new Error('wechaty cant ding coz no puppet'))
} }
return this.puppet.ding(data) return this.puppet.ding() // should return 'dong'
.catch(e => { .catch(e => {
log.error('Wechaty', 'ding() exception: %s', e.message) log.error('Wechaty', 'ding() exception: %s', e.message)
throw e throw e
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册