xP: only care about RPC results if requested
This prevents "No response" errors from firing for most commands.
This commit is contained in:
parent
919b12510b
commit
1f0e0b1ce4
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user