diff --git a/app/server.hoon b/app/server.hoon index 2ce5b7ffe..6b598c3ae 100644 --- a/app/server.hoon +++ b/app/server.hoon @@ -6,14 +6,9 @@ :: +$ card $% [%connect wire [(unit @t) (list @t)] %server] + [%wait wire @da] [%http-response =raw-http-response:light] == -:: -+$ state - $: :: count: sends back the count value - :: - count=(map bone @ud) - == -- :: utilities: :: @@ -39,48 +34,66 @@ ;h1:"Hello, {<(trip name)>}" == == -:: :: helper library that lets an app handle an EventSource. -:: :: -:: ++ event-source -:: |_ m=(map session=@ud [last-id=@ud]) -:: ++ abet m -:: :: +start-session: called by app to start a session and send first event -:: :: -:: :: This creates a new session where we -:: :: -:: ++ start-session -:: |= [session=@ud =bone data=wall] -:: ^- [(list move) +>.$] -:: :- :~ :* bone %http-response -:: %start 200 -:: :~ ['content-type' 'text/event-stream'] -:: ['cache-control' 'no-cache'] -:: == - -:: complete=%.n -:: == == -:: %_ +>.$ -:: :: +reconnect-session: reconnect an old session to a new http pipe -:: :: -:: :: HTTP sessions can be killed -:: :: -:: ++ reconnect-session -:: |= [session=@ud =bone last-seen=@ud] - -:: :: +confirm- -:: :: -:: ++ confirm- - - -:: :: :: +end-session: called in response to an http pipe being closed -:: :: :: -:: :: ++ end-session - -:: :: ++ send-message -:: :: |= [=bone ] -:: -- +:: helper library that lets an app handle an EventSource. +:: +++ event-source + |_ m=(map session=@ud [=bone last-id=@ud]) + ++ abet m + :: +start-session: called by app to start a session and send first event + :: + :: This creates a new session where we + :: + ++ start-session + |= [session=@ud =bone data=wall] + ^- [(list move) _m] + :: + =/ lines=tape + :: + :- :~ :* bone %http-response + %start 200 + :~ ['content-type' 'text/event-stream'] + ['cache-control' 'no-cache'] + == + (wall-to-output data) + complete=%.n + == == + m + :: %_ +>.$ + :: :: +reconnect-session: reconnect an old session to a new http pipe + :: :: + :: :: HTTP sessions can be killed + :: :: + :: ++ reconnect-session + :: |= [session=@ud =bone last-seen=@ud] + :: :: +confirm- + :: :: + :: ++ confirm- + ++ send-message + |= [=bone data=wall] + ^- [(list move) _m] + :- :~ :* bone %http-response + %continue + (wall-to-output data) + == == + m + :: + ++ wall-to-output + |= =wall + ^- (unit octs) + :- ~ + %- as-octs:mimes:html + %- crip + %- zing + %+ weld + %+ turn data + |= t=tape + "data: {t}\0a" + :: + [`tape`['\0a' ~] ~] + -- +:: ++ part1 ^- octs %- as-octs:mimes:html @@ -96,7 +109,28 @@ (trip name) ""