Skip to content

Commit

Permalink
fix #756 #86 #2 #195 #237 #329 puppeteer does not have to wait `netwo…
Browse files Browse the repository at this point in the history
…rkidle`
  • Loading branch information
huan committed Oct 8, 2017
1 parent aeef9fb commit 1a7fd6f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/puppet-web/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async function onScan(this: PuppetWeb, data: ScanInfo) {
}

function onLog(data: any): void {
log.verbose('PuppetWebEvent', 'onLog(%s)', data)
log.silly('PuppetWebEvent', 'onLog(%s)', data)
}

async function onLogin(this: PuppetWeb, memo: string, attempt = 0): Promise<void> {
Expand Down
38 changes: 19 additions & 19 deletions src/puppet-web/puppet-web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export class PuppetWeb extends Puppet {
this.state.current('live', false)

try {
await this.initPuppetWatchrat()
await this.initScanWatchrat()
await this.initWatchdogForPuppet()
await this.initWatchdogForScan()

const throttleQueue = new RxQueue('throttle', 5 * 60 * 1000)
this.on('heartbeat', data => throttleQueue.emit('i', data))
Expand Down Expand Up @@ -136,7 +136,7 @@ export class PuppetWeb extends Puppet {
}
}

public initPuppetWatchrat(): void {
public initWatchdogForPuppet(): void {
this.on('ding', data => this.puppetWatchrat.feed({
data,
type: 'ding',
Expand All @@ -155,7 +155,7 @@ export class PuppetWeb extends Puppet {
* sometimes the qrcode will not refresh, leave there expired.
* so we need to refresh the page after a while
*/
public initScanWatchrat(): void {
public initWatchdogForScan(): void {
this.on('scan', info => this.scanWatchrat.feed({
data: info,
type: 'scan',
Expand Down Expand Up @@ -249,20 +249,27 @@ export class PuppetWeb extends Puppet {
public async initBridge(profile: Profile): Promise<Bridge> {
log.verbose('PuppetWeb', 'initBridge()')

const head = false
const bridge = new Bridge({
head,
profile,
})

if (this.state.target() === 'dead') {
const e = new Error('initBridge() found targetState != live, no init anymore')
log.warn('PuppetWeb', e.message)
throw e
}

const head = true
this.bridge = new Bridge({
head,
profile,
})

this.bridge.on('ding' , Event.onDing.bind(this))
this.bridge.on('log' , Event.onLog.bind(this))
this.bridge.on('login' , Event.onLogin.bind(this))
this.bridge.on('logout' , Event.onLogout.bind(this))
this.bridge.on('message' , Event.onMessage.bind(this))
this.bridge.on('scan' , Event.onScan.bind(this))

try {
await bridge.init()
await this.bridge.init()
} catch (e) {
// FIXME
/*
Expand All @@ -277,14 +284,7 @@ export class PuppetWeb extends Puppet {
throw e
}

bridge.on('ding' , Event.onDing.bind(this))
bridge.on('log' , Event.onLog.bind(this))
bridge.on('login' , Event.onLogin.bind(this))
bridge.on('logout' , Event.onLogout.bind(this))
bridge.on('message' , Event.onMessage.bind(this))
bridge.on('scan' , Event.onScan.bind(this))

return bridge
return this.bridge
}

public reset(reason?: string): void {
Expand Down
17 changes: 9 additions & 8 deletions src/puppet-web/wechaty-bro.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
hookEvents()
hookRecalledMsgProcess()

log('init() scanCode: ' + WechatyBro.vars.scanCode)
checkScan()

heartBeat(true)
Expand Down Expand Up @@ -204,6 +205,8 @@
// 200: 登录成功
var code = +WechatyBro.glue.loginScope.code
var url = WechatyBro.glue.loginScope.qrcodeUrl
log('checkScan() code:' + code + ' url:' + url + ' scanCode:' + WechatyBro.vars.scanCode)

if (url && code !== WechatyBro.vars.scanCode) {

log('checkScan() - code change detected: from '
Expand All @@ -212,8 +215,8 @@
+ code
)
WechatyBro.emit('scan', {
code: code
, url: url
code: code,
url: url,
})
WechatyBro.vars.scanCode = code
}
Expand Down Expand Up @@ -775,13 +778,11 @@

// variable
, vars: {
loginStatus: false
, initStatus: false
loginStatus : false,
initStatus : false,

, socket: null
, eventsBuf: []
, scanCode: null
, heartBeatTimmer: null
scanCode : null,
heartBeatTimmer : null,
}

// funcs
Expand Down

0 comments on commit 1a7fd6f

Please sign in to comment.