Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
fix: 修复主动关闭socket定时器仍运行问题
Browse files Browse the repository at this point in the history
  • Loading branch information
leirensheng committed Dec 15, 2020
1 parent 94e0020 commit 82a8731
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/controllers/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const server = {
updateUrl: null,
updateImageUrl: null,
title: null,
loadSheetUrl: null,
loadSheetUrl: null,
retryTimer:null,
allowUpdate: false, //共享编辑模式
historyParam: function(data, sheetIndex, range) {
let _this = this;
Expand Down Expand Up @@ -162,7 +163,7 @@ const server = {
_this.wxErrorCount = 0;

//防止websocket长时间不发送消息导致断连
setInterval(function(){
_this.retryTimer = setInterval(function(){
_this.websocket.send("rub");
}, 60000);
}
Expand Down Expand Up @@ -322,7 +323,10 @@ const server = {
//连接关闭时触发
_this.websocket.onclose = function(e){
console.info(locale().websocket.close);
if(e.code!==1000){
if(e.code === 1000){
clearInterval(_this.retryTimer)
_this.retryTimer = null
}else{
alert(locale().websocket.contact);
}
}
Expand Down

0 comments on commit 82a8731

Please sign in to comment.