防止多次重连

pull/23/head
陶士涵 4 years ago
parent 88db962f50
commit 796ae971e7

@ -16,10 +16,12 @@ new Vue({
timer:null, timer:null,
sendDisabled:false, sendDisabled:false,
flyLang:GOFLY_LANG[LANG], flyLang:GOFLY_LANG[LANG],
connecting:true,
}, },
methods: { methods: {
//初始化websocket //初始化websocket
initConn:function() { initConn:function() {
this.connecting=true;
let socket = new ReconnectingWebSocket(this.server+"?visitor_id="+this.visitor.visitor_id);//创建Socket实例 let socket = new ReconnectingWebSocket(this.server+"?visitor_id="+this.visitor.visitor_id);//创建Socket实例
socket.maxReconnectAttempts = 30; socket.maxReconnectAttempts = 30;
this.socket = socket this.socket = socket
@ -31,6 +33,8 @@ new Vue({
}, },
OnOpen:function() { OnOpen:function() {
this.chatTitle=GOFLY_LANG[LANG]['connectok']; this.chatTitle=GOFLY_LANG[LANG]['connectok'];
this.connecting=false;
}, },
OnMessage:function(e) { OnMessage:function(e) {
const redata = JSON.parse(e.data); const redata = JSON.parse(e.data);
@ -357,6 +361,9 @@ new Vue({
$('.faceBox').hide(); $('.faceBox').hide();
}); });
window.onfocus = function () { window.onfocus = function () {
if(_this.connecting=true){
return;
}
_this.initConn(); _this.initConn();
} }
}, },

Loading…
Cancel
Save