|
@@ -193,7 +193,7 @@ function WsManager(url, opts) {
|
|
this.readyState = 'closed' //当前socket状态
|
|
this.readyState = 'closed' //当前socket状态
|
|
this.binaryType = opts.binaryType || 'blob' //数据传输类型
|
|
this.binaryType = opts.binaryType || 'blob' //数据传输类型
|
|
this._reconnectTimes = 0 //重连次数
|
|
this._reconnectTimes = 0 //重连次数
|
|
- this._reconnectionDelay = opts.reconnectionDelay || 1000 //重连延迟
|
|
|
|
|
|
+ this._reconnectionDelay = opts.reconnectionDelay || 3000 //重连延迟
|
|
this.reconnection(opts.reconnection !== false) // 是否自动重连
|
|
this.reconnection(opts.reconnection !== false) // 是否自动重连
|
|
this.reconnectionAttempts(opts.reconnectionAttempts || Infinity) //重连最大尝试次数
|
|
this.reconnectionAttempts(opts.reconnectionAttempts || Infinity) //重连最大尝试次数
|
|
this.timeout(null == opts.timeout ? 20000 : opts.timeout)
|
|
this.timeout(null == opts.timeout ? 20000 : opts.timeout)
|
|
@@ -221,7 +221,7 @@ WsManager.prototype.connect = function(fn) {
|
|
}
|
|
}
|
|
|
|
|
|
WsManager.prototype.reconnect = function() {
|
|
WsManager.prototype.reconnect = function() {
|
|
- clearInterval(this.keepAliveTimeout);
|
|
|
|
|
|
+ // clearInterval(this.keepAliveTimeout);
|
|
|
|
|
|
if(this._reconnectTimes < this._reconnectionAttempts) {
|
|
if(this._reconnectTimes < this._reconnectionAttempts) {
|
|
if(this.socket) {
|
|
if(this.socket) {
|
|
@@ -288,10 +288,10 @@ WsManager.prototype.openWxConnect = function() {
|
|
|
|
|
|
_socket.onClose((res) => {
|
|
_socket.onClose((res) => {
|
|
this.readyState = 'closed';
|
|
this.readyState = 'closed';
|
|
-
|
|
|
|
|
|
+ clearInterval(this.keepAliveTimeout);
|
|
//只要关闭就重连(暂时性处理)并且不是在后台 不进行重连
|
|
//只要关闭就重连(暂时性处理)并且不是在后台 不进行重连
|
|
if(this._reconnection && !Global.isOnHide ) {
|
|
if(this._reconnection && !Global.isOnHide ) {
|
|
- this.reconnect()
|
|
|
|
|
|
+ this.reconnect();
|
|
}
|
|
}
|
|
|
|
|
|
this.emit('close', res)
|
|
this.emit('close', res)
|
|
@@ -313,10 +313,11 @@ WsManager.prototype.openWxConnect = function() {
|
|
|
|
|
|
_socket.onError((res) => {
|
|
_socket.onError((res) => {
|
|
this.readyState = 'closed';
|
|
this.readyState = 'closed';
|
|
|
|
+ clearInterval(this.keepAliveTimeout);
|
|
if(this._reconnection && !Global.isOnHide) {
|
|
if(this._reconnection && !Global.isOnHide) {
|
|
- this.reconnect()
|
|
|
|
|
|
+ this.reconnect();
|
|
} else {
|
|
} else {
|
|
- _socket.close()
|
|
|
|
|
|
+ _socket.close();
|
|
}
|
|
}
|
|
|
|
|
|
this.emit('error', res.errMsg);
|
|
this.emit('error', res.errMsg);
|