From 8c3ee80b21278eaa6fb29f73b79c16d443923dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Thu, 8 Sep 2022 02:33:44 +0200 Subject: [PATCH] xC/xP: finalize and implement Event.PING --- xC-proto | 22 ++++++++++++++-------- xP/public/xP.js | 7 ++++++- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/xC-proto b/xC-proto index c44f095..fd06491 100644 --- a/xC-proto +++ b/xC-proto @@ -8,11 +8,12 @@ struct CommandMessage { u32 command_seq; union CommandData switch (enum Command { HELLO, - PING, ACTIVE, - BUFFER_COMPLETE, BUFFER_INPUT, BUFFER_ACTIVATE, + PING_RESPONSE, + PING, + BUFFER_COMPLETE, BUFFER_LOG, } command) { case HELLO: @@ -20,19 +21,24 @@ struct CommandMessage { // If the version check succeeds, the client will receive // an initial stream of BUFFER_UPDATE, BUFFER_LINE, // and finally a BUFFER_ACTIVATE message. - case PING: - void; case ACTIVE: void; - case BUFFER_COMPLETE: - string buffer_name; - string text; - u32 position; case BUFFER_INPUT: string buffer_name; string text; case BUFFER_ACTIVATE: string buffer_name; + case PING_RESPONSE: + u32 event_seq; + + // Only these commands may produce Event.RESPONSE, as below, + // but any command may produce an error. + case PING: + void; + case BUFFER_COMPLETE: + string buffer_name; + string text; + u32 position; case BUFFER_LOG: string buffer_name; } data; diff --git a/xP/public/xP.js b/xP/public/xP.js index 42a7a55..eb27b46 100644 --- a/xP/public/xP.js +++ b/xP/public/xP.js @@ -85,7 +85,8 @@ class RelayRpc extends EventTarget { if (typeof e.event !== 'string') throw "Invalid event tag" - this.dispatchEvent(new CustomEvent(e.event, {detail: e})) + this.dispatchEvent(new CustomEvent( + e.event, {detail: {eventSeq: message.eventSeq, ...e}})) // Minor abstraction layering violation. m.redraw() @@ -153,6 +154,10 @@ rpc.addEventListener('close', event => { m.redraw() }) +rpc.addEventListener('Ping', event => { + rpc.send({command: 'PingResponse', eventSeq: event.detail.eventSeq}) +}) + rpc.addEventListener('BufferUpdate', event => { let e = event.detail, b = buffers.get(e.bufferName) if (b === undefined) {