Added local remote desktop recording.

This commit is contained in:
Ylian Saint-Hilaire 2020-05-02 17:59:12 -07:00
parent f5fc3134b3
commit 4606e8beb1
8 changed files with 66 additions and 18 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 612 B

After

Width:  |  Height:  |  Size: 325 B

File diff suppressed because one or more lines are too long

View File

@ -196,7 +196,7 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
if (obj.debugmode > 1) { console.log("KRecv(" + str.length + "): " + rstr2hex(str.substring(0, Math.min(str.length, 40)))); }
if (str.length < 4) return;
var cmdmsg = null, X = 0, Y = 0, command = ReadShort(str, 0), cmdsize = ReadShort(str, 2), jumboAdd = 0;
if (obj.recordedData != null) { obj.recordedData.push({ t: Date.now(), d: str }); }
if (obj.recordedData != null) { obj.recordedData.push(recordingEntry(2, 1, str.length)); obj.recordedData.push(str); }
if ((command == 27) && (cmdsize == 8)) {
// Jumbo packet
if (str.length < 12) return;
@ -779,17 +779,56 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
}
obj.StartRecording = function () {
obj.recordedData = [];
obj.recordedStart = Date.now();
if (obj.recordedData != null) return;
// Take a screen shot and save it to file
obj.CanvasId['toBlob'](function (blob) {
var fileReader = new FileReader();
fileReader.readAsArrayBuffer(blob);
fileReader.onload = function (event) {
// This is an ArrayBuffer, convert it to a string array
var binary = '', bytes = new Uint8Array(fileReader.result), length = bytes.byteLength;
for (var i = 0; i < length; i++) { binary += String.fromCharCode(bytes[i]); }
obj.recordedData = [];
obj.recordedStart = Date.now();
obj.recordedSize = 0;
obj.recordedData.push(recordingEntry(1, 0, JSON.stringify({ magic: 'MeshCentralRelaySession', ver: 1, time: new Date().toLocaleString(), protocol: 2 }))); // Metadata (nodeid: obj.nodeid)
obj.recordedData.push(recordingEntry(2, 1, obj.shortToStr(7) + obj.shortToStr(8) + obj.shortToStr(obj.ScreenWidth) + obj.shortToStr(obj.ScreenHeight))); // Screen width and height
// Save a screenshot
var cmdlen = (4 + binary.length);
if (cmdlen > 65000) {
// Jumbo Packet
obj.recordedData.push(recordingEntry(2, 1, obj.shortToStr(27) + obj.shortToStr(8) + obj.intToStr(cmdlen) + obj.shortToStr(3) + obj.shortToStr(0) + obj.shortToStr(0) + obj.shortToStr(0) + binary));
} else {
// Normal packet
obj.recordedData.push(recordingEntry(2, 1, obj.shortToStr(3) + obj.shortToStr(cmdlen) + obj.shortToStr(0) + obj.shortToStr(0) + binary));
}
};
});
}
obj.StopRecording = function () {
if (obj.recordedData == null) return;
var r = obj.recordedData;
r.push(recordingEntry(3, 0, 'MeshCentralMCREC'));
delete obj.recordedData;
delete obj.recordedStart;
delete obj.recordedSize;
return r;
}
function recordingEntry(type, flags, data) {
// Header: Type (2) + Flags (2) + Size(4) + Time(8)
// Type (1 = Header, 2 = Network Data), Flags (1 = Binary, 2 = User), Size (4 bytes), Time (8 bytes)
var now = Date.now();
if (typeof data == 'number') {
obj.recordedSize += data;
return obj.shortToStr(type) + obj.shortToStr(flags) + obj.intToStr(data) + obj.intToStr(now >> 32) + obj.intToStr(now & 32);
} else {
obj.recordedSize += data.length;
return obj.shortToStr(type) + obj.shortToStr(flags) + obj.intToStr(data.length) + obj.intToStr(now >> 32) + obj.intToStr(now & 32) + data;
}
}
// Private method
obj.MuchTheSame = function (a, b) { return (Math.abs(a - b) < 4); }
obj.Debug = function (msg) { console.log(msg); }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -20335,6 +20335,12 @@
"default.handlebars->23->1453"
]
},
{
"en": "Record remote desktop session to file",
"xloc": [
"default.handlebars->container->column_l->p11->deskarea0->deskarea4->1"
]
},
{
"cs": "Rekurzivní mazání",
"de": "Rekursiv Löschen",
@ -21679,7 +21685,7 @@
"ru": "Сохранить снимок экрана удаленного рабочего стола",
"zh-chs": "保存遠程桌面的屏幕截圖",
"xloc": [
"default.handlebars->container->column_l->p11->deskarea0->deskarea1->1"
"default.handlebars->container->column_l->p11->deskarea0->deskarea4->1"
]
},
{
@ -21711,10 +21717,7 @@
"nl": "Opslaan...",
"pt": "Salvar...",
"ru": "Сохранить...",
"zh-chs": "保存...",
"xloc": [
"default.handlebars->container->column_l->p11->deskarea0->deskarea1->1"
]
"zh-chs": "保存..."
},
{
"cs": "Škálování",

View File

@ -572,7 +572,7 @@
<span id=DeskOpenWebButton title="Open a web address on the remote computer"><img src='images/icon-url2.png' onclick=deviceUrlFunction() height=16 width=16 style=padding-top:2px /></span>
<span id=DeskBackgroundButton title="Toggle remote desktop background"><img src='images/icon-background.png' onclick=deviceToggleBackground(event) height=16 width=16 style=padding-top:2px /></span>
<span id=DeskSaveImageButton title="Save a screenshot of the remote desktop"><img src='images/icon-camera.png' onclick=deskSaveImage() height=16 width=16 style=padding-top:2px /></span>
<span id=DeskRecordButton title="Record remote desktop session to file" style="display:none"><img src='images/icon-film.png' onclick=deskRecordSession() height=16 width=16 style=padding-top:2px /></span>
<span id=DeskRecordButton title="Record remote desktop session to file" style="display:none"><img id=DeskRecordButtonImage src='images/icon-film.png' onclick=deskRecordSession() height=16 width=16 style=padding-top:2px /></span>
</div>
<div>
<select id="deskkeys">
@ -5806,7 +5806,7 @@
// Display this only if we have Chat & Notify permissions
QV('DeskSaveImageButton', (deskState == 3) && (Q('Desk')['toBlob'] != null));
QV('DeskRecordButton', (deskState == 3));
QV('DeskRecordButton', (deskState == 3) && (Q('Desk')['toBlob'] != null));
QV('DeskChatButton', ((rights & 16384) != 0) && (browserfullscreen == false) && (inputAllowed) && (currentNode.agent) && online);
QV('DeskNotifyButton', ((rights & 16384) != 0) && (browserfullscreen == false) && (currentNode.agent) && (currentNode.agent.id < 5) && (inputAllowed) && (currentNode.agent) && online);
@ -5994,6 +5994,9 @@
QH('deskstatus', str);
switch (state) {
case 0:
// Stop recording
if (desktop.m.recordedData != null) { deskRecordSession(); }
// Disconnect and clean up the remote desktop
desktop.Stop();
desktopNode = desktop = null;
@ -6530,13 +6533,13 @@
if (desktop == null) return;
if (desktop.m.recordedData == null) {
// Start recording
console.log('Start record');
Q('DeskRecordButtonImage').src = 'images/icon-film-red.png';
desktop.m.StartRecording();
} else {
// Stop recording
console.log('Stop record');
var rec = desktop.m.StopRecording();
console.log('frames', rec.length);
Q('DeskRecordButtonImage').src = 'images/icon-film.png';
var d = new Date(), n = 'DesktopSesion-' + currentNode.name + '-' + d.getFullYear() + '-' + ('0' + (d.getMonth() + 1)).slice(-2) + '-' + ('0' + d.getDate()).slice(-2) + '-' + ('0' + d.getHours()).slice(-2) + '-' + ('0' + d.getMinutes()).slice(-2);
saveAs(data2blob(desktop.m.StopRecording().join('')), n + '.mcrec');
}
}
@ -11659,6 +11662,9 @@
if ((xxcurrentView == 50) || (Math.floor(xxcurrentView / 10) != Math.floor(x / 10))) { goBackStack.push(xxcurrentView); }
}
// If we are recording the desktop, stop it now.
if ((xxcurrentView == 11) && (desktop != null) && (desktop.m.recordedData != null)) { deskRecordSession(); }
// Edit this line when adding a new screen
for (var i = 0; i < 52; i++) { QV('p' + i, i == x); }
xxcurrentView = x;