Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
12e9096c
W
wechaty
项目概览
.Veneno.
/
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,发现更多精彩内容 >>
提交
12e9096c
编写于
6月 17, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bugs fix for saveSession & login event & this binding for event handler etc
上级
ab04383c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
22 addition
and
17 deletion
+22
-17
src/puppet-web-bridge.js
src/puppet-web-bridge.js
+8
-8
src/puppet-web-event.js
src/puppet-web-event.js
+4
-2
src/puppet-web-injectio.js
src/puppet-web-injectio.js
+6
-4
src/puppet-web.js
src/puppet-web.js
+4
-3
未找到文件。
src/puppet-web-bridge.js
浏览文件 @
12e9096c
...
...
@@ -64,19 +64,19 @@ class Bridge {
const
injectio
=
this
.
getInjectio
()
let
retObj
=
yield
this
.
execute
(
injectio
,
this
.
port
)
if
(
retObj
&&
/^2
/
.
test
(
retObj
.
code
))
{
log
.
verbose
(
'
PuppetWebBridge
'
,
'
inject()
injectio injected, with
code[%d] message[%s] port[%d]
'
if
(
retObj
&&
/^2
|3/
.
test
(
retObj
.
code
))
{
// HTTP Code 2XX & 3XX
log
.
verbose
(
'
PuppetWebBridge
'
,
'
inject()
eval(Wechaty) return
code[%d] message[%s] port[%d]
'
,
retObj
.
code
,
retObj
.
message
,
retObj
.
port
)
}
else
{
throw
new
Error
(
'
execute injectio error:
'
+
retObj
.
message
)
}
else
{
// HTTP Code 4XX & 5XX
throw
new
Error
(
'
execute injectio error:
'
+
retObj
.
code
+
'
,
'
+
retObj
.
message
)
}
retObj
=
yield
this
.
proxyWechaty
(
'
init
'
)
if
(
retObj
&&
/^2
/
.
test
(
retObj
.
code
))
{
log
.
verbose
(
'
PuppetWebBridge
'
,
'
inject()
injectio inited, with
code[%d] message[%s] port[%d]
'
if
(
retObj
&&
/^2
|3/
.
test
(
retObj
.
code
))
{
// HTTP Code 2XX & 3XX
log
.
verbose
(
'
PuppetWebBridge
'
,
'
inject()
Wechaty.init() return
code[%d] message[%s] port[%d]
'
,
retObj
.
code
,
retObj
.
message
,
retObj
.
port
)
}
else
{
throw
new
Error
(
'
execute proxyWechaty(init) error:
'
+
retObj
.
message
)
}
else
{
// HTTP Code 4XX & 5XX
throw
new
Error
(
'
execute proxyWechaty(init) error:
'
+
retObj
.
code
+
'
,
'
+
retObj
.
message
)
}
// const r = yield this.proxyWechaty('initClog')
...
...
src/puppet-web-event.js
浏览文件 @
12e9096c
...
...
@@ -161,6 +161,7 @@ function onServerDisconnect(data) {
return
})
}
/**
* `unload` event is sent from js@browser to webserver via socketio
* after received `unload`, we should fix bridge by re-inject the Wechaty js code into browser.
...
...
@@ -172,7 +173,7 @@ function onServerDisconnect(data) {
*/
function
onServerUnload
(
data
)
{
log
.
warn
(
'
PuppetWebEvent
'
,
'
onServerUnload(%s)
'
,
typeof
data
)
//
this.onServerLogout(
data) // XXX: should emit event[logout] from browser
//
onServerLogout.call(this,
data) // XXX: should emit event[logout] from browser
if
(
!
this
.
browser
)
{
log
.
warn
(
'
PuppetWebEvent
'
,
'
onServerUnload() found browser gone, should be quiting now
'
)
...
...
@@ -203,7 +204,7 @@ function onServerLogin(data) {
const
userName
=
yield
this
.
bridge
.
getUserName
()
if
(
!
userName
)
{
log
.
verbose
(
'
PuppetWebEvent
'
,
'
onServerLogin: browser not full loaded, retry later.
'
)
setTimeout
(
this
.
onServerLogin
.
bind
(
this
),
500
)
setTimeout
(
onServerLogin
.
bind
(
this
),
500
)
return
}
log
.
verbose
(
'
PuppetWebEvent
'
,
'
bridge.getUserName: %s
'
,
userName
)
...
...
@@ -221,6 +222,7 @@ function onServerLogin(data) {
log
.
error
(
'
PuppetWebEvent
'
,
'
onServerLogin() exception: %s
'
,
e
.
message
)
})
}
function
onServerLogout
(
data
)
{
if
(
this
.
user
)
{
this
.
emit
(
'
logout
'
,
this
.
user
)
...
...
src/puppet-web-injectio.js
浏览文件 @
12e9096c
...
...
@@ -320,7 +320,8 @@ return (function(port) {
function
checkScan
()
{
clog
(
'
checkScan()
'
)
if
(
isLogin
())
{
log
(
'
checkScan() - already login, no more check
'
)
log
(
'
checkScan() - already login, no more check, but I will emit a login event
'
)
login
(
'
checkScan found already login
'
)
return
}
if
(
!
Wechaty
.
glue
.
loginScope
)
{
...
...
@@ -391,9 +392,10 @@ return (function(port) {
rootScope
.
$on
(
'
root:pageInit:success
'
),
function
(
event
,
data
)
{
login
(
'
by event[root:pageInit:success]
'
)
}
appScope
.
$on
(
"
newLoginPage
"
,
function
(
event
,
data
)
{
login
(
'
by event[newLoginPage]
'
)
})
// newLoginPage seems not stand for a user login action
// appScope.$on("newLoginPage", function(event, data) {
// login('by event[newLoginPage]')
// })
window
.
addEventListener
(
'
unload
'
,
function
(
e
)
{
// XXX only 1 event can be emitted here???
Wechaty
.
emit
(
'
unload
'
,
e
)
...
...
src/puppet-web.js
浏览文件 @
12e9096c
...
...
@@ -187,6 +187,7 @@ class PuppetWeb extends Puppet {
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
if
(
this
.
watchDogTimer
)
{
clearTimeout
(
this
.
watchDogTimer
)
...
...
@@ -194,17 +195,17 @@ class PuppetWeb extends Puppet {
this
.
watchDogTimer
=
setTimeout
(()
=>
{
const
err
=
new
Error
(
'
watchdog timeout after
'
+
Math
.
floor
(
TIMEOUT
/
1000
)
+
'
seconds
'
)
// this.emit('error', err)
this
.
onBrowserDead
(
err
)
Event
.
onBrowserDead
.
call
(
this
,
err
)
},
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
()
}
this
.
watchDogLastSaveSession
=
Date
.
now
()
}
// if web browser stay at login qrcode page long time,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录