perf: 优化SSE连接
This commit is contained in:
parent
5cae241ccc
commit
a4065674de
@ -13,8 +13,12 @@ export function connectToSSE(username) {
|
|||||||
});
|
});
|
||||||
eventSource.addEventListener('error', function (event) {
|
eventSource.addEventListener('error', function (event) {
|
||||||
eventSource.close()
|
eventSource.close()
|
||||||
connectToSSE(username)
|
|
||||||
});
|
});
|
||||||
|
// 清除定时器
|
||||||
|
if (timer) {
|
||||||
|
clearInterval(timer);
|
||||||
|
}
|
||||||
|
// 15s检测一次连接状态
|
||||||
timer = setInterval(() => {
|
timer = setInterval(() => {
|
||||||
if (eventSource.readyState === 2) {
|
if (eventSource.readyState === 2) {
|
||||||
connectToSSE(username);
|
connectToSSE(username);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user