Fixed desktop & terminal recording.

This commit is contained in:
Ylian Saint-Hilaire 2020-03-11 00:17:10 -07:00
parent f6dfd435fa
commit 8e1fc021c7
7 changed files with 36 additions and 34 deletions

View File

@ -189,10 +189,10 @@ function writeIndex(state, func) {
extraMetadata.indexInterval = state.indexTime;
extraMetadata.indexStartTime = state.startTime;
extraMetadata.indexes = state.indexes;
recordingEntry(state.recFile, 4, 0, state.lastTimeStamp, JSON.stringify(extraMetadata), function (state) {
recordingEntry(state.recFile, 4, 0, state.lastTimeStamp, JSON.stringify(extraMetadata), function (state, len) {
recordingEntry(state.recFile, 3, 0, state.recFileSize - 32, 'MeshCentralMCNDX', function (state) {
func(state);
}, state);
}, state, state.recFileSize - 32 + len);
}, state, state.recFileSize - 32);
}
@ -202,50 +202,50 @@ function recordingEntry(fd, type, flags, time, data, func, tag, position) {
if (typeof data == 'string') {
// String write
var blockData = Buffer.from(data), header = Buffer.alloc(16); // Header: Type (2) + Flags (2) + Size(4) + Time(8)
header.writeInt16BE(type, 0); // Type (1 = Header, 2 = Network Data)
header.writeInt16BE(type, 0); // Type (1 = Header, 2 = Network Data, 3 = End, 4 = Extra Metadata)
header.writeInt16BE(flags, 2); // Flags (1 = Binary, 2 = User)
header.writeInt32BE(blockData.length, 4); // Size
header.writeIntBE(time, 10, 6); // Time
var block = Buffer.concat([header, blockData]);
if (typeof position == 'number') {
fs.write(fd, block, 0, block.length, position, function () { func(tag); });
fs.write(fd, block, 0, block.length, position, function () { func(tag, block.length); });
} else {
fs.write(fd, block, 0, block.length, function () { func(tag); });
fs.write(fd, block, 0, block.length, function () { func(tag, block.length); });
}
} else {
// Binary write
var header = Buffer.alloc(16); // Header: Type (2) + Flags (2) + Size(4) + Time(8)
header.writeInt16BE(type, 0); // Type (1 = Header, 2 = Network Data)
header.writeInt16BE(type, 0); // Type (1 = Header, 2 = Network Data, 3 = End, 4 = Extra Metadata)
header.writeInt16BE(flags | 1, 2); // Flags (1 = Binary, 2 = User)
header.writeInt32BE(data.length, 4); // Size
header.writeIntBE(time, 10, 6); // Time
var block = Buffer.concat([header, data]);
if (typeof position == 'number') {
fs.write(fd, block, 0, block.length, position, function () { func(tag); });
fs.write(fd, block, 0, block.length, position, function () { func(tag, block.length); });
} else {
fs.write(fd, block, 0, block.length, function () { func(tag); });
fs.write(fd, block, 0, block.length, function () { func(tag, block.length); });
}
}
} catch (ex) { console.log(ex); func(state, tag); }
} catch (ex) { console.log(ex); func(tag); }
}
function readLastBlock(state, func) {
var buf = Buffer.alloc(32);
fs.read(state.recFile, buf, 0, 32, state.recFileSize - 32, function (err, bytesRead, buf) {
var type = buf.readUInt16BE(0);
var flags = buf.readUInt16BE(2);
var size = buf.readUInt32BE(4);
var time = (buf.readUInt32BE(8) << 32) + buf.readUInt32BE(12);
var type = buf.readUInt16BE(0); // Type (1 = Header, 2 = Network Data)
var flags = buf.readUInt16BE(2); // Flags (1 = Binary, 2 = User)
var size = buf.readUInt32BE(4); // Size
var time = buf.readUIntBE(10, 6); // Time
var magic = buf.toString('utf8', 16, 32);
if ((type == 3) && (size == 16) && (magic == 'MeshCentralMCNDX')) {
// Extra metadata present, lets read it.
extraMetadata = null;
var buf2 = Buffer.alloc(16);
fs.read(state.recFile, buf2, 0, 16, time, function (err, bytesRead, buf2) {
var xtype = buf2.readUInt16BE(0);
var xflags = buf2.readUInt16BE(2);
var xsize = buf2.readUInt32BE(4);
var xtime = (buf2.readUInt32BE(8) << 32) + buf.readUInt32BE(12);
var xtype = buf2.readUInt16BE(0); // Type (1 = Header, 2 = Network Data, 3 = End, 4 = Extra Metadata)
var xflags = buf2.readUInt16BE(2); // Flags (1 = Binary, 2 = User)
var xsize = buf2.readUInt32BE(4); // Size
var xtime = buf.readUIntBE(10, 6); // Time
var buf3 = Buffer.alloc(xsize);
fs.read(state.recFile, buf3, 0, xsize, time + 16, function (err, bytesRead, buf3) {
func(state, true, xtime, JSON.parse(buf3.toString()));
@ -264,10 +264,10 @@ function readNextBlock(state, func) {
fs.read(state.recFile, buf, 0, 16, state.recFilePtr, function (err, bytesRead, buf) {
if (bytesRead != 16) { func(state, null, true); return; } // Error
try {
r.type = buf.readUInt16BE(0);
r.flags = buf.readUInt16BE(2);
r.size = buf.readUInt32BE(4);
r.time = buf.readUIntBE(8, 8);
r.type = buf.readUInt16BE(0); // Type (1 = Header, 2 = Network Data, 3 = End, 4 = Extra Metadata)
r.flags = buf.readUInt16BE(2); // Flags (1 = Binary, 2 = User)
r.size = buf.readUInt32BE(4); // Size
r.time = buf.readUIntBE(10, 6); // Time
r.date = new Date(r.time);
r.ptr = state.recFilePtr;
if ((state.recFilePtr + 16 + r.size) > state.recFileSize) { func(state, null, true); return; } // Error

View File

@ -227,7 +227,7 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
var metadata = { magic: 'MeshCentralRelaySession', ver: 1, userid: sessionUser._id, username: sessionUser.name, sessionid: obj.id, ipaddr1: cleanRemoteAddr(obj.req.ip), ipaddr2: cleanRemoteAddr(obj.peer.req.ip), time: new Date().toLocaleString(), protocol: (((obj.req == null) || (obj.req.query == null)) ? null : obj.req.query.p), nodeid: (((obj.req == null) || (obj.req.query == null)) ? null : obj.req.query.nodeid ) };
if (xdevicename2 != null) { metadata.devicename = xdevicename2; }
var firstBlock = JSON.stringify(metadata);
recordingEntry(fd, 1, ((obj.req.query.browser) ? 2 : 0), firstBlock, function () {
recordingEntry(fd, 1, 0, firstBlock, function () {
try { relayinfo.peer1.ws.logfile = ws.logfile = { fd: fd, lock: false, filename: recFullFilename }; } catch (ex) {
try { ws.send('c'); } catch (ex) { } // Send connect to both peers, 'cr' indicates the session is being recorded.
try { relayinfo.peer1.ws.send('c'); } catch (ex) { }

View File

@ -37,7 +37,10 @@
"express": "^4.17.0",
"express-handlebars": "^3.1.0",
"express-ws": "^4.0.0",
"html-minifier": "^4.0.0",
"ipcheck": "^0.1.0",
"jsdom": "^16.2.1",
"minify-js": "0.0.4",
"minimist": "^1.2.0",
"multiparty": "^4.2.1",
"nedb": "^1.8.0",

View File

@ -1,5 +1,5 @@
@ECHO OFF
CD ..\translate
C:\Users\Default.DESKTOP-M9I88C9\AppData\Roaming\nvm\v12.13.0\node translate.js minifyall
C:\Users\Default.DESKTOP-M9I88C9\AppData\Roaming\nvm\v12.13.0\node translate.js translateall
C:\Users\Default.DESKTOP-M9I88C9\AppData\Roaming\nvm\v12.13.0\node translate.js extractall
%LOCALAPPDATA%\..\Roaming\nvm\v12.13.0\node64 translate.js minifyall
%LOCALAPPDATA%\..\Roaming\nvm\v12.13.0\node64 translate.js translateall
%LOCALAPPDATA%\..\Roaming\nvm\v12.13.0\node64 translate.js extractall

View File

@ -21570,14 +21570,14 @@
]
},
{
"en": "{0} second{1}",
"nl": "{0} seconde{1}",
"es": "{0} second{1}",
"de": "{0} Sekunde{1}",
"cs": "{0} sekund{1}",
"pt": "{0} segundo{1}",
"de": "{0} Sekunde{1}",
"en": "{0} second{1}",
"es": "{0} second{1}",
"fr": "{0} seconde{1}",
"ja": "{0} 秒{1}",
"nl": "{0} seconde{1}",
"pt": "{0} segundo{1}",
"ru": "{0} секунд{1}",
"xloc": [
"player.handlebars->3->3"
@ -21883,4 +21883,4 @@
]
}
]
}
}

View File

@ -197,7 +197,7 @@
function processFirstBlock(type, flags, time, data) {
recFileProtocol = 0;
if ((type != 1) || (flags != 0)) { cleanup(); return; }
if ((type != 1) || (flags > 2)) { cleanup(); return; }
try { recFileMetadata = JSON.parse(data) } catch (ex) { cleanup(); return; }
if ((recFileMetadata == null) || (recFileMetadata.magic != 'MeshCentralRelaySession') || (recFileMetadata.ver != 1)) { cleanup(); return; }
if (recFileExtras) { for (var i in recFileExtras) { recFileMetadata[i] = recFileExtras[i]; } }
@ -428,7 +428,7 @@
recFile = files[0];
recFilePtr = 0;
readNextBlock(processFirstBlock);
readLastBlock(function (type, flags, time) {
readLastBlock(function (type, flags, time, extras) {
if (type == 3) {
// File is ok
recFileEndTime = time;

1
x.json

File diff suppressed because one or more lines are too long