2018-10-04 02:10:15 +03:00
|
|
|
|%
|
|
|
|
:: +move: output effect
|
|
|
|
::
|
|
|
|
+$ move [bone card]
|
|
|
|
:: +card: output effect payload
|
|
|
|
::
|
|
|
|
+$ card
|
|
|
|
$% [%connect wire [(unit @t) (list @t)] %server]
|
2018-10-22 21:36:30 +03:00
|
|
|
[%wait wire @da]
|
2018-10-04 02:10:15 +03:00
|
|
|
[%http-response =raw-http-response:light]
|
|
|
|
==
|
|
|
|
--
|
|
|
|
:: utilities:
|
|
|
|
::
|
|
|
|
|%
|
|
|
|
::
|
|
|
|
++ parse-request-line
|
|
|
|
|= url=@t
|
|
|
|
^- [[(unit @ta) site=(list @t)] args=(list [key=@t value=@t])]
|
|
|
|
(fall (rush url ;~(plug apat:de-purl:html yque:de-purl:html)) [[~ ~] ~])
|
|
|
|
:: +hello:
|
|
|
|
::
|
|
|
|
++ hello
|
|
|
|
|= name=@t
|
|
|
|
^- octs
|
|
|
|
%- as-octs:mimes:html
|
|
|
|
%- crip
|
|
|
|
%- en-xml:html
|
|
|
|
;html
|
|
|
|
;head
|
|
|
|
;title:"Hello, {<(trip name)>}"
|
|
|
|
==
|
|
|
|
;body
|
|
|
|
;h1:"Hello, {<(trip name)>}"
|
|
|
|
==
|
|
|
|
==
|
2018-10-22 21:36:30 +03:00
|
|
|
:: 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]
|
|
|
|
::
|
|
|
|
:- :~ :* bone %http-response
|
|
|
|
%start 200
|
|
|
|
:~ ['content-type' 'text/event-stream']
|
|
|
|
['cache-control' 'no-cache']
|
|
|
|
==
|
|
|
|
(wall-to-output data)
|
|
|
|
complete=%.n
|
|
|
|
== ==
|
|
|
|
m
|
2018-10-23 21:34:59 +03:00
|
|
|
|
|
|
|
::
|
2018-10-22 21:36:30 +03:00
|
|
|
:: %_ +>.$
|
|
|
|
:: :: +reconnect-session: reconnect an old session to a new http pipe
|
|
|
|
:: ::
|
|
|
|
:: :: HTTP sessions can be killed
|
|
|
|
:: ::
|
|
|
|
:: ++ reconnect-session
|
|
|
|
:: |= [session=@ud =bone last-seen=@ud]
|
2018-10-10 21:51:52 +03:00
|
|
|
|
2018-10-22 21:36:30 +03:00
|
|
|
:: :: +confirm-
|
|
|
|
:: ::
|
|
|
|
:: ++ confirm-
|
2018-10-10 21:51:52 +03:00
|
|
|
|
2018-10-22 21:36:30 +03:00
|
|
|
++ send-message
|
|
|
|
|= [=bone data=wall]
|
|
|
|
^- [(list move) _m]
|
|
|
|
:- :~ :* bone %http-response
|
|
|
|
%continue
|
|
|
|
(wall-to-output data)
|
2018-10-23 21:34:59 +03:00
|
|
|
complete=%.n
|
2018-10-22 21:36:30 +03:00
|
|
|
== ==
|
|
|
|
m
|
|
|
|
::
|
|
|
|
++ wall-to-output
|
|
|
|
|= =wall
|
|
|
|
^- (unit octs)
|
|
|
|
:- ~
|
|
|
|
%- as-octs:mimes:html
|
|
|
|
%- crip
|
|
|
|
%- zing
|
|
|
|
%+ weld
|
2018-10-23 21:34:59 +03:00
|
|
|
%+ turn wall
|
2018-10-22 21:36:30 +03:00
|
|
|
|= t=tape
|
|
|
|
"data: {t}\0a"
|
|
|
|
::
|
|
|
|
[`tape`['\0a' ~] ~]
|
|
|
|
--
|
|
|
|
::
|
2018-10-10 21:51:52 +03:00
|
|
|
++ part1
|
|
|
|
^- octs
|
|
|
|
%- as-octs:mimes:html
|
|
|
|
%- crip
|
|
|
|
"<html><head><title>Hello, ""
|
|
|
|
::
|
|
|
|
++ part2
|
|
|
|
|= name=@t
|
|
|
|
^- octs
|
|
|
|
%- as-octs:mimes:html
|
|
|
|
%- crip
|
|
|
|
;: weld
|
|
|
|
(trip name)
|
|
|
|
""</title></head><body><h1>Hello, ""
|
|
|
|
(trip name)
|
2018-10-22 21:36:30 +03:00
|
|
|
""</h1>"
|
|
|
|
"<p>Time is <span id=time></span></p>"
|
|
|
|
::
|
|
|
|
%- trip
|
|
|
|
'''
|
|
|
|
<script>
|
|
|
|
var evtSource = new EventSource("/~server/stream", { withCredentials: true } );
|
|
|
|
|
|
|
|
evtSource.onmessage = function(e) {
|
|
|
|
var message = document.getElementById("time");
|
|
|
|
message.innerHTML = e.data;
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
'''
|
|
|
|
::
|
|
|
|
"</body></html>"
|
|
|
|
==
|
|
|
|
--
|
|
|
|
|%
|
|
|
|
::
|
|
|
|
+$ state
|
|
|
|
$: events=(map session=@ud [=bone last-id=@ud])
|
2018-10-10 21:51:52 +03:00
|
|
|
==
|
2018-10-04 02:10:15 +03:00
|
|
|
--
|
|
|
|
::
|
|
|
|
|_ [bow=bowl:gall state]
|
|
|
|
::
|
|
|
|
++ this .
|
|
|
|
::
|
|
|
|
++ prep
|
|
|
|
|= old=(unit state)
|
|
|
|
^- (quip move _this)
|
|
|
|
~& %prep
|
|
|
|
:- [`move`[ost.bow [%connect / [~ /'~server'] %server]] ~]
|
|
|
|
?~ old
|
|
|
|
this
|
|
|
|
this(+<+ u.old)
|
|
|
|
:: alerts us that we were bound. we need this because the vane calls back.
|
|
|
|
::
|
|
|
|
++ bound
|
|
|
|
|= [wir=wire success=? binding=binding:light]
|
|
|
|
~& [%bound success]
|
|
|
|
[~ this]
|
|
|
|
::
|
2018-10-22 21:36:30 +03:00
|
|
|
:: TODO: Before we can actually add EventSource()s, we need to have %thud
|
|
|
|
:: handling working.
|
|
|
|
::
|
|
|
|
++ handle-start-stream
|
|
|
|
|= req=http-request:light
|
|
|
|
^- (quip move _this)
|
|
|
|
:: Start a session sending the current time
|
|
|
|
::
|
|
|
|
=^ moves events
|
|
|
|
(~(start-session event-source events) 0 ost.bow ["{<now.bow>}" ~])
|
|
|
|
::
|
|
|
|
:_ this
|
|
|
|
:- ^- move
|
|
|
|
[ost.bow %wait /timer (add now.bow ~s1)]
|
|
|
|
::
|
|
|
|
moves
|
|
|
|
:: +wake: responds to a %wait send from +handle-start-stream
|
|
|
|
::
|
|
|
|
++ wake
|
|
|
|
|= [wir=wire ~]
|
|
|
|
^- (quip move _this)
|
2018-10-23 21:34:59 +03:00
|
|
|
:: ~& [%tick wir now.bow]
|
2018-10-22 21:36:30 +03:00
|
|
|
::
|
|
|
|
=^ moves events
|
|
|
|
(~(send-message event-source events) ost.bow ["{<now.bow>}" ~])
|
|
|
|
::
|
|
|
|
:_ this
|
|
|
|
:- ^- move
|
|
|
|
[ost.bow %wait /timer (add now.bow ~s1)]
|
|
|
|
moves
|
|
|
|
::
|
2018-10-04 02:10:15 +03:00
|
|
|
:: received when we have a
|
|
|
|
::
|
|
|
|
++ poke-handle-http-request
|
|
|
|
|= [authenticated=? secure=? address=address:light req=http-request:light]
|
|
|
|
^- (quip move _this)
|
|
|
|
::
|
|
|
|
=+ request-line=(parse-request-line url.req)
|
|
|
|
~& [%request-line request-line]
|
|
|
|
=/ name=@t
|
|
|
|
=+ back-path=(flop site.request-line)
|
|
|
|
?~ back-path
|
|
|
|
'World'
|
|
|
|
i.back-path
|
2018-10-22 21:36:30 +03:00
|
|
|
?: =(name 'stream')
|
|
|
|
(handle-start-stream req)
|
2018-10-04 02:10:15 +03:00
|
|
|
~& [%name name]
|
|
|
|
::
|
|
|
|
:_ this
|
|
|
|
:~ ^- move
|
|
|
|
:- ost.bow
|
|
|
|
:* %http-response
|
2018-10-22 21:36:30 +03:00
|
|
|
[%start 200 ['content-type' 'text/html']~ [~ part1] %.n]
|
|
|
|
==
|
|
|
|
::
|
|
|
|
^- move
|
|
|
|
:- ost.bow
|
|
|
|
:* %http-response
|
|
|
|
[%continue [~ (part2 name)] %.y]
|
2018-10-10 21:51:52 +03:00
|
|
|
==
|
|
|
|
==
|
2018-10-04 02:10:15 +03:00
|
|
|
--
|