提交 e27182b4 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

Merge branch 'master' of github.com:zixia/wechaty

......@@ -3,7 +3,7 @@
Connecting ChatBots.
Wechaty is a Bot Library for Wechat **Personal** Account.
Wechaty is a Bot Framework for Wechat **Personal** Account.
> Easy creating personal account wechat robot in 9 lines of code.
......
......@@ -37,6 +37,8 @@ class Message {
, self: undefined // to store the logined user id
}
// FIXME: has ther any better method to know the room ID?
if (rawObj.MMIsChatRoom) {
if (/^@@/.test(rawObj.FromUserName)) {
obj.room = rawObj.FromUserName // MMPeerUserName always eq FromUserName ?
......@@ -52,6 +54,9 @@ class Message {
return obj
}
toString() {
return htmlUtil.plainText(this.obj.content)
}
toStringDigest() {
const text = htmlUtil.digestEmoji(this.obj.digest)
return '{' + this.type() + '}' + text
}
......
......@@ -97,22 +97,27 @@ class Browser extends EventEmitter {
}
getPhantomJsDriver() {
// https://github.com/SeleniumHQ/selenium/issues/2069
// setup custom phantomJS capability
// setup custom phantomJS capability https://github.com/SeleniumHQ/selenium/issues/2069
const phantomjsExe = require('phantomjs-prebuilt').path
// const phantomjsExe = require('phantomjs2').path
const customPhantom = WebDriver.Capabilities.phantomjs()
.setAlertBehavior('ignore')
.set('phantomjs.binary.path', phantomjsExe)
.set('phantomjs.cli.args', [
const phantomjsArgs = [
'--ignore-ssl-errors=true' // this help socket.io connect with localhost
, '--load-images=false'
, '--remote-debugger-port=8080'
// , '--webdriver-logfile=/tmp/wd.log'
// , '--webdriver-loglevel=DEBUG'
])
]
if (/silly|verbose/i.test(process.env.WECHATY_DEBUG)) {
phantomjsArgs.push('--remote-debugger-port=8080') // XXX: be careful when in production usage.
}
const customPhantom = WebDriver.Capabilities.phantomjs()
.setAlertBehavior('ignore')
.set('phantomjs.binary.path', phantomjsExe)
.set('phantomjs.cli.args', phantomjsArgs)
log.silly('PuppetWebBrowser', 'phantomjs binary: ' + phantomjsExe)
log.silly('PuppetWebBrowser', 'phantomjs args: ' + phantomjsArgs.join(' '))
return new WebDriver.Builder()
.withCapabilities(customPhantom)
......@@ -156,9 +161,11 @@ class Browser extends EventEmitter {
const max = 15
const backoff = 100
// max = (2*totalTime/backoff) ^ (1/2)
// timeout = 11250 for {max: 15, backoff: 100}
// timeout = 45000 for {max: 30, backoff: 100}
/**
* max = (2*totalTime/backoff) ^ (1/2)
* timeout = 11250 for {max: 15, backoff: 100}
* timeout = 45000 for {max: 30, backoff: 100}
*/
const timeout = max * (backoff * max) / 2
return retryPromise({ max: max, backoff: backoff }, attempt => {
......@@ -213,10 +220,12 @@ class Browser extends EventEmitter {
return this.addCookies(c)
})
}
// convert expiry from seconds to milliseconds. https://github.com/SeleniumHQ/selenium/issues/2245
// with selenium-webdriver v2.53.2
// NOTICE: the lastest branch of selenium-webdriver for js has changed the interface of addCookie:
// https://github.com/SeleniumHQ/selenium/commit/02f407976ca1d516826990f11aca7de3c16ba576
/**
* convert expiry from seconds to milliseconds. https://github.com/SeleniumHQ/selenium/issues/2245
* with selenium-webdriver v2.53.2
* NOTICE: the lastest branch of selenium-webdriver for js has changed the interface of addCookie:
* https://github.com/SeleniumHQ/selenium/commit/02f407976ca1d516826990f11aca7de3c16ba576
*/
if (cookie.expiry) { cookie.expiry = cookie.expiry * 1000 /* XXX: be aware of new version of webdriver */}
log.silly('PuppetWebBrowser', 'addCookies("%s", "%s", "%s", "%s", "%s", "%s")'
......
......@@ -39,6 +39,7 @@ return (function(port) {
, socket: null
, eventsBuf: []
, scanCode: null
, heartBeatTimmer: null
}
// funcs
......@@ -109,17 +110,22 @@ return (function(port) {
checkScan()
heartBeat()
heartBeat(true)
clog('inited!. ;-D')
Wechaty.vars.inited = true
return 'init: success'
}
function heartBeat() {
function heartBeat(firstTime) {
var TIMEOUT = 15000 // 15s
if (firstTime && Wechaty.vars.heartBeatTimmer) {
Wechaty.log('heartBeat timer exist when 1st time is true? return for do nothing')
return
}
Wechaty.emit('ding', 'heartbeat@browser')
setTimeout(heartBeat, TIMEOUT)
Wechaty.vars.heartBeatTimmer = setTimeout(heartBeat, TIMEOUT)
return TIMEOUT
}
function glueAngular() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册