chore: updates

This commit is contained in:
Tristan Yang
2023-07-26 16:36:12 +08:00
parent 927a3b7075
commit 32b4793aed
3 changed files with 7 additions and 13 deletions
+5 -10
View File
@@ -134,17 +134,18 @@ export default function useStreaming() {
SSE.onopen = () => {
ready = false;
//todo
// opened = true;
// connectionIsOpen = true;
};
SSE.onerror = (err) => {
// 断网了
if (!navigator.onLine) {
stopStreaming();
}
const { readyState } = err.target as EventSource;
console.error("sse error", readyState, err);
// 连接还处于开启状态
if (readyState === EventSource.OPEN || readyState === EventSource.CONNECTING) {
return;
}
console.info("sse error", readyState, err);
// 重连
keepAlive(2000);
};
@@ -438,12 +439,6 @@ export default function useStreaming() {
if (streamingReady) {
startStreaming();
}
return () => {
if (streamingReady) {
console.info("debug SSE: stopStreaming at effect");
stopStreaming();
}
};
}, [streamingReady]);
return {