Commit 3d095858 authored by Joel's avatar Joel

feat: api add eventtype pong message to avoid api return too slow and frontend ignore it

parent d32faf12
...@@ -62,9 +62,12 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted ...@@ -62,9 +62,12 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
const lines = buffer.split('\n') const lines = buffer.split('\n')
try { try {
lines.forEach((message) => { lines.forEach((message) => {
if (!message) if (!message || !message.startsWith('data: '))
return return
bufferObj = JSON.parse(message.substring(6)) // remove data: and parse as json bufferObj = JSON.parse(message.substring(6)) // remove data: and parse as json
if (bufferObj.event !== 'message')
return
onData(unicodeToChar(bufferObj.answer), isFirstMessage, { onData(unicodeToChar(bufferObj.answer), isFirstMessage, {
conversationId: bufferObj.conversation_id, conversationId: bufferObj.conversation_id,
messageId: bufferObj.id, messageId: bufferObj.id,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment