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