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

bug fix

上级 fa101547
......@@ -7,7 +7,7 @@
"wechaty": {
"DEFAULT_HEAD": "chrome",
"DEFAULT_PUPPET": "web",
"DEFAULT_PROFILE": "profile",
"DEFAULT_PROFILE": "demo",
"DEFAULT_PORT": 8788,
"DEFAULT_PROTOCOL": "io|0.0.1",
"DEFAULT_TOKEN": "WECHATY_IO_TOKEN",
......
......@@ -135,12 +135,14 @@ Object.assign(Config, {
puppetInstance
})
export type WatchdogFoodName = 'HEARTBEAT'
| 'POISON'
| 'SCAN'
export type WatchdogFood = {
data: any
, timeout?: number // millisecond
, type?: 'HEARTBEAT'
| 'POISON'
| 'SCAN'
, type?: WatchdogFoodName
}
export type ScanInfo = {
......
......@@ -534,7 +534,11 @@ class Browser extends EventEmitter {
}
public dead(forceReason?: string): boolean {
log.verbose('PuppetWebBrowser', 'dead(%s)', forceReason ? forceReason : '')
if (forceReason) {
log.verbose('PuppetWebBrowser', 'dead(%s)', forceReason)
} else {
log.silly('PuppetWebBrowser', 'dead()')
}
let msg
let dead = false
......
......@@ -49,7 +49,10 @@ export class PuppetWeb extends Puppet {
private port: number
constructor(private setting: PuppetWebSetting = {}) {
public lastScanEventTime: number
public watchDogLastSaveSession: number
constructor(public setting: PuppetWebSetting = {}) {
super()
this.on('watchdog', Watchdog.onFeed.bind(this))
......
......@@ -15,12 +15,13 @@
*/
// const co = require('co')
import log from '../brolog-env'
import {
WatchdogFood
} from '../config'
import Event from './event'
WatchdogFood
, WatchdogFoodName
, log
} from '../config'
import PuppetWeb from './puppet-web'
import Event from './event'
/* tslint:disable:variable-name */
const Watchdog = {
......@@ -122,11 +123,16 @@ function watchDogReset(timeout, lastFeed) {
* save every 5 mins
*
*/
function autoSaveSession() {
function autoSaveSession(this: PuppetWeb, force = false) {
log.silly('PuppetWebWatchdog', 'autoSaveSession()')
if (force) {
this.watchDogLastSaveSession = 0 // 0 will cause save session right now
}
const SAVE_SESSION_INTERVAL = 5 * 60 * 1000 // 5 mins
if (Date.now() - this.watchDogLastSaveSession > SAVE_SESSION_INTERVAL) {
log.verbose('PuppetWebWatchdog', 'watchDog() saveSession(%s) after %d minutes'
, this.profile
log.verbose('PuppetWebWatchdog', 'autoSaveSession() profile(%s) after %d minutes'
, this.setting.profile
, Math.floor(SAVE_SESSION_INTERVAL / 1000 / 60)
)
this.browser.saveSession()
......@@ -143,16 +149,17 @@ function autoSaveSession() {
* so we need to refresh the page after a while
*
*/
function monitorScan(type) {
function monitorScan(this: PuppetWeb, type: WatchdogFoodName) {
log.silly('PuppetWebWatchdog', 'monitorScan(%s)', type)
const scanTimeout = 10 * 60 * 1000 // 10 mins
if (type === 'SCAN') { // watchDog was feed a 'scan' data
this.lastScanEventTime = Date.now()
// autoSaveSession.call(this, true)
}
if (this.logined()) { // XXX: login status right?
this.lastScanEventTime = null
this.lastScanEventTime = 0
} else if (this.lastScanEventTime
&& Date.now() - this.lastScanEventTime > scanTimeout) {
log.warn('PuppetWebWatchdog', 'monirotScan() refresh browser for no food of type scan after %s mins'
......
......@@ -353,7 +353,7 @@ export class Room extends EventEmitter implements Sayable {
public static create(contactList: Contact[], topic?: string): Promise<Room> {
log.verbose('Room', 'create(%s, %s)', contactList.join(','), topic)
if (!contactList || !(typeof contactList === 'array')) {
if (!contactList || !Array.isArray(contactList)) {
throw new Error('contactList not found')
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册