fix: reconnect while disconnect only while error

This commit is contained in:
Tristan Yang
2022-10-25 11:40:41 +08:00
parent 82cdd6a66d
commit 0560170484
3 changed files with 21 additions and 11 deletions
+12 -2
View File
@@ -82,9 +82,19 @@ export default function useStreaming() {
initialized = true;
};
SSE.onerror = (err) => {
console.error("sse error", err);
const { readyState } = err.target as EventSource;
console.error("sse error", readyState);
// 连接还处于开启或正在连接状态
if (readyState === EventSource.OPEN || readyState === EventSource.CONNECTING) {
return;
}
initializing = false;
// 正常的关闭
if (readyState === EventSource.CLOSED) {
initialized = false;
return;
}
// 非正常状态,目前未知
stopStreaming();
if (inter) {
clearTimeout(inter);