From 9986567cf03caf4040a162acb14b7128daa77198 Mon Sep 17 00:00:00 2001 From: si458 Date: Sun, 14 Jan 2024 17:42:43 +0000 Subject: [PATCH] add set remote clipboard to web-rdp #4133 Signed-off-by: si458 --- public/mstsc/client.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/public/mstsc/client.js b/public/mstsc/client.js index 502c31e4..3294fe69 100644 --- a/public/mstsc/client.js +++ b/public/mstsc/client.js @@ -18,6 +18,7 @@ */ /* * added get clipboard from remote RDP - Simon Smith 2024 + * added set clipboard to remote RDP - Simon Smith 2024 */ (function() { @@ -176,6 +177,19 @@ options: options, locale: Mstsc.locale() }])); + self.prevClipboardText = null; + self.clipboardReadTimer = setInterval(function(){ + if(navigator.clipboard.readText != null){ + navigator.clipboard.readText() + .then(function(data){ + if(data != self.prevClipboard){ + self.prevClipboard = data; + if (self.socket) { self.socket.send(JSON.stringify(['clipboard', data])); } + } + }) + .catch(function(){ }); + } + }, 1000); }; this.socket.onmessage = function (evt) { if (typeof evt.data == 'string') { @@ -226,6 +240,8 @@ this.socket.onclose = function () { //console.log("WS-CLOSE"); self.activeSession = false; + clearInterval(self.clipboardReadTimer); + self.prevClipboardText = null; next(null); }; }