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

code clean up

上级 21d5a27f
...@@ -47,6 +47,8 @@ class PuppetWeb extends Puppet { ...@@ -47,6 +47,8 @@ class PuppetWeb extends Puppet {
this.userId = null // user id this.userId = null // user id
this.user = null // <Contact> of user self this.user = null // <Contact> of user self
this.on('watchdog', Watchdog.onFeed.bind(this))
} }
toString() { return `Class PuppetWeb({browser:${this.browser},port:${this.port}})` } toString() { return `Class PuppetWeb({browser:${this.browser},port:${this.port}})` }
...@@ -56,8 +58,6 @@ class PuppetWeb extends Puppet { ...@@ -56,8 +58,6 @@ class PuppetWeb extends Puppet {
this.readyState('connecting') this.readyState('connecting')
this.on('watchdog', Watchdog.onFeed.bind(this))
return co.call(this, function* () { return co.call(this, function* () {
this.port = yield UtilLib.getPort(Config.DEFAULT_PUPPET_PORT) this.port = yield UtilLib.getPort(Config.DEFAULT_PUPPET_PORT)
...@@ -75,7 +75,6 @@ class PuppetWeb extends Puppet { ...@@ -75,7 +75,6 @@ class PuppetWeb extends Puppet {
this.bridge = yield this.initBridge() this.bridge = yield this.initBridge()
log.verbose('PuppetWeb', 'initBridge() done') log.verbose('PuppetWeb', 'initBridge() done')
// this.watchDog('inited') // start watchdog
this.emit('watchdog', { data: 'inited' }) this.emit('watchdog', { data: 'inited' })
}) })
.catch(e => { // Reject .catch(e => { // Reject
...@@ -190,14 +189,14 @@ class PuppetWeb extends Puppet { ...@@ -190,14 +189,14 @@ class PuppetWeb extends Puppet {
}) })
return bridge.init() return bridge.init()
.catch(e => { .catch(e => {
if (this.browser.dead()) { if (this.browser.dead()) {
log.warn('PuppetWeb', 'initBridge() found browser dead, wait it to restore') log.warn('PuppetWeb', 'initBridge() found browser dead, wait it to restore')
} else { } else {
log.error('PuppetWeb', 'initBridge() exception: %s', e.message) log.error('PuppetWeb', 'initBridge() exception: %s', e.message)
throw e throw e
} }
}) })
} }
initServer() { initServer() {
...@@ -222,10 +221,10 @@ class PuppetWeb extends Puppet { ...@@ -222,10 +221,10 @@ class PuppetWeb extends Puppet {
server.on('ding' , Event.onServerDing.bind(this)) server.on('ding' , Event.onServerDing.bind(this))
return server.init() return server.init()
.catch(e => { .catch(e => {
log.error('PuppetWeb', 'initServer() exception: %s', e.message) log.error('PuppetWeb', 'initServer() exception: %s', e.message)
throw e throw e
}) })
} }
...@@ -257,10 +256,10 @@ class PuppetWeb extends Puppet { ...@@ -257,10 +256,10 @@ class PuppetWeb extends Puppet {
log.silly('PuppetWeb', `send(${destination}, ${content})`) log.silly('PuppetWeb', `send(${destination}, ${content})`)
return this.bridge.send(destination, content) return this.bridge.send(destination, content)
.catch(e => { .catch(e => {
log.error('PuppetWeb', 'send() exception: %s', e.message) log.error('PuppetWeb', 'send() exception: %s', e.message)
throw e throw e
}) })
} }
reply(message, replyContent) { reply(message, replyContent) {
if (this.self(message)) { if (this.self(message)) {
...@@ -287,10 +286,10 @@ class PuppetWeb extends Puppet { ...@@ -287,10 +286,10 @@ class PuppetWeb extends Puppet {
*/ */
logout() { logout() {
return this.bridge.logout() return this.bridge.logout()
.catch(e => { .catch(e => {
log.error('PuppetWeb', 'logout() exception: %s', e.message) log.error('PuppetWeb', 'logout() exception: %s', e.message)
throw e throw e
}) })
} }
getContact(id) { getContact(id) {
...@@ -299,10 +298,10 @@ class PuppetWeb extends Puppet { ...@@ -299,10 +298,10 @@ class PuppetWeb extends Puppet {
} }
return this.bridge.getContact(id) return this.bridge.getContact(id)
.catch(e => { .catch(e => {
log.error('PuppetWeb', 'getContact(%d) exception: %s', id, e.message) log.error('PuppetWeb', 'getContact(%d) exception: %s', id, e.message)
throw e throw e
}) })
} }
logined() { return !!(this.user) } logined() { return !!(this.user) }
ding(data) { ding(data) {
...@@ -310,19 +309,19 @@ class PuppetWeb extends Puppet { ...@@ -310,19 +309,19 @@ class PuppetWeb extends Puppet {
return Promise.reject(new Error('ding fail: no bridge(yet)!')) return Promise.reject(new Error('ding fail: no bridge(yet)!'))
} }
return this.bridge.ding(data) return this.bridge.ding(data)
.catch(e => { .catch(e => {
log.warn('PuppetWeb', 'ding(%s) rejected: %s', data, e.message) log.warn('PuppetWeb', 'ding(%s) rejected: %s', data, e.message)
throw e throw e
}) })
} }
} }
Object.assign(PuppetWeb, { // Object.assign(PuppetWeb, {
default: PuppetWeb // default: PuppetWeb
, PuppetWeb // , PuppetWeb
, Server // , Server
, Browser // , Browser
, Bridge // , Bridge
}) // })
module.exports = PuppetWeb module.exports = PuppetWeb.default = PuppetWeb.PuppetWeb = PuppetWeb
...@@ -9,16 +9,14 @@ ...@@ -9,16 +9,14 @@
* *
*/ */
const EventEmitter = require('events') const EventEmitter = require('events')
const path = require('path')
const co = require('co') const co = require('co')
const fs = require('fs') const fs = require('fs')
const path = require('path')
const log = require('./brolog-env')
const UtilLib = require('./util-lib')
const PuppetWeb = require('./puppet-web')
const Config = require('./config') const PuppetWeb = require('./puppet-web')
const UtilLib = require('./util-lib')
const Config = require('./config')
const log = require('./brolog-env')
class Wechaty extends EventEmitter { class Wechaty extends EventEmitter {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册