diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2025-05-08 13:04:22 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2025-05-08 13:33:59 +0200 |
commit | a3dd82d6be22d5874136688f27f58dd9e67971cf (patch) | |
tree | af94838d7149ed83ec2c4446f59ac15f817dfcca /xP | |
parent | d572cfeb40b996a898f6d67d273fac2fab37c86e (diff) | |
download | xK-a3dd82d6be22d5874136688f27f58dd9e67971cf.tar.gz xK-a3dd82d6be22d5874136688f27f58dd9e67971cf.tar.xz xK-a3dd82d6be22d5874136688f27f58dd9e67971cf.zip |
Event the smallest protocol change has great consequences.
Relay events have been reordered to improve forward compatibility.
WIP:
- xM handling (send)
- xA handling (relaySend)
- xC: fix connection killing
Diffstat (limited to 'xP')
-rw-r--r-- | xP/public/xP.js | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/xP/public/xP.js b/xP/public/xP.js index 6035db3..bc91bb3 100644 --- a/xP/public/xP.js +++ b/xP/public/xP.js @@ -69,14 +69,22 @@ class RelayRPC extends EventTarget { let e = message.data switch (e.event) { case Relay.Event.Error: - if (this.promised[e.commandSeq] !== undefined) - this.promised[e.commandSeq].reject(e.error) + let p = this.promised[e.commandSeq] + // TODO(p): Network indicator. + if (p === true) + break + else if (p !== undefined) + p.reject(e.error) else console.error(`Unawaited error: ${e.error}`) break case Relay.Event.Response: - if (this.promised[e.commandSeq] !== undefined) - this.promised[e.commandSeq].resolve(e.data) + let p = this.promised[e.commandSeq] + // TODO(p): Network indicator. + if (p === true) + break + else if (p !== undefined) + p.resolve(e.data) else console.error("Unawaited response") break @@ -110,6 +118,9 @@ class RelayRPC extends EventTarget { this.ws.send(JSON.stringify({commandSeq: seq, data: params})) + // TODO(p): Network indicator. + this.promised[seq] = true + // Automagically detect if we want a result. let data = undefined const promise = new Promise( @@ -998,6 +1009,11 @@ let Input = { onKeyDown: event => { // TODO: And perhaps on other actions, too. + // TODO: Throttle these, for example by remembering when the last + // one was sent (or attempted to be sent), then setting a timeout + // and bumping that timeout when already present. + // Or even just refusing to resend it within a timeframe. + // This deserves a function. rpc.send({command: 'Active'}) let b = buffers.get(bufferCurrent) |