Improved websocket speed for MSTSC.js bitmaps.

This commit is contained in:
Ylian Saint-Hilaire 2020-06-10 12:10:32 -07:00
parent 8c53349a2a
commit cc67742d3a
2 changed files with 38 additions and 27 deletions

View File

@ -84,7 +84,9 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain, u
}).on('connect', function () { }).on('connect', function () {
send(['rdp-connect']); send(['rdp-connect']);
}).on('bitmap', function (bitmap) { }).on('bitmap', function (bitmap) {
send(['rdp-bitmap', bitmap]); try { ws.send(bitmap.data); } catch (ex) { } // Send the bitmap data as binary
delete bitmap.data;
send(['rdp-bitmap', bitmap]); // Send the bitmap metadata seperately, without bitmap data.
}).on('close', function () { }).on('close', function () {
send(['rdp-close']); send(['rdp-close']);
}).on('error', function (err) { }).on('error', function (err) {

View File

@ -129,6 +129,7 @@
// start connection // start connection
var self = this; var self = this;
this.socket = new WebSocket("wss://" + window.location.host + "/mstsc/relay.ashx"); this.socket = new WebSocket("wss://" + window.location.host + "/mstsc/relay.ashx");
this.socket.binaryType = 'arraybuffer';
this.socket.onopen = function () { this.socket.onopen = function () {
console.log("WS-OPEN"); console.log("WS-OPEN");
self.socket.send(JSON.stringify(['infos', { self.socket.send(JSON.stringify(['infos', {
@ -145,33 +146,41 @@
}])); }]));
}; };
this.socket.onmessage = function (evt) { this.socket.onmessage = function (evt) {
var msg = JSON.parse(evt.data); if (typeof evt.data == 'string') {
switch (msg[0]) { // This is a JSON text string, parse it.
case 'rdp-connect': { var msg = JSON.parse(evt.data);
//console.log('[mstsc.js] connected'); switch (msg[0]) {
self.activeSession = true; case 'rdp-connect': {
break; //console.log('[mstsc.js] connected');
} self.activeSession = true;
case 'rdp-bitmap': { break;
var bitmap = msg[1]; }
bitmap.data = new Uint8Array(bitmap.data.data).buffer; case 'rdp-bitmap': {
//console.log('[mstsc.js] bitmap update bpp : ' + bitmap.bitsPerPixel); if (self.bitmapData == null) break;
self.render.update(bitmap); var bitmap = msg[1];
break; bitmap.data = self.bitmapData; // Use the binary data that was sent earlier.
} delete self.bitmapData;
case 'rdp-close': { //console.log('[mstsc.js] bitmap update bpp : ' + bitmap.bitsPerPixel);
//console.log('[mstsc.js] close'); self.render.update(bitmap);
self.activeSession = false; break;
next(null); }
break; case 'rdp-close': {
} //console.log('[mstsc.js] close');
case 'rdp-error': { self.activeSession = false;
var err = msg[1]; next(null);
console.log('[mstsc.js] error : ' + err.code + '(' + err.message + ')'); break;
self.activeSession = false; }
next(err); case 'rdp-error': {
break; var err = msg[1];
console.log('[mstsc.js] error : ' + err.code + '(' + err.message + ')');
self.activeSession = false;
next(err);
break;
}
} }
} else {
// This is binary bitmap data, store it.
self.bitmapData = evt.data;
} }
}; };
this.socket.onclose = function () { this.socket.onclose = function () {