mirror of
https://github.com/urbit/shrub.git
synced 2025-01-05 19:46:50 +03:00
/gep/hart.js long-poll utils factored out
This commit is contained in:
parent
2d15399137
commit
d83db302f6
412
arvo/eyre.hoon
412
arvo/eyre.hoon
@ -139,8 +139,7 @@
|
|||||||
hen=duct :: event trace
|
hen=duct :: event trace
|
||||||
som=seam :: logical request
|
som=seam :: logical request
|
||||||
pez=pest :: request state
|
pez=pest :: request state
|
||||||
vaz=(list ,[p=cord q=tape]) :: variables
|
sip=marl :: injected scripts
|
||||||
sip=(list manx) :: scripts in result
|
|
||||||
== ::
|
== ::
|
||||||
++ rote :: remote server
|
++ rote :: remote server
|
||||||
$: cnt=@ud :: number served
|
$: cnt=@ud :: number served
|
||||||
@ -152,6 +151,7 @@
|
|||||||
[%aph p=ship q=@ud r=@ud s=json] :: app heartbeat
|
[%aph p=ship q=@ud r=@ud s=json] :: app heartbeat
|
||||||
[%apg p=term q=ship r=mark s=path] :: app get/start
|
[%apg p=term q=ship r=mark s=path] :: app get/start
|
||||||
[%apm p=ship q=@ud r=@ud s=hasp t=json] :: message send
|
[%apm p=ship q=@ud r=@ud s=hasp t=json] :: message send
|
||||||
|
[%app p=ship q=(unit ,@ud)] :: script by port
|
||||||
[%aps p=ship q=@ud s=hasp t=path] :: subscribe
|
[%aps p=ship q=@ud s=hasp t=path] :: subscribe
|
||||||
[%apu p=ship q=@ud s=hasp t=path] :: unsubscribe
|
[%apu p=ship q=@ud s=hasp t=path] :: unsubscribe
|
||||||
[%cog p=@ud q=@ud] :: console get
|
[%cog p=@ud q=@ud] :: console get
|
||||||
@ -315,30 +315,6 @@
|
|||||||
=+ rep=:(welp p.hop scr q.q.hop)
|
=+ rep=:(welp p.hop scr q.q.hop)
|
||||||
[%mid p.luv (tact rep)]
|
[%mid p.luv (tact rep)]
|
||||||
==
|
==
|
||||||
++ lofe :: variables in head
|
|
||||||
|= [vaz=(list ,[p=cord q=tape]) sip=(list manx) luv=love]
|
|
||||||
%- lofa
|
|
||||||
:_ luv
|
|
||||||
%- flop
|
|
||||||
^- (list manx)
|
|
||||||
:_ sip
|
|
||||||
^- manx
|
|
||||||
:- [%script ~]
|
|
||||||
:- :/ "window.urb = \{};\0a"
|
|
||||||
(turn vaz |=([a=cord b=tape] :/("window.urb.{(trip a)}={b};\0a")))
|
|
||||||
::
|
|
||||||
++ lofi :: XX unused
|
|
||||||
|= [mog=(list manx) luv=love]
|
|
||||||
^- love
|
|
||||||
?: =(~ mog) luv
|
|
||||||
?+ -.luv luv
|
|
||||||
%mid
|
|
||||||
?. =(/text/html p.luv) luv
|
|
||||||
=+ str=(trip q.q.luv)
|
|
||||||
=+ scr=|-(^-(tape ?~(mog "</body>" (xmlt & i.mog $(mog t.mog)))))
|
|
||||||
=+ rep=(need (repg "</body>" str scr))
|
|
||||||
[%mid p.luv (tact rep)]
|
|
||||||
==
|
|
||||||
::
|
::
|
||||||
++ loft :: love to response
|
++ loft :: love to response
|
||||||
|= luv=love
|
|= luv=love
|
||||||
@ -610,7 +586,7 @@
|
|||||||
=+ cyz=(need (~(get by wup.sef) ses))
|
=+ cyz=(need (~(get by wup.sef) ses))
|
||||||
~(. ya [our ses] sef cyz)
|
~(. ya [our ses] sef cyz)
|
||||||
::
|
::
|
||||||
++ galt
|
++ galt ::
|
||||||
|= [our=ship ses=hole num=@ud mez=(each bead (list tank))]
|
|= [our=ship ses=hole num=@ud mez=(each bead (list tank))]
|
||||||
^+ +>
|
^+ +>
|
||||||
=+ suf=(~(get by own) our)
|
=+ suf=(~(get by own) our)
|
||||||
@ -920,116 +896,115 @@
|
|||||||
|= [our=ship whu=(unit ship) rul=tape ruf=tape]
|
|= [our=ship whu=(unit ship) rul=tape ruf=tape]
|
||||||
^- manx
|
^- manx
|
||||||
=+ ^= sic ^- manx
|
=+ ^= sic ^- manx
|
||||||
;script
|
;script:'''
|
||||||
;
|
var seal = {
|
||||||
; var seal = {
|
who: goal,
|
||||||
; who: goal,
|
url: burl,
|
||||||
; url: burl,
|
pas: null
|
||||||
; pas: null
|
}
|
||||||
; }
|
var hist = []
|
||||||
; var hist = []
|
var hind = 0
|
||||||
; var hind = 0
|
$(
|
||||||
; $(
|
function() {
|
||||||
; function() {
|
$input = $('#input .line')
|
||||||
; $input = $('#input .line')
|
$prompt = $('#input .prompt')
|
||||||
; $prompt = $('#input .prompt')
|
$prompt.addClass('prefix')
|
||||||
; $prompt.addClass('prefix')
|
$output = $('#output')
|
||||||
; $output = $('#output')
|
$input.focus()
|
||||||
; $input.focus()
|
$('body').click(function() { $input.focus() })
|
||||||
; $('body').click(function() { $input.focus() })
|
ctrl = false;
|
||||||
; ctrl = false;
|
|
||||||
;
|
start = function(ship) {
|
||||||
; start = function(ship) {
|
$prompt.text('vessel: ~')
|
||||||
; $prompt.text('vessel: ~')
|
$input.attr('placeholder', 'ship-name')
|
||||||
; $input.attr('placeholder', 'ship-name')
|
if(ship) {
|
||||||
; if(ship) {
|
$input.val(ship)
|
||||||
; $input.val(ship)
|
}
|
||||||
; }
|
}
|
||||||
; }
|
|
||||||
;
|
ident = function() {
|
||||||
; ident = function() {
|
seal.who = $input.val()
|
||||||
; seal.who = $input.val()
|
|
||||||
;
|
if( (seal.who.length != 13) &&
|
||||||
; if( (seal.who.length != 13) &&
|
(seal.who.length != 6) &&
|
||||||
; (seal.who.length != 6) &&
|
(seal.who.length != 3) )
|
||||||
; (seal.who.length != 3) )
|
{
|
||||||
; {
|
$output.text('not a ship name - try again.');
|
||||||
; $output.text('not a ship name - try again.');
|
return false;
|
||||||
; return false;
|
}
|
||||||
; }
|
|
||||||
;
|
if(seal.who !== host) {
|
||||||
; if(seal.who !== host) {
|
var foreign = {oth: host, ses: session};
|
||||||
; var foreign = {oth: host, ses: session};
|
var all = $.extend({}, seal, foreign);
|
||||||
; var all = $.extend({}, seal, foreign);
|
|
||||||
;
|
console.log('redirect')
|
||||||
; console.log('redirect')
|
window.location="http://"+seal.who+".urbit.org/gul"
|
||||||
; window.location="http://"+seal.who+".urbit.org/gul"
|
+ $.params(all);
|
||||||
; + $.params(all);
|
return false;
|
||||||
; return false;
|
}
|
||||||
; }
|
|
||||||
;
|
$output.text($prompt.text() + " " + seal.who)
|
||||||
; $output.text($prompt.text() + " " + seal.who)
|
$input.val('')
|
||||||
; $input.val('')
|
$input.attr('placeholder', 'ronber-bacnub-hanmev-labnyd')
|
||||||
; $input.attr('placeholder', 'ronber-bacnub-hanmev-labnyd')
|
$prompt.text('secret: ~')
|
||||||
; $prompt.text('secret: ~')
|
|
||||||
;
|
return true;
|
||||||
; return true;
|
}
|
||||||
; }
|
|
||||||
;
|
login = function() {
|
||||||
; login = function() {
|
seal.pas = $input.val()
|
||||||
; seal.pas = $input.val()
|
|
||||||
;
|
output = $output.html()
|
||||||
; output = $output.html()
|
console.log($output.html())
|
||||||
; console.log($output.html())
|
$output.html(output.replace('sorry. please try again.<br>',''))
|
||||||
; $output.html(output.replace('sorry. please try again.<br>',''))
|
|
||||||
;
|
$.post(form, seal, function(data,xhr,status) {
|
||||||
; $.post(form, seal, function(data,xhr,status) {
|
console.log(data);
|
||||||
; console.log(data);
|
if(data.ok == true) {
|
||||||
; if(data.ok == true) {
|
document.location = data.next;
|
||||||
; document.location = data.next;
|
} else {
|
||||||
; } else {
|
$output.prepend('sorry. please try again.<br>')
|
||||||
; $output.prepend('sorry. please try again.<br>')
|
}
|
||||||
; }
|
})
|
||||||
; })
|
}
|
||||||
; }
|
|
||||||
;
|
steps = [ident,login]
|
||||||
; steps = [ident,login]
|
step = 0
|
||||||
; step = 0
|
start(seal.who)
|
||||||
; start(seal.who)
|
if(seal.who) {
|
||||||
; if(seal.who) {
|
ident()
|
||||||
; ident()
|
step++
|
||||||
; step++
|
}
|
||||||
; }
|
|
||||||
;
|
$input.on('keydown', function(e) {
|
||||||
; $input.on('keydown', function(e) {
|
if(e.keyCode == 17) {
|
||||||
; if(e.keyCode == 17) {
|
ctrl = true
|
||||||
; ctrl = true
|
return;
|
||||||
; return;
|
}
|
||||||
; }
|
|
||||||
;
|
if(e.keyCode == 68 &&
|
||||||
; if(e.keyCode == 68 &&
|
ctrl == true &&
|
||||||
; ctrl == true &&
|
step == 1) {
|
||||||
; step == 1) {
|
$output.text('')
|
||||||
; $output.text('')
|
step = 0
|
||||||
; step = 0
|
start(null)
|
||||||
; start(null)
|
return;
|
||||||
; return;
|
}
|
||||||
; }
|
|
||||||
;
|
if(e.keyCode == 13) {
|
||||||
; if(e.keyCode == 13) {
|
if(steps[step]() && step < steps.length-1)
|
||||||
; if(steps[step]() && step < steps.length-1)
|
step++
|
||||||
; step++
|
return;
|
||||||
; return;
|
}
|
||||||
; }
|
});
|
||||||
; });
|
|
||||||
;
|
$input.on('keyup', function(e) {
|
||||||
; $input.on('keyup', function(e) {
|
if(e.keyCode == 17) {
|
||||||
; if(e.keyCode == 17) {
|
ctrl = false
|
||||||
; ctrl = false
|
}
|
||||||
; }
|
});
|
||||||
; });
|
})
|
||||||
; })
|
'''
|
||||||
==
|
|
||||||
=+ ^= cof
|
=+ ^= cof
|
||||||
;=
|
;=
|
||||||
; var host = '{(trip (rsh 3 1 (scot %p our)))}';
|
; var host = '{(trip (rsh 3 1 (scot %p our)))}';
|
||||||
@ -1043,32 +1018,32 @@
|
|||||||
;head
|
;head
|
||||||
;title: urbit login
|
;title: urbit login
|
||||||
;script(type "text/javascript", src jqu);
|
;script(type "text/javascript", src jqu);
|
||||||
;style
|
;style:'''
|
||||||
; body {
|
body {
|
||||||
; margin: 60px 120px;
|
margin: 60px 120px;
|
||||||
; font: normal 12px "Menlo" monospace;
|
font: normal 12px "Menlo" monospace;
|
||||||
; background-color: #000;
|
background-color: #000;
|
||||||
; color: #fff;
|
color: #fff;
|
||||||
; }
|
}
|
||||||
;
|
|
||||||
; #output {
|
#output {
|
||||||
;
|
|
||||||
; }
|
}
|
||||||
;
|
|
||||||
; #input .prompt {
|
#input .prompt {
|
||||||
; display: inline-block;
|
display: inline-block;
|
||||||
; margin-right: 12px;
|
margin-right: 12px;
|
||||||
; }
|
}
|
||||||
;
|
|
||||||
; #input .line {
|
#input .line {
|
||||||
; outline: none;
|
outline: none;
|
||||||
; width: 80%;
|
width: 80%;
|
||||||
; border: 0;
|
border: 0;
|
||||||
; background-color: transparent;
|
background-color: transparent;
|
||||||
; color: #fff;
|
color: #fff;
|
||||||
; font: normal 12px "Menlo" monospace;
|
font: normal 12px "Menlo" monospace;
|
||||||
; }
|
}
|
||||||
==
|
'''
|
||||||
==
|
==
|
||||||
=+ ^= bod ^- manx
|
=+ ^= bod ^- manx
|
||||||
;body
|
;body
|
||||||
@ -1150,30 +1125,21 @@
|
|||||||
?> ?=(%way pez.u.pup)
|
?> ?=(%way pez.u.pup)
|
||||||
$(yov t.yov, q.rey (~(put by q.rey) i.yov u.pup(pez noz)))
|
$(yov t.yov, q.rey (~(put by q.rey) i.yov u.pup(pez noz)))
|
||||||
::
|
::
|
||||||
++ duti :: heartbeat script
|
++ duty |= [our=ship nap=@ud you=ship orx=oryx] :: interface script
|
||||||
;script:'''
|
^- cord
|
||||||
window.urb.seqn_h = 0
|
%^ cat 3
|
||||||
window.urb.heartbeat = function() {
|
%- crip
|
||||||
this.poll({
|
=- "window.urb = {(pojo (jobe -))}\0a"
|
||||||
type:"heb",
|
:~
|
||||||
ship:this.ship,
|
[%ship (jape |1:<our>)]
|
||||||
dely:30000,
|
[%port (jone nap)]
|
||||||
seqn:function() {
|
[%auto %b %&]
|
||||||
return window.urb.seqn_h
|
[%user (jape |1:<you>)]
|
||||||
},
|
[%oryx %s orx]
|
||||||
incs:function() {
|
==
|
||||||
window.urb.seqn_h = window.urb.seqn_h+1
|
|
||||||
}
|
|
||||||
},function() {
|
|
||||||
console.log('heartbeat.')
|
|
||||||
})
|
|
||||||
}
|
|
||||||
window.urb.heartbeat()
|
|
||||||
'''
|
'''
|
||||||
::
|
|
||||||
++ duty
|
|
||||||
;script:'''
|
|
||||||
window.urb.seqn_u = 0
|
window.urb.seqn_u = 0
|
||||||
|
window.urb.seqn_h = 0
|
||||||
window.urb.dely = 0
|
window.urb.dely = 0
|
||||||
window.urb.puls = 0
|
window.urb.puls = 0
|
||||||
window.urb.cabs = {}
|
window.urb.cabs = {}
|
||||||
@ -1312,6 +1278,23 @@
|
|||||||
}
|
}
|
||||||
window.urb.poll(param)
|
window.urb.poll(param)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.urb.heartbeat = function() {
|
||||||
|
this.poll({
|
||||||
|
type:"heb",
|
||||||
|
ship:this.ship,
|
||||||
|
dely:30000,
|
||||||
|
seqn:function() {
|
||||||
|
return window.urb.seqn_h
|
||||||
|
},
|
||||||
|
incs:function() {
|
||||||
|
window.urb.seqn_h = window.urb.seqn_h+1
|
||||||
|
}
|
||||||
|
},function() {
|
||||||
|
console.log('heartbeat.')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
window.urb.heartbeat()
|
||||||
'''
|
'''
|
||||||
::
|
::
|
||||||
++ fape :: dispatch %ape
|
++ fape :: dispatch %ape
|
||||||
@ -1365,6 +1348,18 @@
|
|||||||
(need (eccu orx.ced moh))
|
(need (eccu orx.ced moh))
|
||||||
==
|
==
|
||||||
::
|
::
|
||||||
|
++ fapp
|
||||||
|
|= [fur=(unit term) you=@p paw=path]
|
||||||
|
?> ?=([~ %js] fur)
|
||||||
|
?> ?=(?([%hart ~] [@ %hart ~]) paw)
|
||||||
|
:- ~
|
||||||
|
:* %app
|
||||||
|
you
|
||||||
|
?~ t.paw
|
||||||
|
~
|
||||||
|
(some (slav %ui (cat 3 '0i' i.paw)))
|
||||||
|
==
|
||||||
|
::
|
||||||
++ faps :: dispatch %aps
|
++ faps :: dispatch %aps
|
||||||
|= [fur=(unit term) you=@p paw=path moh=moth]
|
|= [fur=(unit term) you=@p paw=path moh=moth]
|
||||||
^- (unit seam)
|
^- (unit seam)
|
||||||
@ -1612,6 +1607,7 @@
|
|||||||
%r :: app response
|
%r :: app response
|
||||||
%s :: app subscribe
|
%s :: app subscribe
|
||||||
%h :: app heartbeat
|
%h :: app heartbeat
|
||||||
|
%p :: app script by port
|
||||||
%n :: now
|
%n :: now
|
||||||
%u :: app unsubscribe
|
%u :: app unsubscribe
|
||||||
%z :: app version
|
%z :: app version
|
||||||
@ -1642,6 +1638,7 @@
|
|||||||
%l (fool r.pul)
|
%l (fool r.pul)
|
||||||
%g (fapg p.q.pul yun paw)
|
%g (fapg p.q.pul yun paw)
|
||||||
%e (fape p.q.pul yun paw)
|
%e (fape p.q.pul yun paw)
|
||||||
|
%p (fapp p.q.pul yun paw)
|
||||||
==
|
==
|
||||||
::
|
::
|
||||||
%p
|
%p
|
||||||
@ -1727,7 +1724,6 @@
|
|||||||
*seam
|
*seam
|
||||||
`pest`[%raw pul moh]
|
`pest`[%raw pul moh]
|
||||||
~
|
~
|
||||||
~
|
|
||||||
==
|
==
|
||||||
==
|
==
|
||||||
::
|
::
|
||||||
@ -1798,6 +1794,10 @@
|
|||||||
:: ~& [%wink-apm +.som.pip]
|
:: ~& [%wink-apm +.som.pip]
|
||||||
:- [~ pip(pez %way)]
|
:- [~ pip(pez %way)]
|
||||||
(yokm num +.som.pip)
|
(yokm num +.som.pip)
|
||||||
|
::
|
||||||
|
%app :: script by port
|
||||||
|
:: ~& [%wink-app +.som.pip]
|
||||||
|
(yokp num +.som.pip)
|
||||||
::
|
::
|
||||||
%aps :: subscribe
|
%aps :: subscribe
|
||||||
:: ~& [%wink-aps +.som.pip]
|
:: ~& [%wink-aps +.som.pip]
|
||||||
@ -1913,7 +1913,7 @@
|
|||||||
:+ 500
|
:+ 500
|
||||||
~[content-type/'text/html']
|
~[content-type/'text/html']
|
||||||
[~ (tact (xmlt | mad ~))]
|
[~ (tact (xmlt | mad ~))]
|
||||||
& [%fin (lofe vaz.pip mog (lopo q.p.p.pez.pip))]
|
& [%fin (lofa mog (lopo q.p.p.pez.pip))]
|
||||||
==
|
==
|
||||||
==
|
==
|
||||||
::
|
::
|
||||||
@ -1969,6 +1969,17 @@
|
|||||||
?~ yon (bust 204 num)
|
?~ yon (bust 204 num)
|
||||||
abet:(post:u.yon cnt num hap jon)
|
abet:(post:u.yon cnt num hap jon)
|
||||||
::
|
::
|
||||||
|
++ yokp :: script by port
|
||||||
|
|= [num=@ud you=ship nup=(unit ,@ud)]
|
||||||
|
^- [(unit pimp) _+>]
|
||||||
|
?~ nup
|
||||||
|
$(nup [~ num], +> ~(harp yo num you *sink))
|
||||||
|
=+ yon=(yolk u.nup)
|
||||||
|
?~ yon
|
||||||
|
=+ err=(bust 204 num)
|
||||||
|
[`(need (~(get by q.rey.err) num)) err]
|
||||||
|
[- abet:+]:(hark:u.yon num)
|
||||||
|
::
|
||||||
++ yoks :: subscribe
|
++ yoks :: subscribe
|
||||||
|= [num=@ud you=ship nap=@ud hap=hasp pax=path]
|
|= [num=@ud you=ship nap=@ud hap=hasp pax=path]
|
||||||
=+ yon=(yolk nap)
|
=+ yon=(yolk nap)
|
||||||
@ -2012,7 +2023,7 @@
|
|||||||
(pass(hen hen.q.i.wuh) `p.i.wuh `note`[%g %nuke hap.q.i.wuh you])
|
(pass(hen hen.q.i.wuh) `p.i.wuh `note`[%g %nuke hap.q.i.wuh you])
|
||||||
==
|
==
|
||||||
::
|
::
|
||||||
++ beat
|
++ beat
|
||||||
|= [cnt=@ud num=@ud jon=json]
|
|= [cnt=@ud num=@ud jon=json]
|
||||||
^- [(unit pimp) _+>]
|
^- [(unit pimp) _+>]
|
||||||
?. =(cnt num.bet.siq)
|
?. =(cnt num.bet.siq)
|
||||||
@ -2022,6 +2033,18 @@
|
|||||||
=. +>.$ (hear:(yule %bet) ~ %& %json !>((joba %a-ok %b %&)))
|
=. +>.$ (hear:(yule %bet) ~ %& %json !>((joba %a-ok %b %&)))
|
||||||
[`(need (~(get by q.rey) num)) +>.$]
|
[`(need (~(get by q.rey) num)) +>.$]
|
||||||
::
|
::
|
||||||
|
++ hark
|
||||||
|
|= num=@ud
|
||||||
|
^- [(unit pimp) _+>]
|
||||||
|
=. +>.$ abet:(busk:(yule %nil) num _@ ~ %& %js !>((duty our nap you orx.ced)))
|
||||||
|
[`(need (~(get by q.rey) num)) +>.$]
|
||||||
|
::
|
||||||
|
++ harp
|
||||||
|
%_ abet
|
||||||
|
tim.bet.siq now
|
||||||
|
num.sub.siq 1
|
||||||
|
==
|
||||||
|
::
|
||||||
++ hoop :: request path
|
++ hoop :: request path
|
||||||
|= can=(unit ,@ud)
|
|= can=(unit ,@ud)
|
||||||
^- path
|
^- path
|
||||||
@ -2117,22 +2140,17 @@
|
|||||||
==
|
==
|
||||||
=+ pip=u.pup
|
=+ pip=u.pup
|
||||||
=+ ^= sip
|
=+ ^= sip
|
||||||
?. =(%apg -.som.pip) sip.pip
|
?. ?=(%apg -.som.pip) sip.pip
|
||||||
[duty duti sip.pip]
|
=* his q.som.pip
|
||||||
|
=+ mef=?:(=(our his) "gop" "gip/{|1:<his>}")
|
||||||
|
[;script(src "/{mef}/{(pojo (jone nap))}/hart.js"); sip.pip]
|
||||||
?~ huq +>.$(..yo (bust 404 num))
|
?~ huq +>.$(..yo (bust 404 num))
|
||||||
%= +>.$
|
%= +>.$
|
||||||
q.rey
|
q.rey
|
||||||
%+ ~(put by q.rey) num
|
%+ ~(put by q.rey) num
|
||||||
^- pimp
|
^- pimp
|
||||||
=+ quo=|=(a=cord :(weld "\"" (trip a) "\""))
|
|
||||||
%= pip
|
%= pip
|
||||||
pez %new
|
pez %new
|
||||||
vaz :~ [%ship (quo (rsh 3 1 (scot %p our)))]
|
|
||||||
[%port (trip (rsh 3 2 (scot %ui nap)))]
|
|
||||||
[%auto "true"]
|
|
||||||
[%oryx (quo orx.ced)]
|
|
||||||
[%user (quo (rsh 3 1 (scot %p you)))]
|
|
||||||
==
|
|
||||||
sip sip
|
sip sip
|
||||||
som ^- seam
|
som ^- seam
|
||||||
:+ %sil
|
:+ %sil
|
||||||
|
Loading…
Reference in New Issue
Block a user