Completed work on RDP clipboard support.

Ylian Saint-Hilaire committed May 16, 2022 at 12:44 UTC 0d723df2e8348d52c4a11d155104998aeb46e0b9
3 files changed +20 -12
apprelays.js
-1
@@ -203,7 +203,6 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain) {
203 send(['rdp-bitmap', bitmap]); // Send the bitmap metadata seperately, without bitmap data.
204 }).on('clipboard', function (content) {
205 // Clipboard data changed
206 - console.log('RDP clipboard recv', content);
206 send(['rdp-clipboard', content]);
207 }).on('close', function () {
208 send(['rdp-close']);
public/scripts/agent-rdp-0.0.1.js
+3 -4
@@ -15,6 +15,7 @@ var CreateRDPDesktop = function (canvasid) {
15 obj.Canvas = obj.CanvasId.getContext('2d');
16 obj.ScreenWidth = obj.width = 1280;
17 obj.ScreenHeight = obj.height = 1024;
18 + obj.m.onClipboardChanged = null;
19
20 function mouseButtonMap(button) {
21 // Swap mouse buttons if needed
@@ -83,10 +84,7 @@ var CreateRDPDesktop = function (canvasid) {
84 obj.Stop();
85 break;
86 }
86 - case 'rdp-clipboard': {
87 - console.log('clipboard', msg[1]);
88 - break;
89 - }
87 + case 'rdp-clipboard': { obj.lastClipboardContent = msg[1]; if (obj.m.onClipboardChanged) { obj.m.onClipboardChanged(msg[1]); } break; }
88 case 'ping': { obj.socket.send('["pong"]'); break; }
89 case 'pong': { break; }
90 }
@@ -105,6 +103,7 @@ var CreateRDPDesktop = function (canvasid) {
103 }
104
105 obj.m.setClipboard = function (content) { if (obj.socket) { obj.socket.send(JSON.stringify(['clipboard', content])); } }
106 + obj.m.getClipboard = function () { return obj.lastClipboardContent; }
107
108 function changeState(newstate) {
109 if (obj.State == newstate) return;
views/default.handlebars
+17 -7
@@ -1371,6 +1371,7 @@
1371 <label style="display:block"><input type="checkbox" id="d7rdp7" />Disable Cursor Settings</label>
1372 <label style="display:block"><input type="checkbox" id="d7rdp8" />Enable Font Smooting</label>
1373 <label style="display:block"><input type="checkbox" id="d7rdp9" />Enable Desktop Composision</label>
1374 + <label style="display:block"><input type="checkbox" id="d7rdpclip" />Automatic Clipboard</label>
1375 <label style="display:block"><input type="checkbox" id="d7rdpsmb" />Swap Mouse Buttons</label>
1376 </div>
1377 </div>
@@ -7559,7 +7560,12 @@
7560
7561 function deskClipboardInFunction() {
7562 if (desktop == null || desktop.State != 3) return;
7562 - meshserver.send({ action: 'msg', type: 'getclip', nodeid: currentNode._id, tag: 2 });
7563 + if (desktop.m.getClipboard) {
7564 + var text = desktop.m.getClipboard();
7565 + if ((text != null) && (navigator.clipboard != null)) { navigator.clipboard.writeText(text).then(function() { }).catch(function(err) { console.log(err); }) } // Put remote clipboard data into our clipboard
7566 + } else {
7567 + meshserver.send({ action: 'msg', type: 'getclip', nodeid: currentNode._id, tag: 2 });
7568 + }
7569 }
7570
7571 // Called to lock or unlock remote desktop user input
@@ -8339,7 +8345,6 @@
8345 QE('connectbutton1h', hwonline);
8346 QV('deskFocusBtn', (desktop != null) && (desktop.contype == 2) && (deskState != 0) && (desktopsettings.showfocus));
8347 QE('DeskClip', deskState == 3);
8342 - //QE('DeskClip', (deskState == 3) && (desktop.contype != 4));
8348 QV('DeskClip', (inputAllowed) && (currentNode.agent) && ((features2 & 0x1800) != 0x1800) && (currentNode.agent.id != 11) && (currentNode.agent.id != 16) && ((desktop == null) || (desktop.contype != 2)) && ((desktopsettings.autoclipboard != true) || (navigator.clipboard == null) || (navigator.clipboard.readText == null))); // Clipboard not supported on macOS
8349 QE('DeskESC', (deskState == 3) && (desktop.contype != 4));
8350 QV('DeskESC', browserfullscreen && inputAllowed);
@@ -8352,10 +8357,10 @@
8357 QV('DeskTimer', deskState == 3);
8358
8359 // Enable browser clipboard read if supported
8355 - QV('DeskClipboardOutButton', online && inputAllowed && ((desktop == null) || (desktop.contype != 4)) && ((features2 & 0x1000) == 0) && (navigator.clipboard != null) && (navigator.clipboard.readText != null) && ((desktopsettings.autoclipboard != true) || (navigator.clipboard == null) || (navigator.clipboard.readText == null)));
8360 + var autoclipboard = ((desktop) && (desktop.contype == 4)) ? desktopsettings.rdpautoclipboard : desktopsettings.autoclipboard;
8361 + QV('DeskClipboardOutButton', online && inputAllowed && (desktop != null) && ((features2 & 0x1000) == 0) && (navigator.clipboard != null) && (navigator.clipboard.readText != null) && ((autoclipboard != true) || (navigator.clipboard == null) || (navigator.clipboard.readText == null)));
8362 QV('d7deskAutoClipboardLabel', (navigator.clipboard.readText != null) && ((features2 & 0x1000) == 0));
8357 - QV('DeskClipboardInButton', online && inputAllowed && ((desktop == null) || (desktop.contype != 4)) && ((features2 & 0x0800) == 0) && (navigator.clipboard != null) && (navigator.clipboard.writeText != null) && ((desktopsettings.autoclipboard != true) || (navigator.clipboard == null) || (navigator.clipboard.readText == null)));
8358 -
8363 + QV('DeskClipboardInButton', online && inputAllowed && (desktop != null) && ((features2 & 0x0800) == 0) && (navigator.clipboard != null) && (navigator.clipboard.writeText != null) && ((autoclipboard != true) || (navigator.clipboard == null) || (navigator.clipboard.readText == null)));
8364 if (deskState != 3) {
8365 QV('DeskInputLockedButton', false);
8366 QV('DeskInputUnLockedButton', false);
@@ -8539,6 +8544,7 @@
8544 desktop = CreateRDPDesktop('Desk');
8545 desktop.onStateChanged = onDesktopStateChange;
8546 desktop.m.onScreenSizeChange = mdeskAdjust;
8547 + desktop.m.onClipboardChanged = function(text) { if ((text != null) && (desktopsettings.rdpautoclipboard) && (navigator.clipboard != null)) { navigator.clipboard.writeText(text).then(function() { }).catch(function(err) { console.log(err); }) } } // Put remote clipboard data into our clipboard
8548 if (desktopsettings.rdpsmb) { desktop.m.SwapMouse = desktopsettings.rdpsmb; }
8549 desktop.Start(desktopNode._id, currentNode.rdpport ? currentNode.rdpport : 3389, tsid);
8550 desktop.contype = 4;
@@ -8740,11 +8746,13 @@
8746 if (desktop.latency && (desktop.latency.current >= 0)) { latencyStr = format('{0} ms, ', desktop.latency.current); }
8747 seconds = Math.floor((new Date() - desktop.startTime) / 1000);
8748 QH('DeskTimer', latencyStr + zeroPad(Math.floor(seconds / 3600), 2) + ':' + zeroPad((Math.floor(seconds / 60) % 60), 2) + ':' + zeroPad((seconds % 60), 2));
8743 - if ((desktopsettings.autoclipboard === true) && (navigator.clipboard != null) && (navigator.clipboard.readText != null)) {
8749 + // Auto-clipboard
8750 + if ((((desktop.contype != 4) && (desktopsettings.autoclipboard === true)) || ((desktop.contype == 4) && (desktopsettings.rdpautoclipboard === true))) && (navigator.clipboard != null) && (navigator.clipboard.readText != null)) {
8751 try {
8752 navigator.clipboard.readText().then(function(text) {
8753 + if (desktop == null) return;
8754 if ((text != null) && (deskLastClipboardSent != text)) {
8747 - if (desktop.m.setClipboard) { desktop.m.setClipboard(text); } else { meshserver.send({ action: 'msg', type: 'setclip', nodeid: currentNode._id, data: text }); }
8755 + if (desktop.m.setClipboard) { desktop.m.setClipboard(text); } else { console.log('s3'); meshserver.send({ action: 'msg', type: 'setclip', nodeid: currentNode._id, data: text }); }
8756 deskLastClipboardSent = text;
8757 }
8758 }).catch(function(err) { });
@@ -8816,6 +8824,7 @@
8824 desktopsettings.localkeymap = d7localKeyMap.checked;
8825 desktopsettings.rdpsize = d7rdpsize.value;
8826 desktopsettings.rdpsmb = d7rdpsmb.checked;
8827 + desktopsettings.rdpautoclipboard = d7rdpclip.checked;
8828 var rdpflags = 0;
8829 for (var i = 1; i < 10; i++) { if ((i != 5) && (Q('d7rdp' + i).checked)) { rdpflags |= (1 << (i - 1)); } }
8830 desktopsettings.rdpflags = rdpflags;
@@ -8858,6 +8867,7 @@
8867 if (desktopsettings.rdpsize != null) { d7rdpsize.value = desktopsettings.rdpsize; }
8868 if (desktopsettings.rdpflags == null) { desktopsettings.rdpflags = 0x2F; }
8869 if (desktopsettings.rdpsmb != null) { d7rdpsmb.checked = desktopsettings.rdpsmb; }
8870 + if (desktopsettings.rdpautoclipboard != null) { d7rdpclip.checked = desktopsettings.rdpautoclipboard; }
8871 for (var i = 1; i < 10; i++) { if (i != 5) { Q('d7rdp' + i).checked = ((desktopsettings.rdpflags & (1 << (i - 1))) != 0); } }
8872 }
8873