aboutsummaryrefslogtreecommitdiff
path: root/xP
diff options
context:
space:
mode:
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()