aboutsummaryrefslogtreecommitdiff
path: root/xP
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-09-21 14:22:47 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-09-21 14:31:16 +0200
commit1f0e0b1ce40b765af744d025a83bb85e0994244d (patch)
tree74c5ea93e20ea66358f36672c58c897dda4218bb /xP
parent919b12510b49b7b32850b1153d04bb40506bf0a1 (diff)
downloadxK-1f0e0b1ce40b765af744d025a83bb85e0994244d.tar.gz
xK-1f0e0b1ce40b765af744d025a83bb85e0994244d.tar.xz
xK-1f0e0b1ce40b765af744d025a83bb85e0994244d.zip
xP: only care about RPC results if requested
This prevents "No response" errors from firing for most commands.
Diffstat (limited to 'xP')
-rw-r--r--xP/public/xP.js19
1 files changed, 13 insertions, 6 deletions
diff --git a/xP/public/xP.js b/xP/public/xP.js
index c8ceed0..f418d50 100644
--- a/xP/public/xP.js
+++ b/xP/public/xP.js
@@ -4,7 +4,7 @@ import * as Relay from './proto.js'
// ---- RPC --------------------------------------------------------------------
-class RelayRpc extends EventTarget {
+class RelayRPC extends EventTarget {
constructor(url) {
super()
this.url = url
@@ -72,7 +72,7 @@ class RelayRpc extends EventTarget {
if (this.promised[e.commandSeq] !== undefined)
this.promised[e.commandSeq].reject(e.error)
else
- console.error("Unawaited error")
+ console.error(`Unawaited error: ${e.error}`)
break
case Relay.Event.Response:
if (this.promised[e.commandSeq] !== undefined)
@@ -109,9 +109,16 @@ class RelayRpc extends EventTarget {
seq = this.commandSeq = 0
this.ws.send(JSON.stringify({commandSeq: seq, data: params}))
- return new Promise((resolve, reject) => {
- this.promised[seq] = {resolve, reject}
- })
+
+ // Automagically detect if we want a result.
+ let data = undefined
+ const promise = new Promise(
+ (resolve, reject) => { data = {resolve, reject} })
+ promise.then = (...args) => {
+ this.promised[seq] = data
+ return Promise.prototype.then.call(promise, ...args)
+ }
+ return promise
}
}
@@ -173,7 +180,7 @@ function updateIcon(highlighted) {
// ---- Event processing -------------------------------------------------------
-let rpc = new RelayRpc(proxy)
+let rpc = new RelayRPC(proxy)
let rpcEventHandlers = new Map()
let buffers = new Map()