add set remote clipboard to web-rdp #4133

Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
si458 2024-01-14 17:42:43 +00:00
parent b01078bf55
commit 9986567cf0

View File

@ -18,6 +18,7 @@
*/ */
/* /*
* added get clipboard from remote RDP - Simon Smith 2024 * added get clipboard from remote RDP - Simon Smith 2024
* added set clipboard to remote RDP - Simon Smith 2024
*/ */
(function() { (function() {
@ -176,6 +177,19 @@
options: options, options: options,
locale: Mstsc.locale() 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) { this.socket.onmessage = function (evt) {
if (typeof evt.data == 'string') { if (typeof evt.data == 'string') {
@ -226,6 +240,8 @@
this.socket.onclose = function () { this.socket.onclose = function () {
//console.log("WS-CLOSE"); //console.log("WS-CLOSE");
self.activeSession = false; self.activeSession = false;
clearInterval(self.clipboardReadTimer);
self.prevClipboardText = null;
next(null); next(null);
}; };
} }