Skip to content

Commit

Permalink
fix: websocket 重连次数改为2次
Browse files Browse the repository at this point in the history
  • Loading branch information
shinny-mayanqiong committed Jan 19, 2020
1 parent 25b4a03 commit 38778e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 7 additions & 1 deletion .release-it.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"git": {
"tagName": "v${version}"
},
"npm": {
"publish": true
},
"github": {
"release": true,
"assets": ["./dist/umd/tqsdk-browser.min.js"]
"assets": ["./dist/umd/tqsdk-browser.js", "./dist/umd/tqsdk-browser.min.js"]
}
}
10 changes: 5 additions & 5 deletions src/tqwebsocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class TqWebsocket extends EventEmitter {
CLOSED: 3
}

this.__init()
this.__init(false)
}

// string or object
Expand All @@ -65,10 +65,10 @@ class TqWebsocket extends EventEmitter {
return this.ws.readyState === WebSocket.OPEN
}

__init () {
__init (isReconnection = true) {
this.ws = new WebSocket(this.urlList[this.reconnectUrlIndex])

if (this.reconnectUrlIndex === this.urlList.length - 1) {
if (isReconnection && this.reconnectUrlIndex === this.urlList.length - 1) {
// urlList 循环尝试重连一轮, times += 1
this.reconnectTimes += 1
}
Expand Down Expand Up @@ -101,7 +101,7 @@ class TqWebsocket extends EventEmitter {
if (_this.ws.readyState === 3) {
// 每次重连的时候设置 _this.reconnectUrlIndex
_this.reconnectUrlIndex = (_this.reconnectUrlIndex + 1) < _this.urlList.length ? _this.reconnectUrlIndex + 1 : 0
_this.__init()
_this.__init(true)
_this.emit('reconnect', {
msg: '发起重连第 ' + _this.reconnectTimes + ' 次'
})
Expand All @@ -120,7 +120,7 @@ class TqWebsocket extends EventEmitter {
_this.emit('open', {
msg: '发起重连第 ' + _this.reconnectTimes + ' 次, 成功'
})
_this.reconnectTimes = 0
// _this.reconnectTimes = 0
_this.reconnectUrlIndex = 0
if (this.reconnectTask) {
clearTimeout(_this.reconnectTask)
Expand Down

0 comments on commit 38778e8

Please sign in to comment.