Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46011646
wechaty
提交
50ab45e9
W
wechaty
项目概览
weixin_46011646
/
wechaty
与 Fork 源项目一致
Fork自
wechaty / wechaty
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
50ab45e9
编写于
6月 17, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
better timer for watchdog to monitor scan event
上级
12e9096c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
35 addition
and
22 deletion
+35
-22
src/puppet-web-event.js
src/puppet-web-event.js
+4
-0
src/puppet-web.js
src/puppet-web.js
+31
-22
未找到文件。
src/puppet-web-event.js
浏览文件 @
50ab45e9
...
...
@@ -117,6 +117,10 @@ function onServerScan(data) {
this
.
browser
.
saveSession
(
this
.
session
)
.
catch
(()
=>
{
/* fail safe */
})
}
// feed watchDog a `scan` type of food
this
.
watchDog
(
data
,
{
type
:
'
scan
'
})
this
.
emit
(
'
scan
'
,
data
)
}
...
...
src/puppet-web.js
浏览文件 @
50ab45e9
...
...
@@ -186,45 +186,54 @@ class PuppetWeb extends Puppet {
watchDog
(
data
,
options
)
{
log
.
silly
(
'
PuppetWeb
'
,
'
watchDog(%s)
'
,
data
)
options
=
options
||
{}
const
TIMEOUT
=
options
.
timeout
||
60000
// 60s default. can be override in options
const
EVENT
=
options
.
event
||
'
food
'
// just a name
const
timeout
=
options
.
timeout
||
60000
// 60s default. can be override in options
const
type
=
options
.
type
||
'
food
'
// just a name
if
(
this
.
watchDogTimer
)
{
clearTimeout
(
this
.
watchDogTimer
)
}
this
.
watchDogTimer
=
setTimeout
(()
=>
{
const
err
=
new
Error
(
'
watchdog timeout after
'
+
Math
.
floor
(
TIMEOUT
/
1000
)
+
'
seconds
'
)
// this.emit('error', err)
Event
.
onBrowserDead
.
call
(
this
,
err
)
},
TIMEOUT
)
if
(
this
.
watchDogTimer
)
{
clearTimeout
(
this
.
watchDogTimer
)
}
this
.
watchDogTimer
=
setTimeout
(()
=>
this
.
watchDogReset
(
timeout
),
timeout
)
this
.
watchDogTimer
.
unref
()
// dont block quit
const
SAVE_SESSION_INTERVAL
=
5
*
60
*
1000
// 5 mins
if
(
this
.
session
)
{
if
(
this
.
watchDogLastSaveSession
||
Date
.
now
()
-
this
.
watchDogLastSaveSession
>
SAVE_SESSION_INTERVAL
)
{
if
(
this
.
watchDogLastSaveSession
&&
Date
.
now
()
-
this
.
watchDogLastSaveSession
>
SAVE_SESSION_INTERVAL
)
{
log
.
verbose
(
'
PuppetWeb
'
,
'
watchDog() saveSession(%s) after %d minutes
'
,
this
.
session
,
Math
.
floor
(
SAVE_SESSION_INTERVAL
/
1000
/
60
))
this
.
browser
.
saveSession
(
this
.
session
)
}
this
.
watchDogLastSaveSession
=
Date
.
now
()
}
// if web browser stay at login qrcode page long time,
// sometimes the qrcode will not refresh, leave there expired.
// so we need to refresh the page after a while
const
REFRESH_TIMEOUT
=
10
*
60
*
1000
// 10 mins
/**
* if web browser stay at login qrcode page long time,
* sometimes the qrcode will not refresh, leave there expired.
* so we need to refresh the page after a while
*/
if
(
type
===
'
scan
'
)
{
// watchDog was feed a 'scan' data
log
.
verbose
(
'
PuppetWeb
'
,
'
watchDog() got a food with type scan
'
)
this
.
lastScanEventTime
=
Date
.
now
()
}
if
(
!
this
.
logined
())
{
if
(
!
this
.
watchDogLastRefresh
)
{
this
.
watchDogLastRefresh
=
Date
.
now
()
const
scanTimeout
=
10
*
60
*
1000
// 10 mins
if
(
!
this
.
lastScanEventTime
)
{
// 1st scan event
this
.
lastScanEventTime
=
Date
.
now
()
}
if
(
Date
.
now
()
-
this
.
watchDogLastRefresh
>
REFRESH_TIMEOUT
)
{
log
.
warn
(
'
PuppetWeb
'
,
'
watchDog() refresh browser for not login for a long time
'
)
this
.
browser
.
refresh
(
)
if
(
Date
.
now
()
-
this
.
lastScanEventTime
>
scanTimeout
)
{
log
.
warn
(
'
PuppetWeb
'
,
'
watchDog() refresh browser for no food of type scan after %s mins
'
,
Math
.
floor
(
scanTimeout
/
1000
/
60
)
)
this
.
watchDogLastRefresh
=
Date
.
now
()
// fix the problem here
this
.
browser
.
refresh
()
}
}
else
if
(
this
.
watchDogLastRefresh
)
{
this
.
watchDogLastRefresh
=
null
}
else
if
(
this
.
lastScanEventTime
)
{
this
.
lastScanEventTime
=
null
}
}
watchDogReset
(
timeout
)
{
const
e
=
new
Error
(
'
watchdog reset after
'
+
Math
.
floor
(
timeout
/
1000
)
+
'
seconds
'
)
this
.
emit
(
'
error
'
,
e
)
return
Event
.
onBrowserDead
.
call
(
this
,
e
)
}
send
(
message
)
{
const
to
=
message
.
get
(
'
to
'
)
const
room
=
message
.
get
(
'
room
'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录