Added ability to quit channel from rver
:: %unsubscribe: unsubscribes from an application path
::
[%unsubscribe request-id=@ud subscription-id=@ud]
+ :: %delete: kills a channel
+ ::
+ [%delete ~]
==
:: channel-timeout: the delay before a channel should be reaped
::
%. item
%+ pe %unsubscribe
(ot id+ni subscription+ni ~)
+ ?: =('delete' u.maybe-key)
+ `[%delete ~]
:: if we reached this, we have an invalid action key. fail parsing.
::
~
// the functions will be called, and the outstanding poke will be
// removed after calling the success or failure function.
//
+
this.outstandingPokes = new Map();
// a registry of requestId to subscription functions.
// disconnect function may be called exactly once.
//
this.outstandingSubscriptions = new Map();
+
+ this.deleteOnUnload();
+ }
+
+ deleteOnUnload() {
+ window.addEventListener('beforeunload', (event) => {
+ this.delete();
+ });
}
// sends a poke to an app on an urbit ship
return id;
}
+ // quit the channel
+ //
+ delete() {
+ var id = this.nextId();
+ this.sendJSONToChannel({
+ "id": id,
+ "action": "delete"
+ }, false);
+ }
+
// unsubscribe to a specific subscription
//
unsubscribe(subscriptionId) {
// sends a JSON command command to the server.
//
- sendJSONToChannel(j) {
+ sendJSONToChannel(j, connectAgain = true) {
var req = new XMLHttpRequest();
req.open("PUT", this.channelURL());
req.setRequestHeader("Content-Type", "application/json");
this.lastEventId = this.lastAcknowledgedEventId;
}
+ if (connectAgain) {
this.connectIfDisconnected();
}
+ }
// connects to the EventSource if we are not currently connected
//
var obj = JSON.parse(e.data);
if (obj.response == "poke") {
var funcs = this.outstandingPokes.get(obj.id);
- if (obj.hasOwnProperty("ok"))
+ if (obj.hasOwnProperty("ok")) {
funcs["success"]()
- else if (obj.hasOwnProperty("err"))
+ } else if (obj.hasOwnProperty("err")) {
funcs["fail"](obj.err)
- else
+ } else {
console.log("Invalid poke response: ", obj);
+ }
this.outstandingPokes.delete(obj.id);
} else if (obj.response == "subscribe") {
channel(subscriptions (~(del by subscriptions.channel) channel-wire))
::
$(requests t.requests)
+ ::
+ %delete
+ =/ session
+ (~(got by session.channel-state.state) channel-id)
+ ::
+ =. session.channel-state.state
+ (~(del by session.channel-state.state) channel-id)
+ =. gall-moves
+ %+ weld
+ gall-moves
+ ::
+ :: produce a list of moves which cancels every gall subscription
+ ::
+ %+ turn ~(tap by subscriptions.session)
+ |= [channel-wire=path ship=@p app=term =path]
+ ^- move
+ ::
+ [duct %pass channel-wire [%g %deal [our ship] app %pull ~]]
+ ::
+ $(requests t.requests)
+ ::
==
:: +on-gall-response: turns a gall response into an event
::
