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]
|
2019-01-10 02:43:43 +03:00
|
|
|
[%diff %json json]
|
2018-10-04 02:10:15 +03:00
|
|
|
==
|
|
|
|
--
|
|
|
|
:: 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
|
2018-10-25 02:48:24 +03:00
|
|
|
;title:"Hello, {(trip name)}"
|
2018-10-04 02:10:15 +03:00
|
|
|
==
|
|
|
|
;body
|
2018-10-25 02:48:24 +03:00
|
|
|
;h1:"Hello, {(trip name)}"
|
|
|
|
;p
|
|
|
|
; Time is
|
2019-01-10 02:43:43 +03:00
|
|
|
;span#time:"?????"
|
2018-10-25 02:48:24 +03:00
|
|
|
==
|
2019-01-10 02:43:43 +03:00
|
|
|
;button#start:"Start Timer"
|
|
|
|
;button#poke:"Random Poke"
|
2019-01-09 01:44:03 +03:00
|
|
|
;script(type "module", src "/~server/hello.js");
|
2018-10-04 02:10:15 +03:00
|
|
|
==
|
|
|
|
==
|
2019-01-09 01:44:03 +03:00
|
|
|
::
|
|
|
|
++ hello-js
|
|
|
|
^- octs
|
|
|
|
%- as-octs:mimes:html
|
|
|
|
'''
|
|
|
|
import * as urb from '/~/channel/channel.js';
|
|
|
|
|
|
|
|
var c = urb.newChannel();
|
2019-01-10 02:43:43 +03:00
|
|
|
|
|
|
|
// The poke button just sends a poke
|
|
|
|
document.getElementById("poke").addEventListener("click", function(){
|
|
|
|
c.poke("zod", "server", "json", 5,
|
2019-01-09 01:44:03 +03:00
|
|
|
function() {
|
|
|
|
console.log("Poke worked");
|
|
|
|
},
|
|
|
|
function(err) {
|
|
|
|
console.log("Poke failed: " + err);
|
|
|
|
});
|
2019-01-10 02:43:43 +03:00
|
|
|
});
|
2019-01-09 01:44:03 +03:00
|
|
|
|
2019-01-11 03:35:09 +03:00
|
|
|
function doSubs() {
|
|
|
|
// The subscription sends the time which makes the thing work.
|
|
|
|
//
|
|
|
|
c.subscribe("zod", "server", "/timer",
|
|
|
|
function(err) {
|
|
|
|
console.log("Failed initial connection: " + err);
|
|
|
|
},
|
|
|
|
function(json) {
|
|
|
|
console.log("Subscription update: ", json);
|
|
|
|
var message = document.getElementById("time");
|
|
|
|
message.innerHTML = json;
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
console.log("Subscription quit");
|
|
|
|
|
|
|
|
// resubscribe because Gall is broken
|
|
|
|
//
|
|
|
|
// Galls queuing mechanism is broken and will
|
|
|
|
// break subscriptions whenever 20 messages have
|
|
|
|
// been sent.
|
|
|
|
//
|
|
|
|
doSubs();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
doSubs();
|
2019-01-09 01:44:03 +03:00
|
|
|
'''
|
2018-10-25 02:24:35 +03:00
|
|
|
:: +require-authorization: redirect to the login page when unauthenticated
|
|
|
|
::
|
|
|
|
++ require-authorization
|
|
|
|
|* [=bone move=mold this=*]
|
|
|
|
|= handler=$-(inbound-request:light (quip move _this))
|
|
|
|
|= =inbound-request:light
|
|
|
|
^- (quip move _this)
|
|
|
|
::
|
|
|
|
?: authenticated.inbound-request
|
|
|
|
(handler inbound-request)
|
|
|
|
::
|
|
|
|
:_ this
|
|
|
|
^- (list move)
|
|
|
|
=/ redirect=cord
|
|
|
|
%- crip
|
|
|
|
"/~/login?redirect={(trip url.http-request.inbound-request)}"
|
|
|
|
[bone [%http-response %start 307 ['location' redirect]~ ~ %.y]]~
|
2018-10-22 21:36:30 +03:00
|
|
|
--
|
|
|
|
|%
|
|
|
|
::
|
|
|
|
+$ state
|
2019-01-10 02:43:43 +03:00
|
|
|
$: next-timer=(unit @da)
|
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
|
|
|
:: +wake: responds to a %wait send from +handle-start-stream
|
|
|
|
::
|
|
|
|
++ wake
|
|
|
|
|= [wir=wire ~]
|
|
|
|
^- (quip move _this)
|
2018-10-24 00:25:20 +03:00
|
|
|
::
|
|
|
|
~& [%timer-tick wir now.bow]
|
2018-10-22 21:36:30 +03:00
|
|
|
::
|
2019-01-10 02:43:43 +03:00
|
|
|
=/ moves=(list move)
|
|
|
|
%+ turn (prey:pubsub:userlib /timer bow)
|
|
|
|
|= [=bone ^]
|
|
|
|
[bone %diff %json %s (scot %da now.bow)]
|
|
|
|
:: if we have outbound moves, say that we have another timer.
|
2018-10-22 21:36:30 +03:00
|
|
|
::
|
2019-01-10 02:43:43 +03:00
|
|
|
=. next-timer
|
|
|
|
?: ?=(^ moves)
|
|
|
|
`(add now.bow ~s1)
|
|
|
|
~
|
|
|
|
:: if we have any subscribers, add another timer for the future
|
|
|
|
::
|
|
|
|
=? moves ?=(^ moves)
|
|
|
|
[[ost.bow %wait /timer (add now.bow ~s1)] moves]
|
|
|
|
::
|
|
|
|
[moves this]
|
2018-10-24 00:25:20 +03:00
|
|
|
:: +poke-handle-http-request: received on a new connection established
|
2018-10-04 02:10:15 +03:00
|
|
|
::
|
|
|
|
++ poke-handle-http-request
|
2018-10-25 02:24:35 +03:00
|
|
|
%- (require-authorization ost.bow move this)
|
2018-10-25 00:31:19 +03:00
|
|
|
|= =inbound-request:light
|
2018-10-04 02:10:15 +03:00
|
|
|
^- (quip move _this)
|
|
|
|
::
|
2018-10-25 00:31:19 +03:00
|
|
|
=+ request-line=(parse-request-line url.http-request.inbound-request)
|
2018-10-04 02:10:15 +03:00
|
|
|
~& [%request-line request-line]
|
|
|
|
=/ name=@t
|
|
|
|
=+ back-path=(flop site.request-line)
|
|
|
|
?~ back-path
|
|
|
|
'World'
|
|
|
|
i.back-path
|
|
|
|
::
|
2019-01-09 01:44:03 +03:00
|
|
|
?: =(name 'hello')
|
|
|
|
:_ this
|
|
|
|
:~ ^- move
|
|
|
|
:- ost.bow
|
|
|
|
:* %http-response
|
|
|
|
[%start 200 ['content-type' 'application/javascript']~ [~ hello-js] %.y]
|
|
|
|
==
|
|
|
|
==
|
|
|
|
::
|
2018-10-04 02:10:15 +03:00
|
|
|
:_ this
|
|
|
|
:~ ^- move
|
|
|
|
:- ost.bow
|
|
|
|
:* %http-response
|
2018-10-25 02:48:24 +03:00
|
|
|
[%start 200 ['content-type' 'text/html']~ [~ (hello name)] %.y]
|
2018-10-10 21:51:52 +03:00
|
|
|
==
|
|
|
|
==
|
2018-10-24 00:25:20 +03:00
|
|
|
:: +poke-handle-http-cancel: received when a connection was killed
|
|
|
|
::
|
|
|
|
++ poke-handle-http-cancel
|
2018-10-25 00:31:19 +03:00
|
|
|
|= =inbound-request:light
|
2018-10-24 00:25:20 +03:00
|
|
|
^- (quip move _this)
|
|
|
|
:: the only long lived connections we keep state about are the stream ones.
|
|
|
|
::
|
|
|
|
[~ this]
|
2019-01-10 02:43:43 +03:00
|
|
|
::
|
|
|
|
++ poke-json
|
|
|
|
|= =json
|
|
|
|
^- (quip move _this)
|
|
|
|
~& [%poke-json json]
|
|
|
|
[~ this]
|
|
|
|
::
|
|
|
|
++ peer-timer
|
|
|
|
|= pax/path
|
|
|
|
^- (quip move _this)
|
|
|
|
:: if we don't have a timer, set a timer.
|
|
|
|
?: ?=(^ next-timer)
|
|
|
|
[~ this]
|
|
|
|
::
|
|
|
|
:- [ost.bow %wait /timer (add now.bow ~s1)]~
|
|
|
|
this(next-timer `(unit @da)`[~ (add now.bow ~s1)])
|
2018-10-04 02:10:15 +03:00
|
|
|
--
|