Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wechaty
wechaty
提交
57b9e8ce
W
wechaty
项目概览
wechaty
/
wechaty
上一次同步 大约 3 年
通知
305
Star
10499
Fork
6
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
152
列表
看板
标记
里程碑
合并请求
1
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
152
Issue
152
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
57b9e8ce
编写于
8月 05, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean io code
上级
1578ace2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
15 addition
and
62 deletion
+15
-62
src/io-client.ts
src/io-client.ts
+8
-5
src/io.ts
src/io.ts
+7
-57
未找到文件。
src/io-client.ts
浏览文件 @
57b9e8ce
...
...
@@ -67,9 +67,12 @@ export class IoClient {
this
.
state
.
on
(
'
pending
'
)
try
{
await
this
.
initIo
()
await
this
.
startIo
()
await
this
.
hookWechaty
(
this
.
options
.
wechaty
)
this
.
state
.
on
(
true
)
}
catch
(
e
)
{
log
.
error
(
'
IoClient
'
,
'
init() exception: %s
'
,
e
.
message
)
this
.
state
.
off
(
true
)
...
...
@@ -96,11 +99,11 @@ export class IoClient {
return
}
private
async
ini
tIo
():
Promise
<
void
>
{
log
.
verbose
(
'
IoClient
'
,
'
ini
tIo() with token %s
'
,
this
.
options
.
token
)
private
async
star
tIo
():
Promise
<
void
>
{
log
.
verbose
(
'
IoClient
'
,
'
star
tIo() with token %s
'
,
this
.
options
.
token
)
if
(
this
.
state
.
off
())
{
const
e
=
new
Error
(
'
ini
tIo() state.off() is true, skipped
'
)
const
e
=
new
Error
(
'
star
tIo() state.off() is true, skipped
'
)
log
.
warn
(
'
IoClient
'
,
e
.
message
)
throw
e
}
...
...
@@ -108,7 +111,7 @@ export class IoClient {
try
{
await
this
.
io
.
start
()
}
catch
(
e
)
{
log
.
verbose
(
'
IoClient
'
,
'
ini
tIo() init fail: %s
'
,
e
.
message
)
log
.
verbose
(
'
IoClient
'
,
'
star
tIo() init fail: %s
'
,
e
.
message
)
throw
e
}
...
...
src/io.ts
浏览文件 @
57b9e8ce
...
...
@@ -75,10 +75,10 @@ interface IoEventAny {
type
IoEvent
=
IoEventScan
|
IoEventAny
export
class
Io
{
private
readonly
cuid
:
string
private
readonly
id
:
string
private
readonly
protocol
:
string
private
eventBuffer
:
IoEvent
[]
=
[]
private
ws
:
undefined
|
WebSocket
private
eventBuffer
:
IoEvent
[]
=
[]
private
ws
:
undefined
|
WebSocket
private
readonly
state
=
new
StateSwitch
(
'
Io
'
,
log
)
...
...
@@ -97,14 +97,14 @@ export class Io {
options
.
apihost
=
options
.
apihost
||
config
.
apihost
options
.
protocol
=
options
.
protocol
||
config
.
default
.
DEFAULT_PROTOCOL
this
.
cu
id
=
options
.
wechaty
.
id
this
.
id
=
options
.
wechaty
.
id
this
.
protocol
=
options
.
protocol
+
'
|
'
+
options
.
wechaty
.
id
log
.
verbose
(
'
Io
'
,
'
instantiated with apihost[%s], token[%s], protocol[%s], cuid[%s]
'
,
options
.
apihost
,
options
.
token
,
options
.
protocol
,
this
.
cu
id
,
this
.
id
,
)
}
...
...
@@ -161,7 +161,7 @@ export class Io {
const
wechaty
=
this
.
options
.
wechaty
wechaty
.
on
(
'
error
'
,
error
=>
this
.
send
({
name
:
'
error
'
,
payload
:
error
}))
wechaty
.
on
(
'
heartbeat
'
,
data
=>
this
.
send
({
name
:
'
heartbeat
'
,
payload
:
{
cuid
:
this
.
cu
id
,
data
}
}))
wechaty
.
on
(
'
heartbeat
'
,
data
=>
this
.
send
({
name
:
'
heartbeat
'
,
payload
:
{
cuid
:
this
.
id
,
data
}
}))
wechaty
.
on
(
'
login
'
,
user
=>
this
.
send
({
name
:
'
login
'
,
payload
:
user
}))
wechaty
.
on
(
'
logout
'
,
user
=>
this
.
send
({
name
:
'
logout
'
,
payload
:
user
}))
wechaty
.
on
(
'
message
'
,
message
=>
this
.
ioMessage
(
message
))
...
...
@@ -170,56 +170,6 @@ export class Io {
// wechaty.on('scan', (url, code) => this.send({ name: 'scan', payload: { url, code } }))
wechaty
.
on
(
'
scan
'
,
(
qrcode
,
status
)
=>
this
.
send
({
name
:
'
scan
'
,
payload
:
{
qrcode
,
status
}
}
as
IoEventScan
))
// const hookEvents: WechatyEventName[] = [
// 'scan'
// , 'login'
// , 'logout'
// , 'heartbeat'
// , 'error'
// ]
// hookEvents.map(event => {
// wechaty.on(event, (data) => {
// const ioEvent: IoEvent = {
// name: event
// , payload: data
// }
// switch (event) {
// case 'login':
// case 'logout':
// if (data instanceof Contact) {
// // ioEvent.payload = data.obj
// ioEvent.payload = data
// }
// break
// case 'error':
// ioEvent.payload = data.toString()
// break
// case 'heartbeat':
// ioEvent.payload = {
// cuid: this.cuid
// , data: data
// }
// break
// default:
// break
// }
// this.send(ioEvent)
// })
// })
// wechaty.on('message', m => {
// const text = (m.room() ? '[' + m.room().topic() + ']' : '')
// + '<' + m.from().name() + '>'
// + ':' + m.toStringDigest()
// this.send({ name: 'message', payload: text })
// })
return
}
...
...
@@ -273,7 +223,7 @@ export class Io {
this
.
reconnectTimeout
=
undefined
const
name
=
'
sys
'
const
payload
=
'
Wechaty version
'
+
this
.
options
.
wechaty
.
version
()
+
` with CUID:
${
this
.
cu
id
}
`
const
payload
=
'
Wechaty version
'
+
this
.
options
.
wechaty
.
version
()
+
` with CUID:
${
this
.
id
}
`
const
initEvent
:
IoEvent
=
{
name
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录