From 5162220e89112197eae7f4f8ef9ecb1eb0a6308d Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Sat, 29 Jun 2024 16:08:26 +0700 Subject: [PATCH] #143 use the same writer, remove debug delay --- html5/js/Client.js | 2 +- html5/js/Utilities.js | 4 ++++ html5/js/WebTransport.js | 16 ++++------------ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/html5/js/Client.js b/html5/js/Client.js index 180e8088..26974032 100644 --- a/html5/js/Client.js +++ b/html5/js/Client.js @@ -22,7 +22,7 @@ const FILE_SIZE_LIMIT = 4 * 1024 * 1024 * 1024; //are we even allowed to allocat const FILE_CHUNKS_SIZE = 128 * 1024; const MAX_CONCURRENT_FILES = 5; const CHUNK_TIMEOUT = 10 * 1000; -const WEBTRANSPORT = false; +const WEBTRANSPORT = true; const TEXT_PLAIN = "text/plain"; const UTF8_STRING = "UTF8_STRING"; diff --git a/html5/js/Utilities.js b/html5/js/Utilities.js index 768c6203..4961a9bf 100644 --- a/html5/js/Utilities.js +++ b/html5/js/Utilities.js @@ -101,6 +101,10 @@ const Utilities = { return hex; }, + arrayToHex(buffer) { + return Array.prototype.map.call(buffer, x => ('00' + x.toString(16)).slice(-2)).join(''); + }, + getPlatformProcessor() { //mozilla property: if (navigator.oscpu) { diff --git a/html5/js/WebTransport.js b/html5/js/WebTransport.js index 1a595a8e..98f7e6fa 100644 --- a/html5/js/WebTransport.js +++ b/html5/js/WebTransport.js @@ -16,6 +16,7 @@ class XpraWebTransportProtocol { this.packet_handler = null; this.webtransport = null; this.stream = null; + this.writer = null; this.raw_packets = []; this.rQ = []; // Receive queue this.sQ = []; // Send queue @@ -23,12 +24,7 @@ class XpraWebTransportProtocol { this.header = []; //Queue processing via intervals - this.process_interval = 1000; //milliseconds - } - - close_event_str(event) { - // TODO: re-use websocket `code_mappings`? - return ""+event; + this.process_interval = 0; //milliseconds } cancel_connected_timer() { @@ -97,14 +93,11 @@ class XpraWebTransportProtocol { console.error("error in read loop: "+e); handle(["close", "read loop error", e.toString()]) }); + this.writer = this.stream.writable.getWriter(); handle(["open"]); console.log("async open end"); } - toHex(buffer) { - return Array.prototype.map.call(buffer, x => ('00' + x.toString(16)).slice(-2)).join(''); - } - async read_loop() { const reader = this.stream.readable.getReader(); const me = this; @@ -113,7 +106,6 @@ class XpraWebTransportProtocol { if (done) { break; } - console.log("received: ", this.toHex(value)); this.rQ.push(value); setTimeout(() => me.process_receive_queue(), this.process_interval); } @@ -335,7 +327,7 @@ class XpraWebTransportProtocol { } packet_data.set(bdata, 8); if (this.stream) { - this.stream.writable.getWriter().write(new Uint8Array(packet_data).buffer); + this.writer.write(new Uint8Array(packet_data).buffer); } } }