chore: audio page keepalive

This commit is contained in:
jialin
2024-12-31 11:04:30 +08:00
parent aed7267253
commit e4b1dfc77a
13 changed files with 65 additions and 22 deletions
+10 -4
View File
@@ -8,7 +8,6 @@ const extractJSON = (dataStr: string) => {
if (!dataStr) {
return results;
}
while ((match = extractStreamRegx.exec(dataStr)) !== null) {
try {
const jsonData = JSON.parse(match[1]);
@@ -131,9 +130,16 @@ export const readStreamData = async (
let chunk = decoder.decode(value, { stream: true });
extractJSON(chunk).forEach((data) => {
callback?.(data);
});
if (chunk.startsWith('error:')) {
const errorStr = chunk.slice(7).trim();
const jsonData = JSON.parse(errorStr);
callback({ error: jsonData });
} else {
extractJSON(chunk).forEach((data) => {
callback?.(data);
});
}
await readStreamData(reader, decoder, callback);
};