Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.www.
wechaty
提交
c6265ca7
W
wechaty
项目概览
.www.
/
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,发现更多精彩内容 >>
提交
c6265ca7
编写于
10月 11, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#40 finally runable with ts-node!
上级
e5a92807
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
35 addition
and
25 deletion
+35
-25
src/config.ts
src/config.ts
+1
-1
src/puppet-web/bridge.ts
src/puppet-web/bridge.ts
+2
-1
src/puppet-web/puppet-web.ts
src/puppet-web/puppet-web.ts
+8
-6
src/puppet-web/watchdog.ts
src/puppet-web/watchdog.ts
+5
-5
src/room.ts
src/room.ts
+5
-5
src/util-lib.ts
src/util-lib.ts
+14
-7
未找到文件。
src/config.ts
浏览文件 @
c6265ca7
...
...
@@ -121,7 +121,7 @@ Config.puppetInstance = function(instance?: Puppet): Puppet {
type
WatchdogFood
=
{
data
:
any
,
type
?:
'
HEARTBEAT
'
|
'
POISON
'
,
type
?:
'
HEARTBEAT
'
|
'
POISON
'
|
'
SCAN
'
,
timeout
?:
number
// millisecond
}
...
...
src/puppet-web/bridge.ts
浏览文件 @
c6265ca7
...
...
@@ -191,12 +191,13 @@ class Bridge {
})
}
public
roomModTopic
(
roomId
,
topic
):
Promise
<
void
>
{
public
roomModTopic
(
roomId
,
topic
):
Promise
<
string
>
{
if
(
!
roomId
)
{
throw
new
Error
(
'
no roomId
'
)
}
return
this
.
proxyWechaty
(
'
roomModTopic
'
,
roomId
,
topic
)
.
then
(
_
=>
topic
)
.
catch
(
e
=>
{
log
.
error
(
'
PuppetWebBridge
'
,
'
roomModTopic(%s, %s) exception: %s
'
,
roomId
,
topic
,
e
.
message
)
throw
e
...
...
src/puppet-web/puppet-web.ts
浏览文件 @
c6265ca7
...
...
@@ -204,7 +204,7 @@ class PuppetWeb extends Puppet {
}
}
private
initBridge
()
{
private
initBridge
()
:
Promise
<
Bridge
>
{
log
.
verbose
(
'
PuppetWeb
'
,
'
initBridge()
'
)
const
bridge
=
new
Bridge
(
this
// use puppet instead of browser, is because browser might change(die) duaring run time
...
...
@@ -214,8 +214,9 @@ class PuppetWeb extends Puppet {
this
.
bridge
=
bridge
if
(
this
.
targetState
()
!==
'
live
'
)
{
log
.
warn
(
'
PuppetWeb
'
,
'
initBridge() found targetState != live, no init anymore
'
)
return
Promise
.
resolve
(
'
skipped
'
)
const
errMsg
=
'
initBridge() found targetState != live, no init anymore
'
log
.
warn
(
'
PuppetWeb
'
,
errMsg
)
return
Promise
.
reject
(
errMsg
)
}
return
bridge
.
init
()
...
...
@@ -231,7 +232,7 @@ class PuppetWeb extends Puppet {
})
}
private
initServer
()
{
private
initServer
()
:
Promise
<
Server
>
{
log
.
verbose
(
'
PuppetWeb
'
,
'
initServer()
'
)
const
server
=
new
Server
(
this
.
port
)
...
...
@@ -255,8 +256,9 @@ class PuppetWeb extends Puppet {
this
.
server
=
server
if
(
this
.
targetState
()
!==
'
live
'
)
{
log
.
warn
(
'
PuppetWeb
'
,
'
initServer() found targetState != live, no init anymore
'
)
return
Promise
.
resolve
(
'
skipped
'
)
const
errMsg
=
'
initServer() found targetState != live, no init anymore
'
log
.
warn
(
'
PuppetWeb
'
,
errMsg
)
return
Promise
.
reject
(
errMsg
)
}
return
server
.
init
()
...
...
src/puppet-web/watchdog.ts
浏览文件 @
c6265ca7
...
...
@@ -43,7 +43,7 @@ function onFeed(food: WatchdogFood) {
}
const
feed
=
`
${
food
.
type
}
:[
${
food
.
data
}
]`
log
.
silly
(
'
PuppetWebWatchdog
'
,
'
onFeed: %d, %s
'
,
timeout
,
feed
)
log
.
silly
(
'
PuppetWebWatchdog
'
,
'
onFeed: %d, %s
'
,
food
.
timeout
,
feed
)
if
(
this
.
currentState
()
===
'
killing
'
)
{
...
...
@@ -57,14 +57,14 @@ function onFeed(food: WatchdogFood) {
// return
// }
setWatchDogTimer
.
call
(
this
,
timeout
,
feed
)
setWatchDogTimer
.
call
(
this
,
food
.
timeout
,
feed
)
this
.
emit
(
'
heartbeat
'
,
feed
)
monitorScan
.
call
(
this
,
type
)
monitorScan
.
call
(
this
,
food
.
type
)
autoSaveSession
.
call
(
this
)
switch
(
type
)
{
switch
(
food
.
type
)
{
case
'
POISON
'
:
clearWatchDogTimer
.
call
(
this
)
break
...
...
@@ -74,7 +74,7 @@ function onFeed(food: WatchdogFood) {
break
default
:
throw
new
Error
(
'
Watchdog onFeed: unsupport type
'
+
type
)
throw
new
Error
(
'
Watchdog onFeed: unsupport type
'
+
food
.
type
)
}
}
...
...
src/room.ts
浏览文件 @
c6265ca7
...
...
@@ -212,7 +212,7 @@ class Room extends EventEmitter {
}
public
del
(
contact
:
Contact
):
Promise
<
number
>
{
log
.
verbose
(
'
Room
'
,
'
del(%s)
'
,
contact
)
log
.
verbose
(
'
Room
'
,
'
del(%s)
'
,
contact
.
name
()
)
if
(
!
contact
)
{
throw
new
Error
(
'
contact not found
'
)
...
...
@@ -223,12 +223,12 @@ class Room extends EventEmitter {
}
// @private
private
delLocal
(
contact
:
Contact
):
boolean
{
private
delLocal
(
contact
:
Contact
):
number
{
log
.
verbose
(
'
Room
'
,
'
delLocal(%s)
'
,
contact
)
const
memberList
=
this
.
obj
.
memberList
if
(
!
memberList
||
memberList
.
length
===
0
)
{
return
true
// already in refreshing
return
0
// already in refreshing
}
let
i
...
...
@@ -239,9 +239,9 @@ class Room extends EventEmitter {
}
if
(
i
<
memberList
.
length
)
{
memberList
.
splice
(
i
,
1
)
return
true
return
1
}
return
false
return
0
}
public
quit
()
{
...
...
src/util-lib.ts
浏览文件 @
c6265ca7
...
...
@@ -2,12 +2,19 @@ import * as http from 'http'
import
log
from
'
./brolog-env
'
/**
* bug compatible with:
* https://github.com/wechaty/wechaty/issues/40#issuecomment-252802084
*/
import
*
as
ws
from
'
ws
'
typeof
ws
class
UtilLib
{
public
static
stripHtml
(
html
)
{
public
static
stripHtml
(
html
:
string
):
string
{
return
String
(
html
).
replace
(
/
(
<
([^
>
]
+
)
>
)
/ig
,
''
)
}
public
static
unescapeHtml
(
str
)
{
public
static
unescapeHtml
(
str
:
string
):
string
{
return
String
(
str
)
.
replace
(
/'/g
,
"
'
"
)
.
replace
(
/"/g
,
'
"
'
)
...
...
@@ -16,7 +23,7 @@ class UtilLib {
.
replace
(
/&/g
,
'
&
'
)
}
public
static
digestEmoji
(
html
)
{
public
static
digestEmoji
(
html
:
string
):
string
{
return
String
(
html
)
.
replace
(
/<img class="
(\w
*
?
emoji
)
(\w
*
?
emoji
[^
"
]
+
?)
" text="
(
.*
?)
_web" src=
[^
>
]
+>/g
,
'
$3
'
...
...
@@ -26,7 +33,7 @@ class UtilLib {
)
// '<span class="emoji emoji1f334"></span>'
}
public
static
plainText
(
html
)
{
public
static
plainText
(
html
:
string
):
string
{
return
UtilLib
.
stripHtml
(
UtilLib
.
unescapeHtml
(
UtilLib
.
stripHtml
(
...
...
@@ -38,7 +45,7 @@ class UtilLib {
)
}
public
static
downloadStream
(
url
:
string
,
cookies
):
Promise
<
any
>
{
public
static
downloadStream
(
url
:
string
,
cookies
):
Promise
<
NodeJS
.
ReadableStream
>
{
// const myurl = 'http://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetmsgimg?&MsgID=3080011908135131569&skey=%40crypt_c117402d_53a58f8fbb21978167a3fc7d3be7f8c9'
url
=
url
.
replace
(
/^https/i
,
'
http
'
)
// use http for better performance
const
options
=
require
(
'
url
'
).
parse
(
url
)
...
...
@@ -78,7 +85,7 @@ class UtilLib {
}
// credit - http://stackoverflow.com/a/2117523/1123955
public
static
guid
()
{
public
static
guid
()
:
string
{
/* tslint:disable:no-bitwise */
return
'
xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
'
.
replace
(
/
[
xy
]
/g
,
function
(
c
)
{
const
r
=
Math
.
random
()
*
16
|
0
,
v
=
c
===
'
x
'
?
r
:
(
r
&
0x3
|
0x8
)
...
...
@@ -127,7 +134,7 @@ class UtilLib {
})
})
function
nextPort
(
newPort
:
number
)
{
function
nextPort
(
newPort
:
number
)
:
number
{
const
RANDOM_RANGE
=
1024
const
n
=
Math
.
floor
(
Math
.
random
()
*
RANDOM_RANGE
)
return
newPort
+
n
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录