From f5104c807dd749697f26c6d5e5c31ac981a19634 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch
Date: Tue, 6 Sep 2022 20:17:23 +0200 Subject: xP: indicate connection state --- xP/public/xP.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/xP/public/xP.js b/xP/public/xP.js index fd3a0ae..46b567a 100644 --- a/xP/public/xP.js +++ b/xP/public/xP.js @@ -24,8 +24,8 @@ class RelayRpc extends EventTarget { } // It's going to be code 1006 with no further info. ws.onclose = event => { - reject() this.ws = undefined + reject() } }) } @@ -122,15 +122,25 @@ class RelayRpc extends EventTarget { // ---- Event processing ------------------------------------------------------- -// TODO: Probably reset state on disconnect, and indicate to user. let rpc = new RelayRpc(proxy) -rpc.connect() - .then(result => { - rpc.send({command: 'Hello', version: 1}) - }) let buffers = new Map() let bufferCurrent = undefined +let connecting = true +rpc.connect().then(result => { + buffers.clear() + bufferCurrent = undefined + rpc.send({command: 'Hello', version: 1}) + connecting = false + m.redraw() +}).catch(error => { + connecting = false + m.redraw() +}) + +rpc.addEventListener('close', event => { + m.redraw() +}) rpc.addEventListener('BufferUpdate', event => { let e = event.detail, b = buffers.get(e.bufferName) @@ -374,8 +384,14 @@ let Input = { let Main = { view: vnode => { + let state = "Connected" + if (connecting) + state = "Connecting..." + else if (rpc.ws === undefined) + state = "Disconnected" + return m('.xP', {}, [ - m('.title', {}, "xP"), + m('.title', {}, `xP (${state})`), m('.middle', {}, [m(BufferList), m(Buffer)]), m('.status', {}, bufferCurrent), m(Input), -- cgit v1.2.3-70-g09d2