Code cleanup, optimize clearing udpBuffer

This commit is contained in:
matt 2022-07-01 17:51:17 +00:00
parent c648af5358
commit ce8f08318d
2 changed files with 9 additions and 26 deletions

View File

@ -329,9 +329,7 @@ export default class Display {
x, y, w, h, x, y, w, h,
vx, vy, w, h); vx, vy, w, h);
if (this.isNewFrame(x, y, h, w)) { this._flipCnt += 1;
this._flipCnt += 1;
}
} }
this._damageBounds.left = this._damageBounds.top = 65535; this._damageBounds.left = this._damageBounds.top = 65535;

View File

@ -986,10 +986,6 @@ export default class RFB extends EventTargetMixin {
if (udpBuffer.has(id)) { if (udpBuffer.has(id)) {
let item = udpBuffer.get(id); let item = udpBuffer.get(id);
if (!item) {
Log.Info("Item Missing id: " + id);
return;
}
item.recieved_pieces += 1; item.recieved_pieces += 1;
item.data[i] = u8.slice(16); item.data[i] = u8.slice(16);
item.total_bytes += item.data[i].length; item.total_bytes += item.data[i].length;
@ -1007,33 +1003,21 @@ export default class RFB extends EventTargetMixin {
} }
} else { } else {
let item = { let item = {
total_pieces: pieces, // number of pieces expected total_pieces: pieces, // number of pieces expected
arrival: now, //time first piece was recieved arrival: now, //time first piece was recieved
recieved_pieces: 1, // current number of pieces in data recieved_pieces: 1, // current number of pieces in data
total_bytes: 0, // total size of all data pieces combined total_bytes: 0, // total size of all data pieces combined
data: new Array(pieces) data: new Array(pieces)
} }
item.data[i] = u8.slice(16); item.data[i] = u8.slice(16);
item.total_bytes = item.data[i].length; item.total_bytes = item.data[i].length;
udpBuffer.set(id, item); udpBuffer.set(id, item);
} }
} }
// TODO: this loop is inefficent and likely unneccesary.
// perhaps just keep n number of incomplete messages
const now = Date.now();
for (const [key, value] of udpBuffer.entries()) {
// Drop any messages older than 100ms
if (now - value.arrival > 100) {
Log.Info('Removed id: ' + key + ' Buffer size: ' + udpBuffer.size);
udpBuffer.delete(key);
}
}
} }
} }
if (this._useUdp) { if (this._useUdp) {
setTimeout(function() { this._sendUdpUpgrade() }.bind(this), 3000); setTimeout(function() { this._sendUdpUpgrade() }.bind(this), 3000);
} }
@ -2869,6 +2853,7 @@ export default class RFB extends EventTargetMixin {
case encodings.pseudoEncodingLastRect: case encodings.pseudoEncodingLastRect:
if (document.visibilityState !== "hidden") { if (document.visibilityState !== "hidden") {
this._display.flip(); this._display.flip();
this._udpBuffer.clear();
} }
break; break;
case encodings.encodingTight: case encodings.encodingTight: