From d14d7104182aa6e28967fb3e61f7e7c9b86092ff Mon Sep 17 00:00:00 2001 From: Zhuohuan LI Date: Fri, 8 Jul 2016 12:41:05 +0800 Subject: [PATCH] code clean --- package.json | 2 +- src/puppet-web/watchdog.js | 14 ++++---------- src/wechaty-io.js | 4 ++-- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 951f46d2..913f9b07 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wechaty" - , "version": "0.2.5" + , "version": "0.2.6" , "description": "Wechat for Bot. (Personal Account NOT Official Account)" , "main": "index.js" , "scripts": { diff --git a/src/puppet-web/watchdog.js b/src/puppet-web/watchdog.js index 91220e39..32ead343 100644 --- a/src/puppet-web/watchdog.js +++ b/src/puppet-web/watchdog.js @@ -28,20 +28,14 @@ const Watchdog = { // feed me in time(after 1st feed), or I'll restart system function onFeed({ data - , type = 'GARBAGE' + , type = 'HEARTBEAT' , timeout = 60000 // 60s default. can be override in options but be careful about the number zero(0) } = {}) { if (!this) { - throw new Error('onFeed() must has `this`') + throw new Error('onFeed() must has `this` of instanceof PuppetWeb') } - // console.log('#################') - // console.log(typeof this) - // console.log(this.constructor.name) - // console.log(this) - // throw new Error('faint') - process.nextTick(_ => { log.verbose('PuppetWebWatchdog', 'onFeed: %s, %d, [%s]', type, timeout, data) @@ -50,8 +44,8 @@ function onFeed({ clearWatchDogTimer.call(this) return - case 'GARBAGE': case 'SCAN': + case 'HEARTBEAT': break default: @@ -64,7 +58,7 @@ function onFeed({ monitorScan.call(this, type) autoSaveSession.call(this) - }) + }) // end nextTick } diff --git a/src/wechaty-io.js b/src/wechaty-io.js index 7cf707e7..935b92ad 100644 --- a/src/wechaty-io.js +++ b/src/wechaty-io.js @@ -72,7 +72,7 @@ class WechatyIo { ws.send('Wechaty version ' + this.wechaty.version()) }.bind(this)) - ws.on('message', function(data, flags) { + ws.on('message', (data, flags) => { log.verbose('WechatyIo', 'WebSocket got message') // flags.binary will be set if a binary data is received. // flags.masked will be set if the data was masked. @@ -87,7 +87,7 @@ class WechatyIo { log.warn('WechatyIo', 'onMessage server push function invalid') } } - }.bind(this)) + }) ws .on('close', e => { -- GitLab