Browse Source

fix: 修复主动关闭socket定时器仍运行问题

master
leirensheng 5 years ago
parent
commit
82a8731934
  1. 8
      src/controllers/server.js

8
src/controllers/server.js

@ -26,6 +26,7 @@ const server = {
updateImageUrl: null, updateImageUrl: null,
title: null, title: null,
loadSheetUrl: null, loadSheetUrl: null,
retryTimer:null,
allowUpdate: false, //共享编辑模式 allowUpdate: false, //共享编辑模式
historyParam: function(data, sheetIndex, range) { historyParam: function(data, sheetIndex, range) {
let _this = this; let _this = this;
@ -162,7 +163,7 @@ const server = {
_this.wxErrorCount = 0; _this.wxErrorCount = 0;
//防止websocket长时间不发送消息导致断连 //防止websocket长时间不发送消息导致断连
setInterval(function(){ _this.retryTimer = setInterval(function(){
_this.websocket.send("rub"); _this.websocket.send("rub");
}, 60000); }, 60000);
} }
@ -322,7 +323,10 @@ const server = {
//连接关闭时触发 //连接关闭时触发
_this.websocket.onclose = function(e){ _this.websocket.onclose = function(e){
console.info(locale().websocket.close); console.info(locale().websocket.close);
if(e.code!==1000){ if(e.code === 1000){
clearInterval(_this.retryTimer)
_this.retryTimer = null
}else{
alert(locale().websocket.contact); alert(locale().websocket.contact);
} }
} }

Loading…
Cancel
Save