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

fix typo and show last feed when watchdog timeout

上级 3df7342e
......@@ -16,10 +16,14 @@ const log = require('../npmlog-env')
class Bridge {
constructor(options) {
if (!options || !options.puppet) { throw new Error('Bridge need a puppet')}
if (!options || !options.puppet) {
throw new Error('Bridge need a puppet')
}
log.verbose('PuppetWebBridge', 'new Bridge({puppet: %s, port: %s})'
, options.puppet.constructor.name
, options.port)
, options.port
)
this.puppet = options.puppet
this.port = options.port || 8788 // W(87) X(88), ascii char code ;-]
......
......@@ -154,8 +154,8 @@ function onServerDisconnect(data) {
this.user = null
}
if (this.readyStatus() === 'disconnecting') {
log.verbose('PuppetWebEvent', 'onServerDisconnect() be called when readyStatus is `disconnecting`')
if (this.readyState() === 'disconnecting') {
log.verbose('PuppetWebEvent', 'onServerDisconnect() be called when readyState is `disconnecting`')
return
}
......
......@@ -89,12 +89,12 @@ class PuppetWeb extends Puppet {
quit() {
log.verbose('PuppetWeb', 'quit()')
if (this.readyStatus() === 'disconnecting') {
log.warn('PuppetWeb', 'quit() is called but readyStatus is `disconnecting`?')
if (this.readyState() === 'disconnecting') {
log.warn('PuppetWeb', 'quit() is called but readyState is `disconnecting`?')
throw new Error('do not call quit again when quiting')
}
this.readyStatus('disconnecting')
this.readyState('disconnecting')
// this.clearWatchDogTimer()
this.emit('watchdog', {
......@@ -136,7 +136,7 @@ class PuppetWeb extends Puppet {
})
.then(() => { // Finally, Fail Safe
log.verbose('PuppetWeb', 'quit() done')
this.readyStatus('disconnected')
this.readyState('disconnected')
return this // for Chaining
})
}
......
......@@ -56,7 +56,7 @@ function onFeed({
throw new Error('Watchdog onFeed: unsupport type ' + type)
}
setWatchDogTimer.call(this, timeout)
setWatchDogTimer.call(this, timeout, (type + ':' + data))
this.emit('heartbeat', type + ':' + data)
......@@ -78,7 +78,7 @@ function clearWatchDogTimer() {
}
}
function setWatchDogTimer(timeout) {
function setWatchDogTimer(timeout, feed) {
clearWatchDogTimer.call(this)
......@@ -89,9 +89,13 @@ function setWatchDogTimer(timeout) {
// block quit, force to use quit() // this.watchDogTimer.unref() // dont block quit
}
function watchDogReset(timeout) {
function watchDogReset(timeout, lastFeed) {
log.verbose('PuppetWebWatchdog', 'watchDogReset() timeout %d', timeout)
const e = new Error('watchdog reset after ' + Math.floor(timeout/1000) + ' seconds')
const e = new Error('watchdog reset after '
+ Math.floor(timeout/1000)
+ ' seconds, last feed:'
+ '[' + lastFeed + ']'
)
this.emit('error', e)
return Event.onBrowserDead.call(this, e)
}
......
......@@ -21,15 +21,15 @@ class Puppet extends EventEmitter {
* connected / disconnected
* connecting / disconnecting
*/
this._readyStatus = 'disconnected'
this._readyState = 'disconnected'
}
readyStatus(newStatus) {
if (newStatus) {
log.verbose('Puppet', 'readyStatus(%s)', newStatus)
this._readyStatus = newStatus
readyState(newState) {
if (newState) {
log.verbose('Puppet', 'readyState(%s)', newState)
this._readyState = newState
}
return this._readyStatus
return this._readyState
}
/**
......
const test = require('tape')
const Wechaty = require('../')
const Puppet = Wechaty.Puppet
test('Puppet smoking test', t => {
const p = new Puppet()
t.equal(p.readyState(), 'disconnected', 'should be disconnected state after instanciate')
p.readyState('connecting')
t.equal(p.readyState(), 'connecting', 'should be connecting state after set')
t.end()
})
const test = require('tape')
const Wechaty = require('../')
test('Wechaty Framework', function(t) {
const Wechaty = require('../')
test('Wechaty Framework', t => {
t.ok(Wechaty , 'should export Wechaty')
t.ok(Wechaty.Message , 'should export Wechaty.Message')
t.ok(Wechaty.Contact , 'should export Wechaty.Contact')
......@@ -21,8 +21,7 @@ test('Wechaty Framework', function(t) {
t.end()
})
test('Wechaty config setting', function(t) {
const Wechaty = require('../')
test('Wechaty config setting', t => {
const config = Wechaty.config
t.ok(config , 'should export Wechaty.config')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册