player.handlebars 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  1. <!DOCTYPE html>
  2. <html lang="en" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  5. <meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
  6. <meta name="viewport" content="user-scalable=1.0,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0" />
  7. <meta name="apple-mobile-web-app-capable" content="yes" />
  8. <meta name="format-detection" content="telephone=no" />
  9. <meta name="robots" content="noindex,nofollow">
  10. <link type="text/css" href="styles/style.css" media="screen" rel="stylesheet" title="CSS" />
  11. <link type="text/css" href="styles/xterm.css" media="screen" rel="stylesheet" title="CSS" />
  12. {{{customCSSTags}}}
  13. <link rel="apple-touch-icon" href="/favicon-303x303.png" />
  14. <script type="text/javascript" src="scripts/common-0.0.1{{min}}.js"></script>
  15. <script type="text/javascript" src="scripts/agent-desktop-0.0.2{{min}}.js"></script>
  16. <script type="text/javascript" src="scripts/amt-desktop-0.0.2{{min}}.js"></script>
  17. <script type="text/javascript" src="scripts/amt-terminal-0.0.2{{min}}.js"></script>
  18. <script type="text/javascript" src="scripts/zlib{{min}}.js"></script>
  19. <script type="text/javascript" src="scripts/zlib-inflate{{min}}.js"></script>
  20. <script type="text/javascript" src="scripts/zlib-adler32{{min}}.js"></script>
  21. <script type="text/javascript" src="scripts/zlib-crc32{{min}}.js"></script>
  22. <script type="text/javascript" src="scripts/xterm-min.js"></script>
  23. <script type="text/javascript" src="scripts/xterm-addon-fit-min.js"></script>
  24. <script keeplink=1 type="text/javascript" src="scripts/webm-writer.js"></script>
  25. <script keeplink=1 type="text/javascript" src="scripts/filesaver.min.js"></script>
  26. {{{customJSTags}}}
  27. </head>
  28. <body style="overflow:hidden;background-color:black">
  29. <div id=p11 class="noselect" style="overflow:hidden">
  30. <div id=deskarea0>
  31. <div id=deskarea1 class="areaHead">
  32. <div class="toright2">
  33. <div class='deskareaicon' title="Toggle View Mode" onclick="toggleAspectRatio(1)">&#8690;</div>&nbsp;
  34. <input id="ConvertAsWebM" style="display:none" type=button value="Convert to WebM" onclick="saveAsWebMfile()">&nbsp;
  35. </div>
  36. <div>
  37. <input id="OpenFileButton" type=button value="Open File..." onclick="openfile()" style="display:none">
  38. <span id="deskstatus" style="line-height:22px;overflow:hidden;max-height:22px"></span>
  39. </div>
  40. </div>
  41. <div id=deskarea3x style="max-height:calc(100vh - 58px);height:calc(100vh - 58px);" onclick="togglePause()">
  42. <div id="bigok" style="display:none;left:calc((100vh / 2))"><b>&checkmark;</b></div>
  43. <div id="bigfail" style="display:none;left:calc((100vh / 2))"><b>&#10007;</b></div>
  44. <div id="metadatadiv" style="padding:20px;color:lightgrey;text-align:left;display:none"></div>
  45. <div id=DeskParent>
  46. <canvas id=Desk width=640 height=480></canvas>
  47. </div>
  48. <div id=TermParent style="display:none">
  49. <pre id=Term></pre>
  50. </div>
  51. <div id=XTermParent style="display:none;overflow:scroll;max-height:calc(100vh - 58px);height:calc(100vh - 58px);text-align:left">
  52. </div>
  53. <div id=p11DeskConsoleMsg style="display:none;cursor:pointer;position:absolute;left:30px;top:17px;color:yellow;background-color:rgba(0,0,0,0.6);padding:10px;border-radius:5px" onclick=clearConsoleMsg()></div>
  54. </div>
  55. <div id=deskarea2 style="">
  56. <div class="areaProgress" style="cursor:pointer" onclick="progressBarSeek(event)"><div id="progressbar" style="height:6px;cursor:pointer"></div></div>
  57. </div>
  58. <div id=deskarea4 class="areaFoot">
  59. <div class="toright2">
  60. <div id="timespan" style="padding-top:4px;padding-right:4px">00:00:00</div>
  61. </div>
  62. <div>
  63. &nbsp;
  64. <input id="PlayButton" type=button value="Play" disabled="disabled" onclick="play()">
  65. <input id="PauseButton" type=button value="Pause" disabled="disabled" onclick="pause()">
  66. <input id="RestartButton" type=button value="Restart" disabled="disabled" onclick="restart()">
  67. <select id="PlaySpeed" onchange="this.blur();">
  68. <option value=4>1/4 Speed</option>
  69. <option value=2>1/2 Speed</option>
  70. <option value=1 selected>Normal Speed</option>
  71. <option value=0.5>2x Speed</option>
  72. <option value=0.25>4x Speed</option>
  73. <option value=0.1>10x Speed</option>
  74. </select>
  75. <input id="SeekBackwardButton" type=button value="<<" disabled="disabled" onclick="seekBackward()">
  76. <input id="SeekForwardButton" type=button value=">>" disabled="disabled" onclick="seekForward()">
  77. </div>
  78. </div>
  79. </div>
  80. <div id=dialog class="noselect" style="display:none">
  81. <div id=dialogHeader>
  82. <div tabindex=0 id=id_dialogclose onclick=setDialogMode() onkeypress="if (event.key == 'Enter') setDialogMode()">&#x2716;</div>
  83. <div id=id_dialogtitle></div>
  84. </div>
  85. <div id=dialogBody>
  86. <div id=dialog1>
  87. <div id=id_dialogMessage style=""></div>
  88. </div>
  89. <div id=dialog2 style="">
  90. <div id=id_dialogOptions></div>
  91. </div>
  92. </div>
  93. <div id="idx_dlgButtonBar">
  94. <input id="idx_dlgCancelButton" type="button" value="Cancel" style="" onclick="dialogclose(0)">
  95. <input id="idx_dlgOkButton" type="button" value="OK" style="" onclick="dialogclose(1)">
  96. <div><input id="idx_dlgDeleteButton" type="button" value="Delete" style="display:none" onclick="dialogclose(2)"></div>
  97. </div>
  98. </div>
  99. </div>
  100. <script>
  101. var random = '{{{randomlength}}}' // Random length string for BREACH mitigation
  102. var recFile = null;
  103. var recFilePtr = 0;
  104. var recFileStartTime = 0;
  105. var recFileLastTime = 0;
  106. var recFileEndTime = 0;
  107. var recFileMetadata = null;
  108. var recFileProtocol = 0;
  109. var recFileIndexBasePtr = null;
  110. var recFileExtras = null;
  111. var agentDesktop = null;
  112. var amtDesktop = null;
  113. var playing = false;
  114. var readState = 0;
  115. var waitTimer = null;
  116. var waitTimerArgs = null;
  117. var deskAspectRatio = 0;
  118. var currentDeltaTimeTotalSec = 0;
  119. var videoWriter = null;
  120. var videoWriterLastFrame = null;
  121. var videoWriterCurrentFrame = null;
  122. var videoFrameDuration = 100;
  123. var browser = null;
  124. var domainUrl = '{{{domainurl}}}';
  125. var urlargs;
  126. var term = null;
  127. // Streaming values
  128. var ws = null;
  129. var streamingBlockSize = 102400; // 100k block
  130. var streamingBlockCache = {};
  131. function start() {
  132. // Detect what browser is in use
  133. browser = (function (agent) {
  134. switch (true) {
  135. case agent.indexOf("edge") > -1: return "MS Edge (EdgeHtml)";
  136. case agent.indexOf("edg") > -1: return "MS Edge Chromium";
  137. case agent.indexOf("opr") > -1 && !!window.opr: return "opera";
  138. case agent.indexOf("chrome") > -1 && !!window.chrome: return "chrome";
  139. case agent.indexOf("trident") > -1: return "Internet Explorer";
  140. case agent.indexOf("firefox") > -1: return "firefox";
  141. case agent.indexOf("safari") > -1: return "safari";
  142. default: return "other";
  143. }
  144. })(window.navigator.userAgent.toLowerCase());
  145. urlargs = parseUriArgs(true);
  146. window.onresize = deskAdjust;
  147. document.ondrop = ondrop;
  148. document.ondragover = ondragover;
  149. document.ondragleave = ondragleave;
  150. document.onkeypress = onkeypress;
  151. Q('PlaySpeed').value = 1;
  152. cleanup();
  153. // Make the dialog box movable
  154. dialogBoxDrag();
  155. // Check if we need to stream a session
  156. if (urlargs.stream != null) {
  157. QV('metadatadiv', true);
  158. QH('metadatadiv', "Connecting to server...");
  159. ws = new WebSocket(window.location.protocol.replace('http', 'ws') + '//' + window.location.host + domainUrl + 'recordings.ashx?file=' + urlargs.stream + (urlargs.key ? ('&key=' + urlargs.key) : ''));
  160. ws.binaryType = 'arraybuffer';
  161. ws.onopen = function (e) { console.log('Session Streaming - Connected'); }
  162. ws.onmessage = function (msg) {
  163. if (typeof msg.data != 'string') {
  164. var uint8View = new Uint8Array(msg.data);
  165. var blocknum = (((uint8View[4] << 24) + (uint8View[5] << 16) + (uint8View[6] << 8) + uint8View[7]) / streamingBlockSize);
  166. //console.log('Session Streaming - Got block: ' + blocknum);
  167. streamingBlockCache[blocknum] = msg.data;
  168. var pendingFetchStreamingData2 = [], pendingFetchStreamingData3 = [];
  169. for (var i in pendingFetchStreamingData) {
  170. var j = pendingFetchStreamingData[i].missingBlocks.indexOf(blocknum);
  171. if (j >= 0) { pendingFetchStreamingData[i].missingBlocks.splice(i, 1); }
  172. if (pendingFetchStreamingData[i].missingBlocks.length == 0) {
  173. pendingFetchStreamingData3.push(pendingFetchStreamingData[i]);
  174. } else {
  175. pendingFetchStreamingData2.push(pendingFetchStreamingData[i]);
  176. }
  177. }
  178. pendingFetchStreamingData = pendingFetchStreamingData2;
  179. for (var i in pendingFetchStreamingData3) {
  180. fetchStreamingData(pendingFetchStreamingData3[i].fr, pendingFetchStreamingData3[i].start, pendingFetchStreamingData3[i].end);
  181. }
  182. return;
  183. } else {
  184. var command = null;
  185. try { command = JSON.parse(msg.data); } catch (ex) { console.log(ex); return; }
  186. if ((command == null) || (typeof command.action != 'string')) return;
  187. switch (command.action) {
  188. case 'info': {
  189. console.log('Session Streaming - Session file size: ' + command.size);
  190. if ((typeof command.name != 'string') || (typeof command.size != 'number')) break;
  191. recFile = { name: command.name, size: command.size, streaming: true };
  192. readLastBlock(function (type, flags, time, extras) {
  193. if (type == 3) {
  194. // File is ok
  195. recFileEndTime = time;
  196. recFileExtras = extras;
  197. readNextBlock(processFirstBlock);
  198. } else {
  199. // This is not a good file
  200. recFileEndTime = 0;
  201. }
  202. });
  203. break;
  204. }
  205. }
  206. }
  207. }
  208. ws.onclose = function (e) {
  209. console.log('Session Streaming - Disconnected');
  210. ws = null;
  211. urlargs.stream = null;
  212. QV('OpenFileButton', true);
  213. cleanup();
  214. }
  215. } else {
  216. QV('OpenFileButton', true);
  217. }
  218. }
  219. // Pending fetch requests
  220. var pendingFetchStreamingData = [];
  221. // Get a section of the recorded file
  222. function fetchStreamingData(fr, start, end) {
  223. // Start by looking at what blocks are required
  224. var firstBlock = Math.floor(start / streamingBlockSize);
  225. var lastBlock = Math.floor(end / streamingBlockSize);
  226. var missingBlocks = [];
  227. for (var i = firstBlock; i <= lastBlock; i++) {
  228. if ((streamingBlockCache[i] == null) || (streamingBlockCache[i] === 1)) { missingBlocks.push(i); fetchStreamingBlock(i); }
  229. fetchStreamingBlock(i + 1); // Pre-fetch block
  230. fetchStreamingBlock(i + 2); // Pre-fetch block
  231. }
  232. if (missingBlocks.length == 0) {
  233. // We have all the blocks we need, assemble the data now
  234. var outputptr = 0;
  235. var output = new ArrayBuffer(end - start);
  236. var outputBytes = new Uint8Array(output);
  237. for (var i = firstBlock; i <= lastBlock; i++) {
  238. var block = streamingBlockCache[i]; // Get a block with data we need
  239. var blockstart = (i * streamingBlockSize); // Compute the block starting data pointer
  240. var blockend = blockstart + (block.byteLength - 8); // Compute the block ending data pointer
  241. var r1 = Math.max(start, blockstart); // Compute where we need to start data copy
  242. var r2 = Math.min(end, blockend); // Compute where we need to end data copy
  243. var p1 = r1 - blockstart; // Compute where in the block to start data copy
  244. var p2 = r2 - r1; // Computer how many byte to copy from the block
  245. var subblock = block.slice(8 + p1, 8 + p1 + p2); // Get the sub-block of data we need
  246. outputBytes.set(new Uint8Array(subblock), outputptr); // Copy the sub-block into the main block
  247. outputptr += p2; // Move the pointer forward
  248. }
  249. fr.onload({ target: { result: ArrayBufferToString(output) } } ); // Event the block of data
  250. } else {
  251. pendingFetchStreamingData.push({ fr: fr, start: start, end: end, missingBlocks: missingBlocks });
  252. }
  253. }
  254. // Request a block of data from the server
  255. function fetchStreamingBlock(n) {
  256. if (streamingBlockCache[n] != null) return;
  257. streamingBlockCache[n] = 1; // Mark the block as being requested
  258. if ((n * streamingBlockSize) >= recFile.size) return;
  259. var len = streamingBlockSize;
  260. if (((n + 1) * streamingBlockSize) >= recFile.size) { len = (recFile.size - (n * streamingBlockSize)); }
  261. ws.send('{"action":"get","ptr":' + (n * streamingBlockSize) + ',"size":' + len + '}');
  262. }
  263. function readNextBlock(func) {
  264. if ((recFilePtr + 16) > recFile.size) { QS('progressbar').width = '100%'; func(-1); } else {
  265. var fr = new FileReader();
  266. fr.onload = function (r) {
  267. var result = r.target.result;
  268. var type = ReadShort(result, 0);
  269. var flags = ReadShort(result, 2);
  270. var size = ReadInt(result, 4);
  271. var time = (ReadInt(result, 8) << 32) + ReadInt(result, 12);
  272. if ((recFilePtr + 16 + size) > recFile.size) { QS('progressbar').width = '100%'; func(-1); } else {
  273. var fr2 = new FileReader();
  274. fr2.onload = function (r) {
  275. var result = r.target.result;
  276. recFilePtr += (16 + size);
  277. if (recFileEndTime == 0) {
  278. // File pointer progress bar
  279. QS('progressbar').width = Math.floor(100 * (recFilePtr / recFile.size)) + '%';
  280. } else {
  281. // Time progress bar
  282. QS('progressbar').width = Math.floor(((recFileLastTime - recFileStartTime) / (recFileEndTime - recFileStartTime)) * 100) + '%';
  283. }
  284. func(type, flags, time, result);
  285. };
  286. if (ws == null) {
  287. fr2.readAsBinaryString(recFile.slice(recFilePtr + 16, recFilePtr + 16 + size));
  288. } else {
  289. fetchStreamingData(fr2, recFilePtr + 16, recFilePtr + 16 + size);
  290. }
  291. }
  292. };
  293. if (ws == null) {
  294. fr.readAsBinaryString(recFile.slice(recFilePtr, recFilePtr + 16));
  295. } else {
  296. fetchStreamingData(fr, recFilePtr, recFilePtr + 16);
  297. }
  298. }
  299. }
  300. function readBlockAt(ptr, func) {
  301. var fr = new FileReader();
  302. fr.onload = function (r) {
  303. var result = r.target.result;
  304. var type = ReadShort(result, 0);
  305. var flags = ReadShort(result, 2);
  306. var size = ReadInt(result, 4);
  307. var time = (ReadInt(result, 8) << 32) + ReadInt(result, 12);
  308. if ((ptr + 16 + size) > recFile.size) { func(-1); } else {
  309. var fr2 = new FileReader();
  310. fr2.onload = function (r) {
  311. var result = r.target.result;
  312. func(type, flags, time, result);
  313. };
  314. if (ws == null) {
  315. fr2.readAsBinaryString(recFile.slice(ptr + 16, ptr + 16 + size));
  316. } else {
  317. fetchStreamingData(fr2, ptr + 16, ptr + 16 + size);
  318. }
  319. }
  320. };
  321. if (ws == null) {
  322. fr.readAsBinaryString(recFile.slice(ptr, ptr + 16));
  323. } else {
  324. fetchStreamingData(fr, ptr, ptr + 16);
  325. }
  326. }
  327. function readLastBlock(func) {
  328. if (recFile.size < 32) { func(-1); } else {
  329. var fr = new FileReader();
  330. fr.onload = function (r) {
  331. var result = r.target.result;
  332. var type = ReadShort(result, 0);
  333. var flags = ReadShort(result, 2);
  334. var size = ReadInt(result, 4);
  335. var time = (ReadInt(result, 8) << 32) + ReadInt(result, 12);
  336. var magic = result.substring(16, 32);
  337. if ((type == 3) && (size == 16) && (magic == 'MeshCentralMCNDX')) {
  338. // Extra metadata present, lets read it.
  339. var fr2 = new FileReader();
  340. fr2.onload = function (r) {
  341. var result = r.target.result;
  342. var xtype = ReadShort(result, 0);
  343. var xflags = ReadShort(result, 2);
  344. var xsize = ReadInt(result, 4);
  345. var xtime = (ReadInt(result, 8) << 32) + ReadInt(result, 12);
  346. var extras = JSON.parse(result.substring(16));
  347. func(type, flags, xtime, extras); // Include extra metadata
  348. }
  349. if (ws == null) {
  350. fr2.readAsBinaryString(recFile.slice(time, recFile.size - 32));
  351. } else {
  352. fetchStreamingData(fr2, time, recFile.size - 32);
  353. }
  354. } else if ((type == 3) && (size == 16) && (magic == 'MeshCentralMCREC')) {
  355. func(type, flags, time); // No extra metadata
  356. } else {
  357. func(-1); // Fail
  358. }
  359. };
  360. if (ws == null) {
  361. fr.readAsBinaryString(recFile.slice(recFile.size - 32, recFile.size));
  362. } else {
  363. fetchStreamingData(fr, recFile.size - 32, recFile.size);
  364. }
  365. }
  366. }
  367. function addInfo(name, value) { if (value == null) return ''; return addInfoNoEsc(name, EscapeHtml(value)); }
  368. function addInfoNoEsc(name, value) {
  369. if (value == null) return '';
  370. return '<span style=color:gray>' + EscapeHtml(name) + '</span>:&nbsp;<span style=font-size:20px>' + value + '</span><br/>';
  371. }
  372. function processFirstBlock(type, flags, time, data) {
  373. recFileProtocol = 0;
  374. if ((type != 1) || (flags > 2)) { cleanup(); return; }
  375. try { recFileMetadata = JSON.parse(data) } catch (ex) { cleanup(); return; }
  376. if ((recFileMetadata == null) || (recFileMetadata.magic != 'MeshCentralRelaySession') || (recFileMetadata.ver != 1)) { cleanup(); return; }
  377. if (recFileExtras) { for (var i in recFileExtras) { recFileMetadata[i] = recFileExtras[i]; } }
  378. var x = '';
  379. x += addInfo("Time", recFileMetadata.time);
  380. if (recFileEndTime != 0) { var secs = Math.floor((recFileEndTime - time) / 1000); x += addInfo("Duration", format("{0} second{1}", secs, (secs > 1) ? 's' : '')); }
  381. x += addInfo("Username", recFileMetadata.username);
  382. x += addInfo("UserID", recFileMetadata.userid);
  383. x += addInfo("SessionID", recFileMetadata.sessionid);
  384. if (recFileMetadata.ipaddr1 && recFileMetadata.ipaddr2) { x += addInfo("Addresses", format("{0} to {1}", recFileMetadata.ipaddr1, recFileMetadata.ipaddr2)); }
  385. if (recFileMetadata.devicename) { x += addInfo("Device Name", recFileMetadata.devicename); }
  386. x += addInfo("NodeID", recFileMetadata.nodeid);
  387. if (recFileMetadata.protocol) {
  388. var p = recFileMetadata.protocol;
  389. if (p == 1) { p = "MeshCentral Terminal"; }
  390. else if (p == 2) { p = "MeshCentral Desktop"; }
  391. else if (p == 6) { p = "Admin PowerShell"; }
  392. else if (p == 8) { p = "User Shell"; }
  393. else if (p == 9) { p = "User PowerShell"; }
  394. else if (p == 100) { p = "Intel&reg; AMT WSMAN"; }
  395. else if (p == 101) { p = "Intel&reg; AMT Redirection"; }
  396. else if ((p == 102) || (p == 200 && recFileMetadata.bpp != null)) { p = "Intel&reg; AMT KVM"; }
  397. else if (p == 200) { p = "MeshMessenger"; }
  398. x += addInfoNoEsc("Protocol", p);
  399. }
  400. var encQualityStr = "2 byte-per-pixel";
  401. if (recFileMetadata.bpp == 1) { encQualityStr = "1 byte-per-pixel" }
  402. if (recFileMetadata.graymode) { if (recFileMetadata.lowcolor) { encQualityStr += ", 16 grays"; } else { encQualityStr += ", 256 grays"; } }
  403. x += addInfoNoEsc("Encoding Quality", encQualityStr);
  404. if (recFileMetadata.indexInterval) {
  405. recFileIndexBasePtr = recFilePtr;
  406. x += addInfoNoEsc("Seeking", format("Indexed every {0} seconds", recFileMetadata.indexInterval));
  407. QV('SeekBackwardButton', true);
  408. QV('SeekForwardButton', true);
  409. QE('SeekBackwardButton', true);
  410. QE('SeekForwardButton', true);
  411. } else {
  412. QV('SeekBackwardButton', false);
  413. QV('SeekForwardButton', false);
  414. }
  415. QV('DeskParent', true);
  416. QV('TermParent', false);
  417. QV('XTermParent', false);
  418. QV('ConvertAsWebM', false);
  419. if ((recFileMetadata.protocol == 1) || (recFileMetadata.protocol == 6) || (recFileMetadata.protocol == 8) || (recFileMetadata.protocol == 9)) {
  420. // MeshCentral remote terminal
  421. recFileProtocol = 1;
  422. x += '<br /><br /><span style=color:gray>' + "Press [space] to play/pause." + '</span>';
  423. QE('PlayButton', true);
  424. QE('PauseButton', false);
  425. QE('RestartButton', false);
  426. recFileStartTime = recFileLastTime = time;
  427. }
  428. else if (recFileMetadata.protocol == 2) {
  429. // MeshCentral remote desktop
  430. recFileProtocol = 2;
  431. x += '<br /><br /><span style=color:gray>' + "Press [space] to play/pause." + '</span>';
  432. QE('PlayButton', true);
  433. QE('PauseButton', false);
  434. QE('RestartButton', false);
  435. recFileStartTime = recFileLastTime = time;
  436. agentDesktop = CreateAgentRemoteDesktop('Desk');
  437. agentDesktop.onScreenSizeChange = deskAdjust;
  438. agentDesktop.onPreDrawImage = preCanvasDraw;
  439. agentDesktop.State = 3;
  440. deskAdjust();
  441. QV('ConvertAsWebM', true);
  442. }
  443. else if (recFileMetadata.protocol == 101) {
  444. // Intel AMT Redirection
  445. recFileProtocol = 101;
  446. x += '<br /><br /><span style=color:gray>' + "Press [space] to play/pause." + '</span>';
  447. QE('PlayButton', true);
  448. QE('PauseButton', false);
  449. QE('RestartButton', false);
  450. recFileStartTime = recFileLastTime = time;
  451. amtDesktop = CreateAmtRemoteDesktop('Desk');
  452. amtDesktop.onScreenSizeChange = deskAdjust;
  453. amtDesktop.onPreDrawImage = preCanvasDraw;
  454. if (recFileMetadata.screenSize) { amtDesktop.width = recFileMetadata.screenSize[0]; amtDesktop.height = recFileMetadata.screenSize[1]; }
  455. if (recFileMetadata.bpp) { amtDesktop.bpp = recFileMetadata.bpp; }
  456. if (recFileMetadata.graymode) { amtDesktop.graymode = recFileMetadata.graymode; }
  457. if (recFileMetadata.lowcolor) { amtDesktop.lowcolor = recFileMetadata.lowcolor; }
  458. amtDesktop.State = 3;
  459. amtDesktop.Start();
  460. deskAdjust();
  461. }
  462. else if (recFileMetadata.protocol == 102 || (recFileMetadata.protocol == 200 && recFileMetadata.bpp != null)) {
  463. // Intel AMT Midstream KVM
  464. recFileProtocol = 102;
  465. x += '<br /><br /><span style=color:gray>' + "Press [space] to play/pause." + '</span>';
  466. QE('PlayButton', true);
  467. QE('PauseButton', false);
  468. QE('RestartButton', false);
  469. recFileStartTime = recFileLastTime = time;
  470. amtDesktop = CreateAmtRemoteDesktop('Desk');
  471. amtDesktop.onScreenSizeChange = deskAdjust;
  472. amtDesktop.onPreDrawImage = preCanvasDraw;
  473. amtDesktop.State = 3;
  474. amtDesktop.Start();
  475. if (recFileMetadata.screenSize) { amtDesktop.width = recFileMetadata.screenSize[0]; amtDesktop.height = recFileMetadata.screenSize[1]; }
  476. if (recFileMetadata.bpp) { amtDesktop.bpp = recFileMetadata.bpp; }
  477. if (recFileMetadata.graymode) { amtDesktop.graymode = recFileMetadata.graymode; }
  478. if (recFileMetadata.lowcolor) { amtDesktop.lowcolor = recFileMetadata.lowcolor; }
  479. amtDesktop.state = 3;
  480. deskAdjust();
  481. QV('ConvertAsWebM', true);
  482. }
  483. QV('metadatadiv', true);
  484. QH('metadatadiv', x);
  485. QH('deskstatus', recFile.name);
  486. QS('progressbar').width = '0px';
  487. }
  488. function processBlock(type, flags, time, data) {
  489. if (type < 0) { pause(); return; }
  490. var waitTime = Math.round((time - recFileLastTime) * parseFloat(Q('PlaySpeed').value));
  491. if ((waitTime < 5) || (videoWriter != null)) {
  492. processBlockEx(type, flags, time, data);
  493. } else {
  494. waitTimerArgs = [type, flags, time, data]
  495. waitTimer = setTimeout(function () { waitTimer = null; if (waitTimerArgs) { processBlockEx(waitTimerArgs[0], waitTimerArgs[1], waitTimerArgs[2], waitTimerArgs[3]); } }, waitTime);
  496. }
  497. }
  498. function processBlockEx(type, flags, time, data, forced) {
  499. if ((playing == false) && (forced !== true)) return;
  500. var flagBinary = (flags & 1) != 0, flagUser = (flags & 2) != 0;
  501. // End of the stream, close the WebM converter
  502. if ((type == 3) && (videoWriter != null)) {
  503. preCanvasDraw();
  504. videoWriter.complete().then(function (webMBlob) {
  505. saveAs(webMBlob, recFile.name.replace('.mcrec', '.webm'));
  506. videoWriter = null;
  507. QE('PlaySpeed', true);
  508. QE('SeekBackwardButton', true);
  509. QE('SeekForwardButton', true);
  510. QE('ConvertAsWebM', true);
  511. QE('OpenFileButton', true);
  512. });
  513. }
  514. if (type == 2) {
  515. // Update the clock
  516. recFileLastTime = time;
  517. var deltaTimeTotalSec = Math.floor((time - recFileStartTime) / 1000);
  518. if (currentDeltaTimeTotalSec != deltaTimeTotalSec) {
  519. // Hours, minutes and seconds
  520. currentDeltaTimeTotalSec = deltaTimeTotalSec;
  521. var hrs = Math.floor(deltaTimeTotalSec / 3600);
  522. var mins = Math.floor((deltaTimeTotalSec % 3600) / 60);
  523. var secs = Math.floor(deltaTimeTotalSec % 60);
  524. QH('timespan', pad2(hrs) + ':' + pad2(mins) + ':' + pad2(secs))
  525. }
  526. // Set the initial time on the WebM movie writer if needed
  527. if (videoWriterLastFrame == null) { videoWriterLastFrame = time; }
  528. videoWriterCurrentFrame = time;
  529. }
  530. // MeshCentral Terminal options
  531. if ((type == 2) && !flagBinary && flagUser && (data.length > 2) && (data[0] == '{')) {
  532. var parsed = null;
  533. try { parsed = JSON.parse(data); } catch (ex) { }
  534. if ((parsed != null) && ((parsed.type == 'options') || (parsed.type == 'termsize')) && (typeof parsed.cols == 'number') && (typeof parsed.rows == 'number')) {
  535. term.resize(parsed.cols, parsed.rows);
  536. //console.log('termsize', parsed.cols, parsed.rows);
  537. }
  538. }
  539. if ((type == 2) && flagBinary && !flagUser) {
  540. // Device --> User data
  541. if (recFileProtocol == 1) {
  542. // MeshCentral Terminal
  543. writeXTerm(data);
  544. } else if (recFileProtocol == 2) {
  545. // MeshCentral Remote Desktop
  546. var view = new Uint8Array(data.length);
  547. for (var i = 0; i < data.length; i++) { view[i] = data.charCodeAt(i); }
  548. // Accumulator is not active
  549. var cmd = (view[0] << 8) + view[1], cmdsize = (view[2] << 8) + view[3];
  550. if ((cmd == 27) && (cmdsize == 8)) { cmd = (view[8] << 8) + view[9]; cmdsize = (view[5] << 16) + (view[6] << 8) + view[7]; view = view.slice(8); }
  551. if (cmdsize != view.byteLength) {
  552. console.log('Bad command size', cmd, cmdsize, view.byteLength);
  553. } else {
  554. agentDesktop.ProcessBinaryCommand(cmd, cmdsize, view.slice(0, cmdsize));
  555. }
  556. } else if (recFileProtocol == 101) {
  557. // Intel AMT KVM
  558. var view = new Uint8Array(data.length);
  559. for (var i = 0; i < data.length; i++) { view[i] = data.charCodeAt(i); }
  560. if ((readState == 0) && (rstr2hex(data).startsWith('4100000000000000'))) {
  561. // We are not authenticated, KVM data starts here.
  562. readState = 1;
  563. if (data.length > 8) { amtDesktop.ProcessBinaryData(view.slice(8).buffer); }
  564. } else if (readState == 1) {
  565. amtDesktop.ProcessBinaryData(view.buffer);
  566. }
  567. } else if (recFileProtocol == 102) {
  568. // Intel AMT midstream KVM
  569. var view = new Uint8Array(data.length);
  570. for (var i = 0; i < data.length; i++) { view[i] = data.charCodeAt(i); }
  571. amtDesktop.ProcessBinaryData(view.buffer);
  572. }
  573. } else if ((type == 2) && flagBinary && flagUser) {
  574. // User --> Device data
  575. if (recFileProtocol == 101) {
  576. // Intel AMT KVM
  577. if (rstr2hex(data) == '0000000008080001000700070003050200000000') { console.log('RGB8'); amtDesktop.bpp = 1; } // Switch to 1 byte per pixel, 256 colors
  578. if (rstr2hex(data) == '000000000808000100FF00000000000000000000') { console.log('GRAY8'); amtDesktop.bpp = 1; obj.graymode = true; } // Switch to 1 byte per pixel, 256 grays
  579. if (rstr2hex(data) == '0000000008040001000F00000000000000000000') { console.log('GRAY4'); amtDesktop.bpp = 1; obj.graymode = true; obj.lowcolor = true; } // Switch to 1 byte per pixel, 16 grays
  580. }
  581. }
  582. // This is a PNG screenshot of the display, load it and render it.
  583. if ((type == 3) && (recFileProtocol == 102)) {
  584. var tile = new Image();
  585. tile.src = "data:image/png;base64," + btoa(data);
  586. tile.onload = function () { amtDesktop.canvas.drawImage(tile, 0, 0); }
  587. tile.error = function () { }
  588. }
  589. if (playing) { readNextBlock(processBlock); }
  590. }
  591. function cleanup() {
  592. clearXTerm();
  593. recFile = null;
  594. recFilePtr = 0;
  595. recFileMetadata = null;
  596. playing = false;
  597. if (agentDesktop != null) { agentDesktop.Canvas.clearRect(0, 0, agentDesktop.CanvasId.width, agentDesktop.CanvasId.height); agentDesktop = null; }
  598. if (amtDesktop != null) { amtDesktop.canvas.clearRect(0, 0, amtDesktop.CanvasId.width, amtDesktop.CanvasId.height); amtDesktop = null; }
  599. readState = 0;
  600. waitTimerArgs = null;
  601. currentDeltaTimeTotalSec = 0;
  602. recFileEndTime = 0;
  603. agentTerminal = null;
  604. if (waitTimer != null) { clearTimeout(waitTimer); waitTimer = null; }
  605. QH('deskstatus', '');
  606. QE('PlayButton', false);
  607. QE('PauseButton', false);
  608. QE('RestartButton', false);
  609. QE('SeekBackwardButton', false);
  610. QE('SeekForwardButton', false);
  611. QS('progressbar').width = '0px';
  612. QH('timespan', '00:00:00');
  613. QV('metadatadiv', true);
  614. if (urlargs.stream == null) {
  615. QH('metadatadiv', '<span style=\"font-family:Arial,Helvetica Neue,Helvetica,sans-serif;font-size:28px\">MeshCentral Session Player</span><br /><br /><span style=color:gray>' + "Drag & drop a .mcrec file or click \"Open File...\"" + '</span>');
  616. } else {
  617. QH('metadatadiv', '');
  618. }
  619. QV('DeskParent', true);
  620. QV('TermParent', false);
  621. QV('XTermParent', false);
  622. }
  623. function ondrop(e) {
  624. if (xxdialogMode) return;
  625. haltEvent(e);
  626. QV('bigfail', false);
  627. QV('bigok', false);
  628. // Check if these are files we can upload, remove all folders.
  629. if (e.dataTransfer == null) return;
  630. var files = [];
  631. for (var i in e.dataTransfer.files) {
  632. if ((e.dataTransfer.files[i].type != null) && (e.dataTransfer.files[i].size != null) && (e.dataTransfer.files[i].size != 0) && (e.dataTransfer.files[i].name.endsWith('.mcrec'))) {
  633. files.push(e.dataTransfer.files[i]);
  634. }
  635. }
  636. if (files.length == 0) return;
  637. cleanup();
  638. recFile = files[0];
  639. recFilePtr = 0;
  640. readLastBlock(function (type, flags, time, extras) {
  641. if (type == 3) {
  642. // File is ok
  643. recFileEndTime = time;
  644. recFileExtras = extras;
  645. readNextBlock(processFirstBlock);
  646. } else {
  647. // This is not a good file
  648. recFileEndTime = 0;
  649. }
  650. });
  651. }
  652. var dragtimer = null;
  653. function ondragover(e) {
  654. if (xxdialogMode) return;
  655. haltEvent(e);
  656. if (dragtimer != null) { clearTimeout(dragtimer); dragtimer = null; }
  657. var ac = true;
  658. QV('bigok', ac);
  659. QV('bigfail', !ac);
  660. }
  661. function ondragleave(e) {
  662. if (xxdialogMode) return;
  663. haltEvent(e);
  664. dragtimer = setTimeout(function () { QV('bigfail', false); QV('bigok', false); dragtimer = null; }, 10);
  665. }
  666. function onkeypress(e) {
  667. if (xxdialogMode) return;
  668. if (e.key == ' ') { togglePause(); haltEvent(e); }
  669. if (e.key == '1') { Q('PlaySpeed').value = 4; haltEvent(e); }
  670. if (e.key == '2') { Q('PlaySpeed').value = 2; haltEvent(e); }
  671. if (e.key == '3') { Q('PlaySpeed').value = 1; haltEvent(e); }
  672. if (e.key == '4') { Q('PlaySpeed').value = 0.5; haltEvent(e); }
  673. if (e.key == '5') { Q('PlaySpeed').value = 0.25; haltEvent(e); }
  674. if (e.key == '6') { Q('PlaySpeed').value = 0.1; haltEvent(e); }
  675. if (e.key == '0') { pause(); restart(); haltEvent(e); }
  676. }
  677. function saveAsWebMfile() {
  678. var x = '';
  679. x += addHtmlValue4("Frame rate", '<select id=webmframerate style=width:200px><option value=100 selected>' + "10 frames/sec" + '</option><option value=50>' + "20 frames/sec" + '</option></select>');
  680. x += addHtmlValue4("Quality", '<select id=webmquality style=width:200px><option value=90>' + "90%" + '</option><option value=80>' + "80%" + '</option><option value=60 selected>' + "60%" + '</option><option value=40>' + "40%" + '</option><option value=20>' + "20%" + '</option><option value=10>' + "10%" + '</option></select>');
  681. setDialogMode(2, "Convert to WebM", 3, saveAsWebMfileEx, x);
  682. }
  683. // Convert the remote desktop or KVM file into a WebM movie file.
  684. function saveAsWebMfileEx() {
  685. videoFrameDuration = parseInt(Q('webmframerate').value);
  686. var quality = parseInt(Q('webmquality').value) / 100;
  687. //console.log(videoFrameDuration, quality);
  688. videoWriterLastFrame = null;
  689. videoWriter = new WebMWriter({ quality: quality, frameDuration: 100, transparent: false });
  690. restart();
  691. play();
  692. QE('PlayButton', false);
  693. QE('PauseButton', false);
  694. QE('RestartButton', false);
  695. QE('PlaySpeed', false);
  696. QE('SeekBackwardButton', false);
  697. QE('SeekForwardButton', false);
  698. QE('ConvertAsWebM', false);
  699. QE('OpenFileButton', false);
  700. }
  701. function preCanvasDraw() {
  702. if (videoWriter) {
  703. var delta = videoWriterCurrentFrame - videoWriterLastFrame;
  704. if (delta >= videoFrameDuration) { videoWriter.addFrame(Q('Desk'), delta); videoWriterLastFrame = videoWriterCurrentFrame; }
  705. }
  706. }
  707. function openfile() {
  708. if (xxdialogMode) return;
  709. var x = '<input type=file name=files id=p2fileinput style=width:100% accept=".mcrec" onchange="openfileChanged()" />';
  710. setDialogMode(2, "Open File...", 3, openfileEx, x);
  711. QE('idx_dlgOkButton', false);
  712. }
  713. function openfileEx() {
  714. var xfiles = Q('p2fileinput').files;
  715. if (xfiles != null) { var files = []; for (var i in xfiles) { if ((xfiles[i].type != null) && (xfiles[i].size != null) && (xfiles[i].size != 0) && (xfiles[i].name.endsWith('.mcrec'))) { files.push(xfiles[i]); } } }
  716. if (files.length == 0) return;
  717. cleanup();
  718. recFile = files[0];
  719. recFilePtr = 0;
  720. readLastBlock(function (type, flags, time, extras) {
  721. if (type == 3) {
  722. // File is ok
  723. recFileEndTime = time;
  724. recFileExtras = extras;
  725. readNextBlock(processFirstBlock);
  726. } else {
  727. // This is not a good file
  728. recFileEndTime = 0;
  729. }
  730. });
  731. Q('OpenFileButton').blur();
  732. }
  733. function openfileChanged() {
  734. var xfiles = Q('p2fileinput').files;
  735. if (xfiles != null) { var files = []; for (var i in xfiles) { if ((xfiles[i].type != null) && (xfiles[i].size != null) && (xfiles[i].size != 0) && (xfiles[i].name.endsWith('.mcrec'))) { files.push(xfiles[i]); } } }
  736. QE('idx_dlgOkButton', files.length == 1);
  737. }
  738. function togglePause() {
  739. if (xxdialogMode) return;
  740. if (term != null) return;
  741. if (recFile != null) { if (playing == true) { pause(); } else { if (recFilePtr != recFile.size) { play(); } } } return false;
  742. }
  743. function play() {
  744. if (xxdialogMode) return;
  745. Q('PlayButton').blur();
  746. if ((playing == true) || (recFileProtocol == 0)) return;
  747. playing = true;
  748. QV('metadatadiv', false);
  749. QE('PlayButton', false);
  750. QE('PauseButton', true);
  751. QE('RestartButton', false);
  752. if ((recFileProtocol == 1) && (term == null)) {
  753. QV('DeskParent', false);
  754. QV('TermParent', false);
  755. QV('XTermParent', true);
  756. setupXTerm();
  757. //agentTerminal = CreateAmtRemoteTerminal('Term', {});
  758. //agentTerminal.State = 3;
  759. }
  760. readNextBlock(processBlock);
  761. }
  762. function pause() {
  763. if (xxdialogMode) return;
  764. Q('PauseButton').blur();
  765. if (playing == false) return;
  766. playing = false;
  767. QE('PlayButton', recFilePtr != recFile.size);
  768. QE('PauseButton', false);
  769. QE('RestartButton', recFilePtr != 0);
  770. if (waitTimer != null) {
  771. clearTimeout(waitTimer);
  772. waitTimer = null;
  773. processBlockEx(waitTimerArgs[0], waitTimerArgs[1], waitTimerArgs[2], waitTimerArgs[3]);
  774. waitTimerArgs = null;
  775. }
  776. }
  777. function restart() {
  778. if (xxdialogMode) return;
  779. Q('RestartButton').blur();
  780. if (playing == true) return;
  781. recFilePtr = 0;
  782. readState = 0;
  783. currentDeltaTimeTotalSec = 0;
  784. QV('metadatadiv', true);
  785. QE('PlayButton', true);
  786. QE('PauseButton', false);
  787. QE('RestartButton', false);
  788. QS('progressbar').width = '0px';
  789. QH('timespan', '00:00:00');
  790. QV('DeskParent', true);
  791. QV('TermParent', false);
  792. QV('XTermParent', false);
  793. clearXTerm();
  794. if (agentDesktop) {
  795. agentDesktop.Canvas.clearRect(0, 0, agentDesktop.CanvasId.width, agentDesktop.CanvasId.height);
  796. } else if (amtDesktop) {
  797. amtDesktop.canvas.clearRect(0, 0, amtDesktop.CanvasId.width, amtDesktop.CanvasId.height);
  798. amtDesktop = CreateAmtRemoteDesktop('Desk');
  799. amtDesktop.onScreenSizeChange = deskAdjust;
  800. amtDesktop.State = 3;
  801. amtDesktop.Start();
  802. if (recFileMetadata.protocol == 102) {
  803. if (recFileMetadata.screenSize) { amtDesktop.width = recFileMetadata.screenSize[0]; amtDesktop.height = recFileMetadata.screenSize[1]; }
  804. if (recFileMetadata.bpp) { amtDesktop.bpp = recFileMetadata.bpp; }
  805. if (recFileMetadata.graymode) { amtDesktop.graymode = recFileMetadata.graymode; }
  806. if (recFileMetadata.lowcolor) { amtDesktop.lowcolor = recFileMetadata.lowcolor; }
  807. amtDesktop.state = 3;
  808. }
  809. } else if (agentTerminal) {
  810. agentTerminal = null;
  811. }
  812. }
  813. function clearConsoleMsg() { QH('p11DeskConsoleMsg', ''); }
  814. // Toggle the web page to full screen
  815. function toggleAspectRatio(toggle) {
  816. if (toggle === 1) { deskAspectRatio = ((deskAspectRatio + 1) % 3); }
  817. deskAdjust();
  818. }
  819. function deskAdjust() {
  820. var parentH = Q('DeskParent').clientHeight, parentW = Q('DeskParent').clientWidth;
  821. var deskH = Q('Desk').height, deskW = Q('Desk').width;
  822. if (deskAspectRatio == 2) {
  823. // Scale mode
  824. QS('Desk')['margin-top'] = null;
  825. QS('Desk').height = '100%';
  826. QS('Desk').width = '100%';
  827. QS('DeskParent').overflow = 'hidden';
  828. } else if (deskAspectRatio == 1) {
  829. // Zoomed mode
  830. QS('Desk')['margin-top'] = '0px';
  831. //QS('Desk')['margin-left'] = '0px';
  832. QS('Desk').height = deskH + 'px';
  833. QS('Desk').width = deskW + 'px';
  834. QS('DeskParent').overflow = 'scroll';
  835. } else {
  836. // Fixed aspect ratio
  837. if ((parentH / parentW) > (deskH / deskW)) {
  838. var hNew = ((deskH * parentW) / deskW) + 'px';
  839. //if (webPageFullScreen || fullscreen) {
  840. //QS('deskarea3x').height = null;
  841. //} else {
  842. // QS('deskarea3x').height = hNew;
  843. //QS('deskarea3x').height = null;
  844. //}
  845. QS('Desk').height = hNew;
  846. QS('Desk').width = '100%';
  847. } else {
  848. var wNew = ((deskW * parentH) / deskH) + 'px';
  849. //if (webPageFullScreen || fullscreen) {
  850. //QS('Desk').height = null;
  851. //} else {
  852. QS('Desk').height = '100%';
  853. //}
  854. QS('Desk').width = wNew;
  855. }
  856. QS('Desk')['margin-top'] = null;
  857. QS('DeskParent').overflow = 'hidden';
  858. }
  859. }
  860. function seekBackward() {
  861. if (xxdialogMode) return;
  862. var ndxNumber = Math.round(currentDeltaTimeTotalSec / recFileMetadata.indexInterval);
  863. if (ndxNumber < 2) {
  864. pause(); restart();
  865. } else {
  866. if (recFileMetadata.indexes[ndxNumber - 2] != null) { seek(ndxNumber - 2); }
  867. }
  868. }
  869. function seekForward() {
  870. if (xxdialogMode) return;
  871. var ndxNumber = Math.round(currentDeltaTimeTotalSec / recFileMetadata.indexInterval);
  872. if (recFileMetadata.indexes[ndxNumber] != null) { seek(ndxNumber); }
  873. }
  874. function progressBarSeek(event) {
  875. var ndxNumber = Math.round((event.clientX / document.body.offsetWidth) * (recFileMetadata.indexes.length + 1)) - 1;
  876. if (ndxNumber == -1) { pause(); restart(); } else { seek(ndxNumber); }
  877. }
  878. var SeekIndex;
  879. var SeekIndexPtr;
  880. var SeekIndexTime;
  881. var SeekPlayState;
  882. function seek(indexNumber) {
  883. if (xxdialogMode) return;
  884. //console.log('seek', indexNumber);
  885. if ((recFileMetadata.indexes == null) || (recFileMetadata.indexes[indexNumber] == null)) return null;
  886. SeekPlayState = playing;
  887. pause();
  888. restart();
  889. SeekIndex = recFileMetadata.indexes[indexNumber];
  890. SeekIndexPtr = 3;
  891. recFileLastTime = SeekIndexTime = recFileStartTime + ((1 + indexNumber) * recFileMetadata.indexInterval * 1000);
  892. recFilePtr = recFileIndexBasePtr + SeekIndex[0];
  893. var width = SeekIndex[1];
  894. var height = SeekIndex[2];
  895. if (recFileEndTime == 0) {
  896. // File pointer progress bar
  897. QS('progressbar').width = Math.floor(100 * (recFilePtr / recFile.size)) + '%';
  898. } else {
  899. // Time progress bar
  900. QS('progressbar').width = Math.floor(((recFileLastTime - recFileStartTime) / (recFileEndTime - recFileStartTime)) * 100) + '%';
  901. }
  902. if (agentDesktop) {
  903. agentDesktop.Canvas.clearRect(0, 0, agentDesktop.CanvasId.width, agentDesktop.CanvasId.height);
  904. agentDesktop.ProcessScreenMsg(width, height);
  905. }
  906. QV('metadatadiv', false);
  907. QV('Desk', false);
  908. seekFetchNext(function () { QV('Desk', true); if (SeekPlayState) { play(); } });
  909. }
  910. function seekFetchNext(func) {
  911. if (SeekIndex[SeekIndexPtr] == null) { func(); return; }
  912. readBlockAt(recFileIndexBasePtr + SeekIndex[SeekIndexPtr], function (type, flags, time, data) {
  913. SeekIndexPtr++;
  914. processBlockEx(type, flags, SeekIndexTime, data, true);
  915. seekFetchNext(func);
  916. });
  917. }
  918. //
  919. // POPUP DIALOG
  920. //
  921. // null = Hidden, 1 = Generic Message
  922. var xxdialogMode = 0;
  923. var xxdialogFunc;
  924. var xxdialogButtons;
  925. var xxdialogTag;
  926. var xxcurrentView = -1;
  927. // Display a dialog box
  928. // Parameters: Dialog Mode (0 = none), Dialog Title, Buttons (1 = OK, 2 = Cancel, 3 = OK & Cancel), Call back function(0 = Cancel, 1 = OK), Dialog Content (Mode 2 only)
  929. function setDialogMode(x, y, b, f, c, tag) {
  930. xxdialogMode = x;
  931. xxdialogFunc = f;
  932. xxdialogButtons = b;
  933. xxdialogTag = tag;
  934. QE('idx_dlgOkButton', true);
  935. QV('idx_dlgOkButton', b & 1);
  936. QV('idx_dlgCancelButton', b & 2);
  937. QV('id_dialogclose', (b & 2) || (b & 8));
  938. QV('idx_dlgDeleteButton', b & 4);
  939. QV('idx_dlgButtonBar', b & 7);
  940. if (y) QH('id_dialogtitle', y);
  941. for (var i = 1; i < 3; i++) { QV('dialog' + i, i == x); } // Edit this line when more dialogs are added
  942. QV('dialog', x);
  943. if (c) { if (x == 2) { QH('id_dialogOptions', c); } else { QH('id_dialogMessage', c); } }
  944. }
  945. function dialogclose(x) {
  946. var f = xxdialogFunc, b = xxdialogButtons, t = xxdialogTag;
  947. setDialogMode();
  948. if (((b & 8) || x) && f) f(x, t);
  949. }
  950. function messagebox(t, m) { setSessionActivity(); QH('id_dialogMessage', m); setDialogMode(1, t, 1); }
  951. function statusbox(t, m) { setSessionActivity(); QH('id_dialogMessage', m); setDialogMode(1, t); }
  952. function haltEvent(e) { if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }
  953. function pad2(num) { var s = '00' + num; return s.substr(s.length - 2); }
  954. function format(format) { var args = Array.prototype.slice.call(arguments, 1); return format.replace(/{(\d+)}/g, function (match, number) { return typeof args[number] != 'undefined' ? args[number] : match; }); };
  955. function addHtmlValue(t, v) { return '<table><td style=width:120px>' + t + '<td><b>' + v + '</b></table>'; }
  956. function addHtmlValue2(t, v) { return '<div><div style=display:inline-block;float:right>' + v + '</div><div style=display:inline-block>' + t + '</div></div>'; }
  957. function addHtmlValue3(t, v) { return '<div><b>' + t + '</b></div><div style=margin-left:16px>' + v + '</div>'; }
  958. function addHtmlValue4(t, v) { return '<table style=width:100%><td style=width:120px>' + t + '<td style=text-align:right><b>' + v + '</b></table>'; }
  959. function addHtmlValue5(t, v) { return '<div style=padding:4px><div style=display:inline-block;float:right><b>' + v + '</b></div><div style=display:inline-block>' + t + '</div></div>'; }
  960. // Make the dialog box movable
  961. function dialogBoxDrag() {
  962. var elmnt = Q('dialog');
  963. var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
  964. Q('dialogHeader').onmousedown = dragMouseDown;
  965. function dragMouseDown(e) {
  966. e = e || window.event;
  967. e.preventDefault();
  968. pos3 = e.clientX;
  969. pos4 = e.clientY;
  970. document.onmouseup = closeDragElement;
  971. document.onmousemove = elementDrag;
  972. }
  973. function elementDrag(e) {
  974. e = e || window.event;
  975. e.preventDefault();
  976. pos1 = pos3 - e.clientX;
  977. pos2 = pos4 - e.clientY;
  978. pos3 = e.clientX;
  979. pos4 = e.clientY;
  980. elmnt.style.top = (elmnt.offsetTop - pos2) + 'px';
  981. elmnt.style.left = (elmnt.offsetLeft - pos1) + 'px';
  982. }
  983. function closeDragElement() {
  984. document.onmouseup = null;
  985. document.onmousemove = null;
  986. }
  987. }
  988. // This method has caused exceptions: https://github.com/Ylianst/MeshCentral/issues/4302
  989. function ArrayBufferToString(buffer) {
  990. try { return BinaryToString(String.fromCharCode.apply(null, Array.prototype.slice.apply(new Uint8Array(buffer)))); } catch (ex) { }
  991. console.log('ArrayBufferToString - Unable to convert ' + buffer.byteLength + ' bytes.');
  992. var s = '', u = new Uint8Array(buffer);
  993. for (var i = 0; i < buffer.byteLength; i++) { s += String.fromCharCode(u[i]); }
  994. return s;
  995. }
  996. function StringToArrayBuffer(string) {
  997. return StringToUint8Array(string).buffer;
  998. }
  999. function BinaryToString(binary) {
  1000. var error;
  1001. try {
  1002. return decodeURIComponent(escape(binary));
  1003. } catch (_error) {
  1004. error = _error;
  1005. if (error instanceof URIError) { return binary; } else { throw error; }
  1006. }
  1007. }
  1008. function StringToBinary(string) {
  1009. var chars, code, i, isUCS2, len, _i;
  1010. len = string.length;
  1011. chars = [];
  1012. isUCS2 = false;
  1013. for (i = _i = 0; 0 <= len ? _i < len : _i > len; i = 0 <= len ? ++_i : --_i) {
  1014. code = String.prototype.charCodeAt.call(string, i);
  1015. if (code > 255) { isUCS2 = true; chars = null; break; } else { chars.push(code); }
  1016. }
  1017. if (isUCS2 === true) {
  1018. return unescape(encodeURIComponent(string));
  1019. } else {
  1020. return String.fromCharCode.apply(null, Array.prototype.slice.apply(chars));
  1021. }
  1022. }
  1023. function StringToUint8Array(string) {
  1024. var binary, binLen, buffer, chars, i, _i;
  1025. binary = StringToBinary(string);
  1026. binLen = binary.length;
  1027. buffer = new ArrayBuffer(binLen);
  1028. chars = new Uint8Array(buffer);
  1029. for (i = _i = 0; 0 <= binLen ? _i < binLen : _i > binLen; i = 0 <= binLen ? ++_i : --_i) { chars[i] = String.prototype.charCodeAt.call(binary, i); }
  1030. return chars;
  1031. }
  1032. function setupXTerm() {
  1033. // Setup the terminal
  1034. if (term != null) { term.dispose(); }
  1035. term = new Terminal();
  1036. term.open(Q('XTermParent'));
  1037. term.resize(80, 25);
  1038. //term.setOption('convertEol', true); // Consider \n to be \r\n, this should be taken care of by "termios"
  1039. }
  1040. function clearXTerm() {
  1041. if (term != null) { term.dispose(); term = null; }
  1042. }
  1043. function writeXTerm(data) {
  1044. if (term == null) return;
  1045. if (term.writeUtf8) {
  1046. if (typeof data == 'string') { term.writeUtf8(data); } else { term.writeUtf8(new Uint8Array(data)); }
  1047. } else {
  1048. if (typeof data == 'string') { term.write(data); } else { term.write(new Uint8Array(data)); }
  1049. }
  1050. }
  1051. start();
  1052. </script>
  1053. </body>
  1054. </html>