Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
ad0ad30d
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,发现更多精彩内容 >>
提交
ad0ad30d
编写于
10月 31, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code clean
上级
f9273738
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
37 addition
and
64 deletion
+37
-64
src/config.ts
src/config.ts
+3
-3
src/puppet-web/browser.ts
src/puppet-web/browser.ts
+1
-1
src/puppet-web/puppet-web.ts
src/puppet-web/puppet-web.ts
+1
-0
src/puppet-web/watchdog.ts
src/puppet-web/watchdog.ts
+20
-15
src/puppet.ts
src/puppet.ts
+0
-33
src/wechaty.ts
src/wechaty.ts
+11
-11
test/webdriver.spec.ts
test/webdriver.spec.ts
+1
-1
未找到文件。
src/config.ts
浏览文件 @
ad0ad30d
...
...
@@ -8,13 +8,13 @@ import * as fs from 'fs'
import
Puppet
from
'
./puppet
'
export
type
Puppet
Typ
e
=
'
web
'
|
'
android
'
|
'
ios
'
export
type
Puppet
Nam
e
=
'
web
'
|
'
android
'
|
'
ios
'
export
type
HeadName
=
'
chrome
'
|
'
phantomjs
'
|
'
firefox
'
export
interface
ConfigSetting
{
DEFAULT_HEAD
:
HeadName
DEFAULT_PUPPET
:
Puppet
Typ
e
DEFAULT_PUPPET
:
Puppet
Nam
e
DEFAULT_APIHOST
:
string
DEFAULT_PROFILE
:
string
DEFAULT_TOKEN
:
string
...
...
@@ -27,7 +27,7 @@ export interface ConfigSetting {
token
:
string
debug
:
boolean
puppet
:
Puppet
Typ
e
puppet
:
Puppet
Nam
e
head
:
HeadName
apihost
:
string
...
...
src/puppet-web/browser.ts
浏览文件 @
ad0ad30d
...
...
@@ -265,7 +265,7 @@ export class Browser extends EventEmitter {
return
await
this
.
driver
.
executeScript
.
apply
(
this
.
driver
,
arguments
)
}
catch
(
e
)
{
// this.dead(e)
log
.
warn
(
'
PuppetWebBrowser
'
,
'
execute() exception: %s
'
,
e
.
message
.
substr
(
0
,
99
)
)
log
.
warn
(
'
PuppetWebBrowser
'
,
'
execute() exception: %s
, %s
'
,
e
.
message
.
substr
(
0
,
99
),
e
.
stack
)
throw
e
}
}
...
...
src/puppet-web/puppet-web.ts
浏览文件 @
ad0ad30d
...
...
@@ -98,6 +98,7 @@ export class PuppetWeb extends Puppet {
}
catch
(
e
)
{
log
.
error
(
'
PuppetWeb
'
,
'
init() exception: %s
'
,
e
.
stack
)
this
.
emit
(
'
error
'
,
e
)
await
this
.
quit
()
throw
e
}
...
...
src/puppet-web/watchdog.ts
浏览文件 @
ad0ad30d
...
...
@@ -28,13 +28,10 @@ export const Watchdog = {
onFeed
}
// feed me in time(after 1st feed), or I'll restart system
/**
* feed me in time(after 1st feed), or I'll restart system
*/
function
onFeed
(
this
:
PuppetWeb
,
food
:
WatchdogFood
)
{
// change to tape instead of tap
// type = type || 'HEARTBEAT' // BUG compatible with issue: node-tap strange behaviour cause CircleCI & Travis-CI keep failing #11
// timeout = timeout || 60000 // BUG compatible with issue: node-tap strange behaviour cause CircleCI & Travis-CI keep failing #11
if
(
!
food
.
type
)
{
food
.
type
=
'
HEARTBEAT
'
}
...
...
@@ -49,17 +46,25 @@ function onFeed(this: PuppetWeb, food: WatchdogFood) {
const
feed
=
`
${
food
.
type
}
:[
${
food
.
data
}
]`
log
.
silly
(
'
PuppetWebWatchdog
'
,
'
onFeed: %d, %s
'
,
food
.
timeout
,
feed
)
// if (this.currentState() === 'killing') {
if
(
this
.
state
.
current
()
===
'
dead
'
&&
this
.
state
.
inprocess
())
{
log
.
warn
(
'
PuppetWebWatchdog
'
,
'
onFeed() is disabled because state.current() is `dead` and inprocess()
'
)
return
}
// if (this.readyState() === 'disconnecting'
// // || this.readyState() === 'disconnected'
// ) {
// log.warn('PuppetWebWatchdog', 'onFeed() is disabled because readyState is `disconnecting`')
/**
* Disable Watchdog on the following conditions:
* 1. current state is dead and inprocess
* 1. target state is dead
*
* in other words, watchdog should only work in this condition:
* 1. target state is live
* 1. and stable is true
*
* this is because we will not want to active watchdog when we are closing a browser, or browser is closed.
*/
// if (this.state.current() === 'dead' && this.state.inprocess()) {
// log.warn('PuppetWebWatchdog', 'onFeed() is disabled because state.current() is `dead` and inprocess()')
// return
// }
if
(
this
.
state
.
target
()
===
'
dead
'
||
this
.
state
.
inprocess
())
{
log
.
warn
(
'
PuppetWebWatchdog
'
,
'
onFeed() is disabled because target state is `dead` or state is inprocess
'
)
return
}
setWatchDogTimer
.
call
(
this
,
food
.
timeout
,
feed
)
...
...
src/puppet.ts
浏览文件 @
ad0ad30d
...
...
@@ -32,43 +32,10 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public
state
=
new
StateMonitor
<
'
live
'
,
'
dead
'
>
(
'
Puppet
'
,
'
dead
'
)
// private _targetState: string
// private _currentState: string
constructor
()
{
super
()
/*
* @deprecated
* connected / disconnected
* connecting / disconnecting
*/
// this._readyState = 'disconnected'
// this.targetState('dead')
// this.currentState('dead')
// this.state.target('dead')
// this.state.current('dead')
}
// targetState : 'live' | 'dead'
// public targetState(newState?) {
// if (newState) {
// log.verbose('Puppet', 'targetState(%s)', newState)
// this._targetState = newState
// }
// return this._targetState
// }
// // currentState : 'birthing' | 'killing'
// public currentState(newState?) {
// if (newState) {
// log.verbose('Puppet', 'currentState(%s)', newState)
// this._currentState = newState
// }
// return this._currentState
// }
public
abstract
async
init
():
Promise
<
this
>
/**
* @deprecated
...
...
src/wechaty.ts
浏览文件 @
ad0ad30d
...
...
@@ -16,7 +16,7 @@ import * as path from 'path'
import
{
Config
,
HeadName
,
Puppet
Typ
e
,
Puppet
Nam
e
,
Sayable
}
from
'
./config
'
...
...
@@ -31,9 +31,9 @@ import UtilLib from './util-lib'
import
log
from
'
./brolog-env
'
export
type
Wechaty
Setting
=
{
export
type
Puppet
Setting
=
{
head
?:
HeadName
type
?:
PuppetTyp
e
puppet
?:
PuppetNam
e
profile
?:
string
}
...
...
@@ -59,7 +59,7 @@ export class Wechaty extends EventEmitter implements Sayable {
public
uuid
:
string
public
static
instance
(
setting
?:
Wechaty
Setting
)
{
public
static
instance
(
setting
?:
Puppet
Setting
)
{
if
(
setting
&&
this
.
_instance
)
{
throw
new
Error
(
'
there has already a instance. no params will be allowed any more
'
)
}
...
...
@@ -69,12 +69,12 @@ export class Wechaty extends EventEmitter implements Sayable {
return
this
.
_instance
}
private
constructor
(
private
setting
:
Wechaty
Setting
=
{})
{
private
constructor
(
private
setting
:
Puppet
Setting
=
{})
{
super
()
log
.
verbose
(
'
Wechaty
'
,
'
contructor()
'
)
setting
.
head
=
setting
.
head
||
Config
.
head
setting
.
type
=
setting
.
type
||
Config
.
puppet
setting
.
puppet
=
setting
.
puppet
||
Config
.
puppet
setting
.
profile
=
setting
.
profile
||
Config
.
profile
// setting.port = setting.port || Config.port
...
...
@@ -90,7 +90,7 @@ export class Wechaty extends EventEmitter implements Sayable {
this
.
uuid
=
UtilLib
.
guid
()
}
public
toString
()
{
return
'
Class Wechaty(
'
+
this
.
setting
.
type
+
'
)
'
}
public
toString
()
{
return
'
Class Wechaty(
'
+
this
.
setting
.
puppet
+
'
)
'
}
public
version
(
forceNpm
=
false
)
{
const
dotGitPath
=
path
.
join
(
__dirname
,
'
..
'
,
'
.git
'
)
// `/src/../.git`
...
...
@@ -148,7 +148,7 @@ export class Wechaty extends EventEmitter implements Sayable {
public
async
init
():
Promise
<
this
>
{
log
.
info
(
'
Wechaty
'
,
'
v%s initializing...
'
,
this
.
version
())
log
.
verbose
(
'
Wechaty
'
,
'
puppet: %s
'
,
this
.
setting
.
type
)
log
.
verbose
(
'
Wechaty
'
,
'
puppet: %s
'
,
this
.
setting
.
puppet
)
log
.
verbose
(
'
Wechaty
'
,
'
head: %s
'
,
this
.
setting
.
head
)
log
.
verbose
(
'
Wechaty
'
,
'
profile: %s
'
,
this
.
setting
.
profile
)
log
.
verbose
(
'
Wechaty
'
,
'
uuid: %s
'
,
this
.
uuid
)
...
...
@@ -184,7 +184,7 @@ export class Wechaty extends EventEmitter implements Sayable {
public
on
(
event
:
'
EVENT_PARAM_ERROR
'
,
listener
:
()
=>
void
):
this
public
on
(
event
:
WechatyEventName
,
listener
:
Function
):
this
{
log
.
verbose
(
'
Wechaty
'
,
'
on
(%s, %s)
'
,
event
,
typeof
listener
)
log
.
verbose
(
'
Wechaty
'
,
'
addListener
(%s, %s)
'
,
event
,
typeof
listener
)
// const thisWithSay: Sayable = {
// say: (content: string) => {
...
...
@@ -210,7 +210,7 @@ export class Wechaty extends EventEmitter implements Sayable {
throw
new
Error
(
'
no head
'
)
}
switch
(
this
.
setting
.
type
)
{
switch
(
this
.
setting
.
puppet
)
{
case
'
web
'
:
puppet
=
new
PuppetWeb
({
head
:
this
.
setting
.
head
...
...
@@ -219,7 +219,7 @@ export class Wechaty extends EventEmitter implements Sayable {
break
default
:
throw
new
Error
(
'
Puppet unsupport(yet?):
'
+
this
.
setting
.
type
)
throw
new
Error
(
'
Puppet unsupport(yet?):
'
+
this
.
setting
.
puppet
)
}
const
eventList
:
WechatyEventName
[]
=
[
...
...
test/webdriver.spec.ts
浏览文件 @
ad0ad30d
...
...
@@ -12,7 +12,7 @@ import {
}
from
'
../src/puppet-web/
'
/**
* WHY
USE test.serial
* WHY
force to use SERIAL mode
*
* serial here is because we are checking browser pids inside test.
* if 2 tests run parallel in the same process,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录