mirror of
https://github.com/ilyakooo0/urbit.git
synced 2025-01-04 21:33:41 +03:00
more work on eyre-stuff -- compiles
This commit is contained in:
parent
3fafa64ed5
commit
20574f69f7
128
arvo/eyre.hoon
128
arvo/eyre.hoon
@ -145,9 +145,9 @@
|
||||
$% [%ape p=ship q=@ud r=@ud] :: subscribe pull
|
||||
[%aph p=ship q=@ud r=@ud s=json] :: app heartbeat
|
||||
[%apg p=term q=ship r=logo s=path] :: app get/start
|
||||
[%apm p=ship q=@ud r=@ud s=json] :: message send
|
||||
[%aps p=ship q=@ud r=@ud s=path] :: subscribe
|
||||
[%apu p=ship q=@ud r=@ud] :: unsubscribe
|
||||
[%apm p=ship q=@ud r=@ud s=hasp t=json] :: message send
|
||||
[%aps p=ship q=@ud r=@ud s=hasp t=path] :: subscribe
|
||||
[%apu p=ship q=@ud r=@ud s=hasp t=path] :: unsubscribe
|
||||
[%cog p=@ud q=@ud] :: console get
|
||||
[%con p=@ud] :: console face
|
||||
[%cop p=@ud q=@ud r=json] :: console put
|
||||
@ -166,8 +166,10 @@
|
||||
$: bet=[wig=swig num=@ud tim=@da] :: heartbeat XX pretend
|
||||
meg=[wig=swig num=@ud] :: messages XX swig?
|
||||
sub=[wig=swig num=@ud can=(map ,@ud stem)] :: subscriptions
|
||||
:: XX need to store a way to return the first message in a stream
|
||||
:: XX probably in ++stem?
|
||||
== ::
|
||||
++ stem ,[p=hasp q=path r=duct] :: subscription
|
||||
++ stem ,[p=hasp q=path r=duct] :: subscription
|
||||
++ swig :: update channel
|
||||
$: cnt=@ud :: updates produced
|
||||
toy=@ud :: updates sent
|
||||
@ -190,6 +192,24 @@
|
||||
?~ u.mar ^$(cok t.cok)
|
||||
?:(=(nam p.i.u.mar) [~ q.i.u.mar] $(u.mar t.u.mar))
|
||||
::
|
||||
++ ecca :: [hasp path]
|
||||
|= [orx=oryx moh=moth]
|
||||
^- (unit ,[hasp path])
|
||||
=+ jun=(ecci orx moh)
|
||||
?~ jun ~
|
||||
=+ ^- (unit ,[his=term app=term pax=term])
|
||||
%. u.jun
|
||||
%- ot:jo
|
||||
~[[%ship so:jo] [%appl so:jo] [%path so:jo]]
|
||||
?~ - ~
|
||||
=+ his=(slaw %p (cat 3 '~' his.u))
|
||||
?~ his ~
|
||||
=+ ^= pax
|
||||
%+ rush pax.u
|
||||
;~(pfix fas (more fas (cook crip (plus ;~(pose low nud hep)))))
|
||||
?~ pax ~
|
||||
`[[u.his app.u] u.pax]
|
||||
::
|
||||
++ ecce :: JS from moth
|
||||
|= moh=moth
|
||||
^- (unit json)
|
||||
@ -218,6 +238,20 @@
|
||||
=+ zeb=(~(get by mah) cus)
|
||||
$(hed t.hed, mah (~(put by mah) cus ?~(zeb [q.i.hed ~] [q.i.hed u.zeb])))
|
||||
::
|
||||
++ eccu :: [hasp json]
|
||||
|= [orx=oryx moh=moth]
|
||||
^- (unit ,[hasp json])
|
||||
=+ jun=(ecci orx moh)
|
||||
?~ jun ~
|
||||
=+ ^- (unit ,[his=term app=term jon=json])
|
||||
%. u.jun
|
||||
%- ot:jo
|
||||
~[[%ship so:jo] [%appl so:jo] [%data |=(json (some +<))]]
|
||||
?~ - ~
|
||||
=+ his=(slaw %p (cat 3 '~' his.u))
|
||||
?~ his ~
|
||||
`[[u.his app.u] jon.u]
|
||||
::
|
||||
++ lopo :: cage to love
|
||||
|= cay=cage
|
||||
^- love
|
||||
@ -372,13 +406,15 @@
|
||||
[p.+.sih (slot 3 (spec (slot 3 [typ +.sih])))]
|
||||
:- %json
|
||||
!>
|
||||
?> ?=(json q.q.q.+.sih)
|
||||
=+ can=(need (~(get by can.sub.siq.u.ouy) (slav %ud i.t.mab)))
|
||||
%- jobe
|
||||
?< ?=(~ t.mab)
|
||||
=+ can=(need (~(get by can.sub.siq:beat:u.ouy) (slav %ud i.t.mab)))
|
||||
:- %o
|
||||
%- mo
|
||||
^- (list ,[@t *])
|
||||
:~ [%ship %s (scot %p p.p.can)]
|
||||
[%appl %s q.p.can]
|
||||
[%path %s q.can]
|
||||
[%data q.q.q.+.sih]
|
||||
[%data q.+.sih]
|
||||
==
|
||||
(hear:woy ~ ?:(?=(%rust -.+.sih) [%& cay] [%| cay]))
|
||||
==
|
||||
@ -1065,7 +1101,7 @@
|
||||
|
||||
method = "put"
|
||||
perm = "tih"
|
||||
url = [perm,user,appl,port,heart.seqn]
|
||||
url = [perm,user,port,heart.seqn]
|
||||
url = "/"+url.join("/")
|
||||
|
||||
$this = this
|
||||
@ -1087,11 +1123,11 @@
|
||||
}
|
||||
heart.beat()
|
||||
'''
|
||||
++ duty :: reload script
|
||||
++ duty :: reload script XX
|
||||
;script
|
||||
; var tries = 0;
|
||||
; var cnt = 0;
|
||||
; var next = "/gie/"+user+"/"+appl+"/"+port+"/0/"+(cnt + 1);
|
||||
; var next = "/gie/"+user+"/"+port+"/0/"+(cnt + 1);
|
||||
; call = function() {
|
||||
; xhr = new XMLHttpRequest();
|
||||
; xhr.open('GET', next, true);
|
||||
@ -1120,12 +1156,12 @@
|
||||
|= [fur=(unit term) you=@p paw=path]
|
||||
^- (unit seam)
|
||||
?> ?=(~ fur)
|
||||
?> ?=([@ @ @ @ ~] paw)
|
||||
?> ?=([@ @ ~] paw)
|
||||
:- ~
|
||||
:* %ape
|
||||
you
|
||||
(slav %ui (cat 3 '0i' i.paw))
|
||||
(slav %ui (cat 3 '0i' i.t.paw))
|
||||
(slav %ui (cat 3 '0i' i.t.t.t.paw))
|
||||
==
|
||||
::
|
||||
++ fapg :: dispatch %apg
|
||||
@ -1145,12 +1181,12 @@
|
||||
|= [fur=(unit term) you=@p paw=path moh=moth]
|
||||
^- (unit seam)
|
||||
?> ?=(~ fur)
|
||||
?> ?=([@ @ @ ~] paw)
|
||||
?> ?=([@ @ ~] paw)
|
||||
:- ~
|
||||
:* %aph
|
||||
you
|
||||
(slav %ui (cat 3 '0i' i.paw))
|
||||
(slav %ui (cat 3 '0i' i.t.paw))
|
||||
(slav %ui (cat 3 '0i' i.t.t.paw))
|
||||
(need (ecci orx.ced moh))
|
||||
==
|
||||
::
|
||||
@ -1158,31 +1194,30 @@
|
||||
|= [fur=(unit term) you=@p paw=path moh=moth]
|
||||
^- (unit seam)
|
||||
?> ?=(~ fur)
|
||||
?> ?=([@ @ @ ~] paw)
|
||||
?> ?=([@ @ ~] paw)
|
||||
:- ~
|
||||
:* %apm
|
||||
you
|
||||
(slav %ui (cat 3 '0i' i.paw))
|
||||
(slav %ui (cat 3 '0i' i.t.paw))
|
||||
(slav %ui (cat 3 '0i' i.t.t.paw))
|
||||
(need (ecci orx.ced moh))
|
||||
(need (eccu orx.ced moh))
|
||||
==
|
||||
::
|
||||
++ faps :: dispatch %aps
|
||||
|= [fur=(unit term) you=@p paw=path moh=moth]
|
||||
^- (unit seam)
|
||||
?> ?=(~ fur)
|
||||
?> ?=([@ @ @ *] paw)
|
||||
?> !=(~ (ecci orx.ced moh))
|
||||
?> ?=([@ @ ~] paw)
|
||||
:- ~
|
||||
:* %aps
|
||||
you
|
||||
(slav %ui (cat 3 '0i' i.paw))
|
||||
(slav %ui (cat 3 '0i' i.t.paw))
|
||||
(slav %ui (cat 3 '0i' i.t.t.paw))
|
||||
(turn t.t.t.paw |=(a=@ `@ta`(need ((sand %ta) a))))
|
||||
==
|
||||
(need (ecca orx.ced moh))
|
||||
==
|
||||
::
|
||||
++ fapu :: dispatch %apu
|
||||
|= [fur=(unit term) you=@p paw=path]
|
||||
|= [fur=(unit term) you=@p paw=path moh=moth]
|
||||
^- (unit seam)
|
||||
?> ?=(~ fur)
|
||||
?> ?=([@ @ @ ~] paw)
|
||||
@ -1191,6 +1226,7 @@
|
||||
you
|
||||
(slav %ui (cat 3 '0i' i.t.paw))
|
||||
(slav %ui (cat 3 '0i' i.t.t.paw))
|
||||
(need (ecca orx.ced moh))
|
||||
==
|
||||
::
|
||||
++ flea :: permissive decimal
|
||||
@ -1447,7 +1483,7 @@
|
||||
%l (foom moh)
|
||||
%m (fapm p.q.pul yun paw moh)
|
||||
%s (faps p.q.pul yun paw moh)
|
||||
%u (fapu p.q.pul yun paw)
|
||||
%u (fapu p.q.pul yun paw moh)
|
||||
==
|
||||
::
|
||||
%t
|
||||
@ -1456,7 +1492,7 @@
|
||||
%h (faph p.q.pul yun paw moh)
|
||||
%m (fapm p.q.pul yun paw moh)
|
||||
%s (faps p.q.pul yun paw moh)
|
||||
%u (fapu p.q.pul yun paw)
|
||||
%u (fapu p.q.pul yun paw moh)
|
||||
==
|
||||
==
|
||||
::
|
||||
@ -2011,20 +2047,20 @@
|
||||
[- abet:+]:(beat:u.yon cnt num jon)
|
||||
::
|
||||
++ yokm :: message
|
||||
|= [num=@ud you=ship nap=@ud cnt=@ud jon=json]
|
||||
|= [num=@ud you=ship nap=@ud cnt=@ud hap=hasp jon=json]
|
||||
^+ +>
|
||||
=+ yon=(yolk nap)
|
||||
?~ yon (bust 204 num)
|
||||
abet:(post:u.yon cnt num jon)
|
||||
abet:(post:u.yon cnt num hap jon)
|
||||
::
|
||||
++ yoks :: subscribe
|
||||
|= [num=@ud you=ship nap=@ud suq=@ud pax=path]
|
||||
|= [num=@ud you=ship nap=@ud suq=@ud hap=hasp pax=path]
|
||||
=+ yon=(yolk nap)
|
||||
?~ yon (bust 204 num)
|
||||
abet:(scud:u.yon suq num pax)
|
||||
abet:(scud:u.yon num hap pax)
|
||||
::
|
||||
++ yoku :: unsubscribe
|
||||
|= [num=@ud you=ship nap=@ud suq=@ud]
|
||||
|= [num=@ud you=ship nap=@ud suq=@ud hap=hasp pax=path]
|
||||
!!
|
||||
::
|
||||
++ yolk :: yo by instance
|
||||
@ -2054,7 +2090,7 @@
|
||||
%= $
|
||||
wuh t.wuh
|
||||
..amok
|
||||
(pass(hen r.q.i.wuh) p.i.wuh `note`[%g %nuke p.p.q.i.wuh you])
|
||||
(pass(hen r.q.i.wuh) `p.i.wuh `note`[%g %nuke p.q.i.wuh you])
|
||||
==
|
||||
::
|
||||
++ beat
|
||||
@ -2062,7 +2098,7 @@
|
||||
^- [(unit pimp) _+>]
|
||||
?. =(cnt num.bet.siq)
|
||||
[~ +>.$(..yo (bust 204 num))]
|
||||
=. bet.siq [+(num.bet.siq) now]
|
||||
=. bet.siq bet.siq(num +(num.bet.siq), tim now)
|
||||
=. +>.$ (hire:(yule %bet) cnt num)
|
||||
=. +>.$ (hear:(yule %bet) ~ %& %json !>((joba %a-ok %b %&)))
|
||||
[`(need (~(get by q.rey) num)) +>.$]
|
||||
@ -2085,29 +2121,29 @@
|
||||
+>(mow [[hen %pass (hoop can) noh] mow])
|
||||
::
|
||||
++ post :: transmit
|
||||
|= [hap=hasp cnt=@ud num=@ud jon=json]
|
||||
|= [cnt=@ud num=@ud hap=hasp jon=json]
|
||||
^+ +>
|
||||
=. +>.$
|
||||
?. =(cnt num.meg.siq) +>.$
|
||||
%+ pass(num.meg.siq +(num.meg.siq)) ~
|
||||
`note`[%g %mess [our app] you [%json !>(jon)]]
|
||||
`note`[%g %mess hap you [%json !>(jon)]]
|
||||
?. =(+(cnt) num.meg.siq)
|
||||
+>.$(..yo (bust 204 num))
|
||||
(hire:(yule %meg) cnt num)
|
||||
::
|
||||
++ scud :: subscribe
|
||||
|= [num=@ud hap=hasp pax=path]
|
||||
=. can.sub.siq (~(put by num.sub.siq) [hap pax hen])
|
||||
=. +>.$ (pass num.sub.siq `note`[%g %show hap you pax])
|
||||
=. can.sub.siq (~(put by can.sub.siq) num.sub.siq [hap pax hen])
|
||||
=. +>.$ (pass `num.sub.siq `note`[%g %show hap you pax])
|
||||
=. num.sub.siq +(num.sub.siq)
|
||||
(hire:(yule %sub) 0 num)
|
||||
(hire:(yule %sub) 1 num)
|
||||
::
|
||||
++ self :: request main
|
||||
|= [app=term pax=path]
|
||||
^+ +>
|
||||
=. can.sub.siq (~(put by 0) [hap pax hen])
|
||||
=. can.sub.siq (~(put by can.sub.siq) 0 [[our app] pax hen])
|
||||
=. num.sub.siq +(num.sub.siq)
|
||||
(hire:(yule:(pass 0 [%g %show [our app] you pax]) %sub) 0 nap)
|
||||
(hire:(yule:(pass `0 [%g %show [our app] you pax]) %sub) 0 nap)
|
||||
::
|
||||
++ yule
|
||||
|= pla=?(%bet %meg %sub)
|
||||
@ -2118,9 +2154,9 @@
|
||||
++ abet
|
||||
^+ ..yu
|
||||
?- pla
|
||||
%bet %_(..yu wig.bet wig)
|
||||
%meg %_(..yu wig.meg wig)
|
||||
%sub %_(..yu wig.sub wig)
|
||||
%bet %_(..yu wig.bet.siq wig)
|
||||
%meg %_(..yu wig.meg.siq wig)
|
||||
%sub %_(..yu wig.sub.siq wig)
|
||||
==
|
||||
::
|
||||
++ busk :: seam result
|
||||
@ -2143,7 +2179,7 @@
|
||||
=+ pip=u.pup
|
||||
=+ ^= sip
|
||||
?. =(%apg -.som.pip) sip.pip
|
||||
[duti duty sip.pip]
|
||||
[duti sip.pip]
|
||||
?~ huq +>.$(..yo (bust 404 num))
|
||||
%= +>.$
|
||||
q.rey
|
||||
@ -2153,7 +2189,6 @@
|
||||
%= pip
|
||||
pez %new
|
||||
vaz :~ [%ship (quo (rsh 3 1 (scot %p our)))]
|
||||
[%appl (quo app)]
|
||||
[%port (trip (rsh 3 2 (scot %ui nap)))]
|
||||
[%auto "true"]
|
||||
[%oryx (quo orx.ced)]
|
||||
@ -2176,7 +2211,7 @@
|
||||
^+ ..yu
|
||||
=+ dum=(~(tap by wan.wig) ~)
|
||||
|- ^+ ..yu
|
||||
?~ dum amok
|
||||
?~ dum ..yu :: XX drop stream
|
||||
$(dum t.dum, ..yo (bust 404 q.i.dum))
|
||||
::
|
||||
++ hear :: produce
|
||||
@ -2194,6 +2229,7 @@
|
||||
wan.wig ?~(dul wan.wig (~(del by wan.wig) cnt.wig))
|
||||
red.wig (~(put by red.wig) cnt.wig huq)
|
||||
==
|
||||
~& [%hear pla ?=(~ dul)]
|
||||
?~(dul +>.$ (busk u.dul cnt huq))
|
||||
::
|
||||
++ hire :: consume
|
||||
|
@ -6748,7 +6748,7 @@
|
||||
[%fork *] $(sut p.sut)
|
||||
[%hold *] ?: (~(has in gil) sut)
|
||||
~_ (dunk %type)
|
||||
~|(%burn-loop !!)
|
||||
~|(%burn-loop !!)
|
||||
$(sut repo, gil (~(put in gil) sut))
|
||||
%noun 0
|
||||
%void ~|(%burn-void !!)
|
||||
|
296
main/lib/urb.js
296
main/lib/urb.js
@ -1,113 +1,183 @@
|
||||
window.urb = {
|
||||
ship: ship,
|
||||
port: port,
|
||||
auto: auto,
|
||||
oryx: oryx,
|
||||
user: user,
|
||||
appl: appl,
|
||||
seqn: 0,
|
||||
seqp: 1,
|
||||
seqs: 3,
|
||||
dely: 0,
|
||||
|
||||
req: function(method,url,data,json,cb) {
|
||||
var xhr = new XMLHttpRequest()
|
||||
xhr.open(method.toUpperCase(), url)
|
||||
if(json)
|
||||
xhr.setRequestHeader("content-type", "text/json")
|
||||
if(data)
|
||||
xhr.send(JSON.stringify({oryx: oryx, xyro: data}))
|
||||
else
|
||||
xhr.send({oryx: oryx})
|
||||
if(cb) {
|
||||
xhr.onload = function() {
|
||||
cb(null,{
|
||||
"status":this.status,
|
||||
"data":JSON.parse(this.responseText)
|
||||
})
|
||||
}
|
||||
xhr.onerror = function() {
|
||||
cb({
|
||||
"status":this.status,
|
||||
"data":this.responseText
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
subscribe: function(path,cb) {
|
||||
if(!cb)
|
||||
throw new Error("You must supply a callback to urb.subscribe.")
|
||||
|
||||
var method, perm, url, $this
|
||||
|
||||
method = "put"
|
||||
perm = "tis"
|
||||
url = [perm,this.user,this.appl,this.port]
|
||||
if(path) {
|
||||
url.push(this.seqs)
|
||||
url.push(path)
|
||||
}
|
||||
console.log(url)
|
||||
url = "/"+url.join("/")
|
||||
|
||||
|
||||
$this = this
|
||||
this.req(method,url,{},true,function(err,data) {
|
||||
cb.apply(this,arguments)
|
||||
if(!err) { $this.poll($this.seqs++,cb); }
|
||||
})
|
||||
},
|
||||
|
||||
send: function(data,cb) {
|
||||
if(!data) { data = {}; }
|
||||
if(!cb) { cb = function() {}; }
|
||||
|
||||
var method, perm, url, $this
|
||||
|
||||
method = "put"
|
||||
perm = "tim"
|
||||
url = [perm,this.user,this.appl,this.port,this.seqn]
|
||||
url = "/"+url.join("/")
|
||||
|
||||
this.seqn++
|
||||
|
||||
$this = this
|
||||
this.req(method,url,data,true,function(err,data) {
|
||||
if(err) { $this.seqn--; }
|
||||
cb.apply(this,arguments)
|
||||
})
|
||||
},
|
||||
|
||||
poll: function(stream,cb) {
|
||||
if(!stream)
|
||||
throw new Error("You must supply a stream to urb.poll.")
|
||||
if(!cb)
|
||||
throw new Error("You must supply a callback to urb.poll.")
|
||||
|
||||
var method, perm, url, $this
|
||||
|
||||
method = "get"
|
||||
perm = "gie"
|
||||
if(!stream) { return false; }
|
||||
url = [perm,this.user,this.appl,this.port,stream,this.seqp]
|
||||
url = "/"+url.join("/")
|
||||
console.log(url)
|
||||
|
||||
$this = this
|
||||
this.req(method,url,null,false,function(err,data) {
|
||||
if(cb.apply(this,arguments) === false) { return; }
|
||||
|
||||
if(err)
|
||||
$this.dely += 1000
|
||||
else {
|
||||
$this.dely = 0
|
||||
$this.seqp++
|
||||
}
|
||||
|
||||
setTimeout(function() {
|
||||
$this.poll(stream,cb)
|
||||
},$this.dely)
|
||||
})
|
||||
}
|
||||
}
|
||||
window.urb = {
|
||||
ship: ship,
|
||||
port: port,
|
||||
auto: auto,
|
||||
oryx: oryx,
|
||||
user: user,
|
||||
seqn_h: 0,
|
||||
seqn_u: 0,
|
||||
seqn_s: 0,
|
||||
dely: 0,
|
||||
puls: 0,
|
||||
perms: {
|
||||
sub:"tis",
|
||||
uns:"tiu",
|
||||
mes:"tim",
|
||||
heb:"tih"
|
||||
},
|
||||
cabs: {},
|
||||
|
||||
req: function(method,url,params,json,cb) {
|
||||
var xhr = new XMLHttpRequest()
|
||||
xhr.open(method.toUpperCase(), url)
|
||||
if(json)
|
||||
xhr.setRequestHeader("content-type", "text/json")
|
||||
|
||||
_data = {}
|
||||
if(params.data) { _data.data = params.data; }
|
||||
if(params.ship) { _data.ship = params.ship; }
|
||||
if(params.path) { _data.path = params.path; }
|
||||
if(params.appl) { _data.appl = params.appl; }
|
||||
__data = {oryx: oryx, xyro: _data}
|
||||
console.log(__data)
|
||||
xhr.send(JSON.stringify(__data))
|
||||
|
||||
if(cb) {
|
||||
xhr.onload = function() {
|
||||
cb(null,{
|
||||
"status":this.status,
|
||||
"data":JSON.parse(this.responseText)
|
||||
})
|
||||
}
|
||||
xhr.onerror = function() {
|
||||
cb({
|
||||
"status":this.status,
|
||||
"data":this.responseText
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
send: function(params,cb) {
|
||||
if(!params)
|
||||
throw new Error("You must supply params to urb.send.")
|
||||
if(!params.appl)
|
||||
throw new Error("You must specify an appl for urb.send.")
|
||||
if(!params.data) { params.data = {}; }
|
||||
|
||||
var method, perm, url, $this
|
||||
|
||||
type = params.type ? params.type : "mes"
|
||||
perm = this.perms[type]
|
||||
|
||||
params.ship = params.ship ? params.ship : this.ship
|
||||
|
||||
method = "put"
|
||||
url = [perm,this.user,this.port,this.seqn_s]
|
||||
url = "/"+url.join("/")
|
||||
|
||||
this.seqn_s++
|
||||
|
||||
$this = this
|
||||
this.req(method,url,params,true,function(err,data) {
|
||||
if(err) { $this.seqn_s--; }
|
||||
if(cb) { cb.apply(this,arguments); }
|
||||
})
|
||||
},
|
||||
|
||||
subscribe: function(appl,path,ship,cb) {
|
||||
if(!cb)
|
||||
throw new Error("You must supply a callback to urb.subscribe.")
|
||||
|
||||
var method, perm, url, $this
|
||||
|
||||
ship = ship ? ship : this.ship
|
||||
|
||||
method = "get"
|
||||
params = {
|
||||
type:"sub",
|
||||
appl:appl,
|
||||
path:path,
|
||||
ship:ship,
|
||||
incs:function() {
|
||||
this.seqn_u++
|
||||
}
|
||||
}
|
||||
|
||||
this.cabs[appl+path.replace(/[^\x00-\x7F]/g, "")+ship] = cb
|
||||
|
||||
type = params.type ? params.type : "mes"
|
||||
perm = this.perms[type]
|
||||
method = "put"
|
||||
url = [perm,this.user,this.port,this.seqn_u]
|
||||
url = "/"+url.join("/")
|
||||
|
||||
$this = this
|
||||
this.req(method,url,params,true,function(err,data) {
|
||||
if(cb) { cb.apply(this,arguments); }
|
||||
if(!err && $this.puls == 0) {
|
||||
params.incs()
|
||||
$this.poll(params,cb)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
unsubscribe: function(appl,path,ship,cb) {
|
||||
method = "put"
|
||||
type = "uns"
|
||||
perm = this.perms[type]
|
||||
url = [perm,this.user,this.port,this.seqn_u]
|
||||
url = "/"+url.join("/")
|
||||
|
||||
params = {
|
||||
appl: appl,
|
||||
path: path,
|
||||
ship: ship
|
||||
}
|
||||
|
||||
fn = appl+path.replace(/[^\x00-\x7F]/g, "")+ship
|
||||
this.cabs[fn]('subscription closed')
|
||||
|
||||
this.req(method,url,params,true,function() {
|
||||
console.log('ok unsubscribed')
|
||||
})
|
||||
},
|
||||
|
||||
heartbeat: function() {
|
||||
this.poll({
|
||||
type:"heb",
|
||||
ship:this.ship,
|
||||
incs:function() {
|
||||
this.seqn_h++
|
||||
}
|
||||
},function() {
|
||||
console.log('heartbeat.')
|
||||
})
|
||||
},
|
||||
|
||||
poll: function(params,cb) {
|
||||
if(!params)
|
||||
throw new Error("You must supply params to urb.poll.")
|
||||
|
||||
var method, perm, url, $this
|
||||
|
||||
method = "get"
|
||||
type = params.type ? params.type : "sub"
|
||||
perm = this.perms[type]
|
||||
url = [perm,this.user,this.port,params.seqn]
|
||||
url = "/"+url.join("/")
|
||||
|
||||
this.puls = 1
|
||||
|
||||
$this = this
|
||||
this.req(method,url,params,false,function(err,data) {
|
||||
if(cb) {
|
||||
cb.apply(this,arguments)
|
||||
} else {
|
||||
fn = data.appl+data.path.replace(/[^\x00-\x7F]/g, "")+data.ship
|
||||
$this.cabs[fn].apply(this,arguments)
|
||||
}
|
||||
|
||||
if(err)
|
||||
$this.dely += 1000
|
||||
else {
|
||||
$this.dely = 0
|
||||
params.incs()
|
||||
}
|
||||
|
||||
setTimeout(function() {
|
||||
$this.poll(params,cb)
|
||||
},$this.dely)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user