diff options
Diffstat (limited to 'xP/public')
-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) |