mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-14 21:02:49 +00:00
perf: 优化websocket连接机制
This commit is contained in:
parent
813a49bf67
commit
9a0a04ed76
@ -668,6 +668,13 @@ export default {
|
||||
immediate: true
|
||||
},
|
||||
|
||||
userId: {
|
||||
handler() {
|
||||
this.$store.dispatch("websocketConnection")
|
||||
},
|
||||
immediate: true
|
||||
},
|
||||
|
||||
wsMsg: {
|
||||
handler(info) {
|
||||
const {type, action} = info;
|
||||
|
||||
@ -126,6 +126,7 @@ export default {
|
||||
return true
|
||||
}
|
||||
}
|
||||
this.$store.dispatch("websocketConnection")
|
||||
}
|
||||
},
|
||||
|
||||
@ -269,10 +270,6 @@ export default {
|
||||
this.loadContent--;
|
||||
this.contentDetail = data.content;
|
||||
this.updateBak();
|
||||
//
|
||||
if (this.$isSubElectron) {
|
||||
this.$store.dispatch("websocketConnection")
|
||||
}
|
||||
}).catch(({msg}) => {
|
||||
$A.modalError(msg);
|
||||
this.loadIng--;
|
||||
|
||||
13
resources/assets/js/store/actions.js
vendored
13
resources/assets/js/store/actions.js
vendored
@ -277,7 +277,6 @@ export default {
|
||||
state.userIsAdmin = $A.inArray('admin', userInfo.identity);
|
||||
$A.setStorage("userInfo", state.userInfo);
|
||||
dispatch("getBasicData");
|
||||
dispatch("websocketConnection");
|
||||
resolve()
|
||||
});
|
||||
},
|
||||
@ -2170,6 +2169,9 @@ export default {
|
||||
url = url.replace("http://", "ws://");
|
||||
url += "?action=web&token=" + state.userToken;
|
||||
//
|
||||
const wsRandom = $A.randomString(16);
|
||||
state.wsRandom = wsRandom;
|
||||
//
|
||||
state.ws = new WebSocket(url);
|
||||
state.ws.onopen = (e) => {
|
||||
// console.log("[WS] Open", $A.formatDate())
|
||||
@ -2181,7 +2183,7 @@ export default {
|
||||
//
|
||||
clearTimeout(state.wsTimeout);
|
||||
state.wsTimeout = setTimeout(() => {
|
||||
dispatch('websocketConnection');
|
||||
wsRandom === state.wsRandom && dispatch('websocketConnection');
|
||||
}, 3000);
|
||||
};
|
||||
state.ws.onerror = (e) => {
|
||||
@ -2190,7 +2192,7 @@ export default {
|
||||
//
|
||||
clearTimeout(state.wsTimeout);
|
||||
state.wsTimeout = setTimeout(() => {
|
||||
dispatch('websocketConnection');
|
||||
wsRandom === state.wsRandom && dispatch('websocketConnection');
|
||||
}, 3000);
|
||||
};
|
||||
state.ws.onmessage = (e) => {
|
||||
@ -2453,6 +2455,9 @@ export default {
|
||||
* @param state
|
||||
*/
|
||||
websocketClose({state}) {
|
||||
state.ws && state.ws.close();
|
||||
if (state.ws) {
|
||||
state.ws.close();
|
||||
state.ws = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1
resources/assets/js/store/state.js
vendored
1
resources/assets/js/store/state.js
vendored
@ -43,6 +43,7 @@ const stateData = {
|
||||
wsMsg: {},
|
||||
wsCall: {},
|
||||
wsTimeout: null,
|
||||
wsRandom: 0,
|
||||
wsOpenNum: 0,
|
||||
wsListener: {},
|
||||
wsReadTimeout: null,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user