Skip to main content

sse.ts

Source: sdks/typescript/packages/sdk/src/sse.ts. Back to the TypeScript SDK reference index.

note

This page is generated by tools/docs/gen_sdk_reference.py from the SDK sources and the OpenAPI text folders. Do not edit it by hand: change the source and regenerate.

Interface SSEMessage​

One Server-Sent Events message: event name, data, id and retry.

Fields:

NameTypeRequiredDescription
eventstringyesEvent name, message when the stream gives none.
datastringyesRaw text of the data lines of the event, joined by newlines.
idstringnoValue of the last id field.
retrynumbernoReconnection delay in milliseconds from the retry field.

Class SSEParser​

Incremental Server-Sent Events parser. Feed it arbitrary text chunks (they may split lines, fields or even CRLF pairs) and it returns the complete messages seen so far.

SSEParser.end​

end(): SSEMessage[]

Flushes a trailing message when the stream ends without a blank line.

This element takes no parameter.

Returns: SSEMessage[]. The last messages, possibly empty.

SSEParser.push​

push(chunk: string): SSEMessage[]

Adds a text chunk and returns the messages it completes.

NameTypeDefaultRequiredDescription
chunkstringyesText chunk of the stream, cut anywhere.

Returns: SSEMessage[]. Messages completed by a blank line in this chunk.