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

bug fix

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