1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-03-09 15:40:18 +00:00

New MeshAgents (except macOS and FreeBSD + Many fixes + MessageBox feature.

This commit is contained in:
Ylian Saint-Hilaire 2020-05-18 17:57:11 -07:00
parent 8792432825
commit 0c1fbc4369
29 changed files with 1601 additions and 1499 deletions

File diff suppressed because one or more lines are too long

View file

@ -107,14 +107,18 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
//if (obj.targetnode != null) obj.Debug("ProcessPictureMsg " + X + "," + Y + " - " + obj.targetnode.substring(0, 8));
var tile = new Image();
tile.xcount = obj.tilesReceived++;
//console.log('Tile #' + tile.xcount);
var r = obj.tilesReceived;
tile.src = "data:image/jpeg;base64," + btoa(String.fromCharCode.apply(null, data.slice(4)));
var r = obj.tilesReceived, tdata = data.slice(4), ptr = 0, strs = [];
// String.fromCharCode.apply() can't handle very large argument count, so we have to split like this.
while ((tdata.byteLength - ptr) > 50000) { strs.push(String.fromCharCode.apply(null, tdata.slice(ptr, ptr + 50000))); ptr += 50000; }
if (ptr > 0) { strs.push(String.fromCharCode.apply(null, tdata.slice(ptr))); } else { strs.push(String.fromCharCode.apply(null, tdata)); }
tile.src = "data:image/jpeg;base64," + btoa(strs.join(''));
tile.onload = function () {
//console.log('DecodeTile #' + this.xcount);
if (obj.Canvas != null && obj.KillDraw < r && obj.State != 0) {
if ((obj.Canvas != null) && (obj.KillDraw < r) && (obj.State != 0)) {
obj.PendingOperations.push([r, 2, tile, X, Y]);
while (obj.DoPendingOperations()) { }
} else {
obj.PendingOperations.push([r, 0]);
}
}
tile.error = function () { console.log('DecodeTileError'); }
@ -130,7 +134,7 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
obj.PendingOperations.splice(i, 1);
delete Msg;
obj.TilesDrawn++;
if (obj.TilesDrawn == obj.tilesReceived && obj.KillDraw < obj.TilesDrawn) { obj.KillDraw = obj.TilesDrawn = obj.tilesReceived = 0; }
if ((obj.TilesDrawn == obj.tilesReceived) && (obj.KillDraw < obj.TilesDrawn)) { obj.KillDraw = obj.TilesDrawn = obj.tilesReceived = 0; }
return true;
}
}
@ -164,6 +168,7 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
if (level) { obj.CompressionLevel = level; }
if (scaling) { obj.ScalingLevel = scaling; }
if (frametimer) { obj.FrameRateTimer = frametimer; }
//console.log('SendCompressionLevel', obj.CompressionLevel, obj.ScalingLevel, obj.FrameRateTimer);
obj.send(String.fromCharCode(0x00, 0x05, 0x00, 0x0A, type, obj.CompressionLevel) + obj.shortToStr(obj.ScalingLevel) + obj.shortToStr(obj.FrameRateTimer));
}

File diff suppressed because one or more lines are too long

View file

@ -74,7 +74,7 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
obj.xxOnControlCommand = function (msg) {
var controlMsg;
try { controlMsg = JSON.parse(msg); } catch (e) { return; }
if (controlMsg.ctrlChannel != '102938') { obj.xxOnSocketData(msg); return; }
if (controlMsg.ctrlChannel != '102938') { obj.m.ProcessData(msg); return; }
//console.log(controlMsg);
if ((typeof args != 'undefined') && args.redirtrace) { console.log('RedirRecv', controlMsg); }
if (controlMsg.type == 'console') {
@ -168,15 +168,38 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
}
// Control messages, most likely WebRTC setup
//console.log('New data', e.data.byteLength);
if (typeof e.data == 'string') {
obj.xxOnControlCommand(e.data);
} else {
// Send the data to the module
if (obj.m.ProcessBinaryCommand) {
// Send as Binary Command
var view = new Uint8Array(e.data), cmd = (view[0] << 8) + view[1], cmdsize = (view[2] << 8) + view[3];
if ((cmd == 27) && (cmdsize == 8)) { cmd = (view[8] << 8) + view[9]; cmdsize = (view[5] << 16) + (view[6] << 8) + view[7]; view = view.slice(8); }
if (cmdsize != view.byteLength) { console.log('REDIR-ERROR', cmd, cmdsize, view.byteLength); } else { obj.m.ProcessBinaryCommand(cmd, cmdsize, view); }
if (cmdAccLen != 0) {
// Accumulator is active
var view = new Uint8Array(e.data);
cmdAcc.push(view);
cmdAccLen += view.byteLength;
//console.log('Accumulating', cmdAccLen);
if (cmdAccCmdSize <= cmdAccLen) {
var tmp = new Uint8Array(cmdAccLen), tmpPtr = 0;
for (var i in cmdAcc) { tmp.set(cmdAcc[i], tmpPtr); tmpPtr += cmdAcc[i].byteLength; }
//console.log('AccumulatorCompleted');
obj.m.ProcessBinaryCommand(cmdAccCmd, cmdAccCmdSize, tmp);
cmdAccCmd = 0, cmdAccCmdSize = 0, cmdAccLen = 0, cmdAcc = [];
}
} else {
// Accumulator is not active
var view = new Uint8Array(e.data), cmd = (view[0] << 8) + view[1], cmdsize = (view[2] << 8) + view[3];
if ((cmd == 27) && (cmdsize == 8)) { cmd = (view[8] << 8) + view[9]; cmdsize = (view[5] << 16) + (view[6] << 8) + view[7]; view = view.slice(8); }
//console.log(cmdsize, view.byteLength);
if (cmdsize != view.byteLength) {
//console.log('AccumulatorRequired', cmd, cmdsize, view.byteLength);
cmdAccCmd = cmd; cmdAccCmdSize = cmdsize; cmdAccLen = view.byteLength, cmdAcc = [view];
} else {
obj.m.ProcessBinaryCommand(cmd, cmdsize, view);
}
}
} else if (obj.m.ProcessBinaryData) {
// Send as Binary
obj.m.ProcessBinaryData(new Uint8Array(e.data));
@ -187,6 +210,9 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
}
};
// Command accumulator, this is used for WebRTC fragmentation
var cmdAccCmd = 0, cmdAccCmdSize = 0, cmdAccLen = 0, cmdAcc = [];
obj.sendText = function (x) {
if (typeof x != 'string') { x = JSON.stringify(x); } // Turn into a string if needed
obj.send(encode_utf8(x)); // Encode UTF8 correctly