Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
af5473d4
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,发现更多精彩内容 >>
提交
af5473d4
编写于
10月 10, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#40 Typescript transition step 22: fix bridge.ts & tslint
上级
c283e571
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
54 addition
and
46 deletion
+54
-46
src/puppet-web/bridge.ts
src/puppet-web/bridge.ts
+54
-46
未找到文件。
src/puppet-web/bridge.ts
浏览文件 @
af5473d4
/**
*
* Wechaty - Wechat for Bot, and human who talk to bot.
*
* Inject this js code to browser,
* in order to interactive with wechat web program.
*
* Licenst: MIT
* https://github.com/zixia/wechaty-lib
*
*/
// const co = require('co')
*
* Wechaty - Wechat for Bot, and human who talk to bot.
*
* Inject this js code to browser,
* in order to interactive with wechat web program.
*
* Licenst: MIT
* https://github.com/zixia/wechaty-lib
*
*/
/* tslint:disable:no-var-requires */
const
retryPromise
=
require
(
'
retry-promise
'
).
default
import
log
from
'
../brolog-env
'
import
log
from
'
../brolog-env
'
import
PuppetWeb
from
'
./puppet-web
'
class
Bridge
{
constructor
(
options
)
{
if
(
!
options
||
!
options
.
puppet
)
{
throw
new
Error
(
'
Bridge need a puppet
'
)
constructor
(
private
puppet
:
PuppetWeb
,
private
port
:
number
)
{
if
(
!
puppet
||
!
port
)
{
throw
new
Error
(
'
Bridge need puppet & port
'
)
}
log
.
verbose
(
'
PuppetWebBridge
'
,
'
new Bridge({puppet: %s, port: %s})
'
,
options
.
puppet
.
constructor
.
name
,
options
.
port
,
puppet
.
constructor
.
name
,
port
)
this
.
puppet
=
options
.
puppet
this
.
port
=
options
.
port
||
8788
// W(87) X(88), ascii char code ;-]
}
toString
()
{
return
`Bridge({puppet:
${
this
.
puppet
.
constructor
.
name
}
, port:
${
this
.
port
}
})`
}
init
()
{
public
toString
()
{
return
`Bridge({puppet:
${
this
.
puppet
.
constructor
.
name
}
, port:
${
this
.
port
}
})`
}
public
async
init
():
Promise
<
Bridge
>
{
log
.
verbose
(
'
PuppetWebBridge
'
,
'
init()
'
)
const
max
=
15
...
...
@@ -66,7 +70,7 @@ class Bridge {
})
}
inject
()
{
private
inject
():
Promise
<
any
>
{
log
.
verbose
(
'
PuppetWebBridge
'
,
'
inject()
'
)
return
co
.
call
(
this
,
function
*
()
{
...
...
@@ -90,7 +94,7 @@ class Bridge {
}
const
r
=
yield
this
.
ding
(
'
inject()
'
)
if
(
r
!==
'
inject()
'
)
{
if
(
r
!==
'
inject()
'
)
{
throw
new
Error
(
'
fail to get right return from call ding()
'
)
}
log
.
silly
(
'
PuppetWebBridge
'
,
'
inject() ding success
'
)
...
...
@@ -102,7 +106,8 @@ class Bridge {
throw
e
})
}
getInjectio
()
{
public
getInjectio
():
string
{
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
...
...
@@ -118,7 +123,7 @@ class Bridge {
+
'
; return rejectioReturnValue
'
}
logout
()
{
public
logout
():
Promise
<
all
>
{
log
.
verbose
(
'
PuppetWebBridge
'
,
'
quit()
'
)
return
this
.
proxyWechaty
(
'
logout
'
)
.
catch
(
e
=>
{
...
...
@@ -126,7 +131,8 @@ class Bridge {
throw
e
})
}
quit
()
{
public
quit
():
Promise
<
void
>
{
log
.
verbose
(
'
PuppetWebBridge
'
,
'
quit()
'
)
return
this
.
proxyWechaty
(
'
quit
'
)
.
catch
(
e
=>
{
...
...
@@ -135,7 +141,7 @@ class Bridge {
})
}
getUserName
()
{
public
getUserName
():
Promise
<
string
>
{
return
this
.
proxyWechaty
(
'
getUserName
'
)
.
catch
(
e
=>
{
log
.
error
(
'
PuppetWebBridge
'
,
'
getUserName() exception: %s
'
,
e
.
message
)
...
...
@@ -143,7 +149,7 @@ class Bridge {
})
}
contactFind
(
filterFunction
)
{
public
contactFind
(
filterFunction
):
Promise
<
string
[]
>
{
return
this
.
proxyWechaty
(
'
contactFindAsync
'
,
filterFunction
)
.
catch
(
e
=>
{
log
.
error
(
'
PuppetWebBridge
'
,
'
contactFindAsync() exception: %s
'
,
e
.
message
)
...
...
@@ -151,7 +157,7 @@ class Bridge {
})
}
roomFind
(
filterFunction
)
{
public
roomFind
(
filterFunction
):
Promise
<
string
[]
>
{
return
this
.
proxyWechaty
(
'
roomFind
'
,
filterFunction
)
.
catch
(
e
=>
{
log
.
error
(
'
PuppetWebBridge
'
,
'
roomFind() exception: %s
'
,
e
.
message
)
...
...
@@ -159,7 +165,7 @@ class Bridge {
})
}
roomDelMember
(
roomId
,
contactId
)
{
public
roomDelMember
(
roomId
,
contactId
):
Promise
<
void
>
{
if
(
!
roomId
||
!
contactId
)
{
throw
new
Error
(
'
no roomId or contactId
'
)
}
...
...
@@ -171,7 +177,7 @@ class Bridge {
})
}
roomAddMember
(
roomId
,
contactId
)
{
public
roomAddMember
(
roomId
,
contactId
):
Promise
<
void
>
{
log
.
verbose
(
'
PuppetWebBridge
'
,
'
roomAddMember(%s, %s)
'
,
roomId
,
contactId
)
if
(
!
roomId
||
!
contactId
)
{
...
...
@@ -184,7 +190,7 @@ class Bridge {
})
}
roomModTopic
(
roomId
,
topic
)
{
public
roomModTopic
(
roomId
,
topic
):
Promise
<
void
>
{
if
(
!
roomId
)
{
throw
new
Error
(
'
no roomId
'
)
}
...
...
@@ -196,19 +202,19 @@ class Bridge {
})
}
roomCreate
(
contactIdList
)
{
public
roomCreate
(
contactIdList
:
string
[],
topic
?:
string
):
Promise
<
string
>
{
if
(
!
contactIdList
||
!
Array
.
isArray
(
contactIdList
))
{
throw
new
Error
(
'
no valid contactIdList
'
)
}
return
this
.
proxyWechaty
(
'
roomCreateAsync
'
,
contactIdList
)
return
this
.
proxyWechaty
(
'
roomCreateAsync
'
,
contactIdList
,
topic
)
.
catch
(
e
=>
{
log
.
error
(
'
PuppetWebBridge
'
,
'
roomCreate(%s) exception: %s
'
,
contactIdList
,
e
.
message
)
throw
e
})
}
verifyUserRequest
(
contactId
,
hello
)
{
public
verifyUserRequest
(
contactId
,
hello
):
Promise
<
void
>
{
log
.
verbose
(
'
PuppetWebBridge
'
,
'
verifyUserRequest(%s, %s)
'
,
contactId
,
hello
)
if
(
!
contactId
)
{
...
...
@@ -221,7 +227,7 @@ class Bridge {
})
}
verifyUserOk
(
contactId
,
ticket
)
{
public
verifyUserOk
(
contactId
,
ticket
):
Promise
<
void
>
{
log
.
verbose
(
'
PuppetWebBridge
'
,
'
verifyUserOk(%s, %s)
'
,
contactId
,
ticket
)
if
(
!
contactId
||
!
ticket
)
{
...
...
@@ -234,7 +240,7 @@ class Bridge {
})
}
send
(
toUserName
,
content
)
{
public
send
(
toUserName
,
content
):
Promise
<
void
>
{
return
this
.
proxyWechaty
(
'
send
'
,
toUserName
,
content
)
.
catch
(
e
=>
{
log
.
error
(
'
PuppetWebBridge
'
,
'
send() exception: %s
'
,
e
.
message
)
...
...
@@ -242,15 +248,16 @@ class Bridge {
})
}
getMsgImg
(
id
)
{
public
getMsgImg
(
id
):
Promise
<
string
>
{
return
this
.
proxyWechaty
(
'
getMsgImg
'
,
id
)
.
catch
(
e
=>
{
log
.
silly
(
'
PuppetWebBridge
'
,
'
proxyWechaty(getMsgImg, %d) exception: %s
'
,
id
,
e
.
message
)
throw
e
})
}
getContact
(
id
)
{
if
(
id
!==
id
)
{
// NaN
public
getContact
(
id
:
string
):
Promise
<
string
>
{
if
(
id
!==
id
)
{
// NaN
const
err
=
new
Error
(
'
NaN! where does it come from?
'
)
log
.
error
(
'
PuppetWebBridge
'
,
'
getContact(NaN): %s
'
,
err
)
return
Promise
.
reject
(
err
)
...
...
@@ -290,7 +297,7 @@ class Bridge {
/**
* Proxy Call to Wechaty in Bridge
*/
pr
oxyWechaty
(
wechatyFunc
,
...
args
)
{
pr
ivate
proxyWechaty
(
wechatyFunc
,
...
args
):
Promise
<
any
>
{
const
argsEncoded
=
new
Buffer
(
encodeURIComponent
(
JSON
.
stringify
(
args
)
...
...
@@ -339,7 +346,7 @@ class Bridge {
/**
* call REAL browser excute for other methods
*/
execute
(
script
,
...
args
)
{
private
execute
(
script
,
...
args
):
Promise
<
any
>
{
if
(
!
this
.
puppet
||
!
this
.
puppet
.
browser
)
{
return
Promise
.
reject
(
new
Error
(
'
execute(): no puppet or no puppet.browser in bridge
'
))
}
...
...
@@ -350,7 +357,7 @@ class Bridge {
})
}
executeAsync
(
script
,
...
args
)
{
private
executeAsync
(
script
,
...
args
):
Promise
<
any
>
{
if
(
!
this
.
puppet
||
!
this
.
puppet
.
browser
)
{
return
Promise
.
reject
(
new
Error
(
'
execute(): no puppet or no puppet.browser in bridge
'
))
}
...
...
@@ -361,7 +368,7 @@ class Bridge {
})
}
ding
(
data
)
{
public
ding
(
data
):
Promise
<
any
>
{
return
this
.
proxyWechaty
(
'
ding
'
,
data
)
.
catch
(
e
=>
{
log
.
error
(
'
PuppetWebBridge
'
,
'
ding(%s) exception: %s
'
,
data
,
e
.
message
)
...
...
@@ -373,6 +380,8 @@ class Bridge {
// module.exports = Bridge
export
default
Bridge
/* tslint:disable:jsdoc-format */
/* tslint:disable:max-line-length */
/**
*
* some handy browser javascript snips
...
...
@@ -402,7 +411,6 @@ ng-src="/cgi-bin/mmwebwx-bin/webwxgetmsgimg?&MsgID=6944236226252183282&s
src="/cgi-bin/mmwebwx-bin/webwxgetmsgimg?&MsgID=6944236226252183282&skey=%40crypt_c117402d_2b2a8c58340c8f4b0a4570cb8f11a1e8&type=slave"
style="height: 100px; width: 75px;">
XMLHttpRequestOrig = XMLHttpRequest
XMLHttpRequest = function() { return new XMLHttpRequestOrig() }
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录