SSE

encodes the Server-Sent Events wire format (WHATWG HTML ยง9.2.6).

Every function here returns one complete block, terminated by the blank line that dispatches it. Carriage returns and newlines are stripped from field values, and a data value spanning several lines becomes one data: line per line.

comment-line

defn

(Fn [(Ref String a)] String)

                        (comment-line text)
                    

encodes a comment line. Clients ignore it; it keeps the stream and any proxy in front of it from timing out.

data

defn

(Fn [(Ref String a)] String)

                        (data value)
                    

encodes a data-only event.

encode

defn

(Fn [(Maybe String), (Ref String a), (Maybe String), (Maybe Int)] String)

                        (encode name payload id retry)
                    

encodes one event with an optional name, id and retry.

retry is the reconnection time in milliseconds a client should wait before reopening the stream. An empty payload still emits an empty data: line, so the event is dispatched with an empty payload rather than dropped.

event

defn

(Fn [(Ref String a), (Ref String b)] String)

                        (event name value)
                    

encodes an event with a name, which the client listens for by that name instead of message.

retry-after

defn

(Fn [a] String)

                        (retry-after ms)
                    

encodes a lone reconnection time in milliseconds.