perf: 优化客户端生命周期重连ws机制

This commit is contained in:
kuaifan 2022-05-21 19:40:34 +08:00
parent 6a2f1f80f5
commit 2ab12f74ee
2 changed files with 22 additions and 5 deletions

View File

@ -33,6 +33,7 @@ export default {
created() {
this.electronEvents();
this.eeuiEvents();
},
mounted() {
@ -82,7 +83,7 @@ export default {
handler() {
this.$store.dispatch("websocketConnection");
//
if (this.$isEEUiApp) {
if (this.$isEEUiApp && this.userId > 0) {
setTimeout(_ => {
const webview = requireModuleJs("webview");
webview && webview.sendMessage({
@ -220,6 +221,22 @@ export default {
this.$store.dispatch(action, data);
})
this.manifestUrl = $A.apiUrl("../manifest")
},
eeuiEvents() {
if (!this.$isEEUiApp) {
return;
}
//
window.__onPagePause = () => {
}
//
window.__onPageResume = (num) => {
if (num > 0) {
this.$store.state.ws === null && this.$store.dispatch("websocketConnection");
}
}
}
}
}

View File

@ -2201,11 +2201,11 @@ export default {
*/
websocketConnection({state, dispatch, commit}) {
clearTimeout(state.wsTimeout);
if (state.ws) {
state.ws.close();
state.ws = null;
}
if (state.userId === 0) {
if (state.ws) {
state.ws.close();
state.ws = null;
}
return;
}
//