livedesk 0.1.285 → 0.1.287

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/livedesk.js CHANGED
@@ -518,6 +518,20 @@ function quoteWindowsCommandArg(value) {
518
518
  return `"${text.replaceAll('"', '\\"')}"`;
519
519
  }
520
520
 
521
+ function buildHubRestartBootstrapScript() {
522
+ return [
523
+ 'const { spawn } = require("node:child_process");',
524
+ 'const waitPid = Number(process.env.LIVEDESK_RESTART_WAIT_PID || 0);',
525
+ 'const isAlive = pid => { try { process.kill(pid, 0); return true; } catch (error) { return error?.code !== "ESRCH"; } };',
526
+ 'const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));',
527
+ 'const waitForExit = async pid => { for (let attempt = 0; attempt < 240 && pid > 1; attempt += 1) { if (!isAlive(pid)) return; await sleep(250); } if (pid > 1 && isAlive(pid)) throw new Error("Previous LiveDesk Hub launcher did not exit before restart."); };',
528
+ 'const command = process.env.LIVEDESK_RESTART_COMMAND || "";',
529
+ 'const args = JSON.parse(Buffer.from(process.env.LIVEDESK_RESTART_ARGS_BASE64 || "", "base64").toString("utf8"));',
530
+ '(async () => { await waitForExit(waitPid); if (!command || !Array.isArray(args)) throw new Error("LiveDesk Hub restart command is unavailable."); const next = spawn(command, args, { cwd: process.env.LIVEDESK_RESTART_CWD || process.cwd(), env: process.env, detached: true, stdio: "ignore", windowsHide: true }); next.once("error", error => { console.error("LiveDesk Hub restart failed to start: " + error.message); process.exitCode = 1; }); next.once("spawn", () => next.unref()); })().catch(error => { console.error("LiveDesk Hub restart bootstrap failed: " + error.message); process.exitCode = 1; });',
531
+ ''
532
+ ].join('\n');
533
+ }
534
+
521
535
  async function runManager(args) {
522
536
  const options = parseManagerArgs(args);
523
537
  const httpPort = normalizePort(
@@ -572,21 +586,23 @@ async function runManager(args) {
572
586
  const commandArgs = process.platform === 'win32'
573
587
  ? ['/d', '/s', '/c', `call ${quoteWindowsCommandArg(npxCommand)} ${nextArgs.map(quoteWindowsCommandArg).join(' ')}`]
574
588
  : nextArgs;
575
- const next = spawn(command, commandArgs, {
589
+ const restartBootstrap = spawn(process.execPath, ['-e', buildHubRestartBootstrapScript()], {
576
590
  env: {
577
591
  ...process.env,
578
- LIVEDESK_NODE_EXECUTABLE: process.execPath,
579
- LIVEDESK_NPX_EXECUTABLE: npxCommand
592
+ LIVEDESK_RESTART_WAIT_PID: String(process.pid),
593
+ LIVEDESK_RESTART_COMMAND: command,
594
+ LIVEDESK_RESTART_ARGS_BASE64: Buffer.from(JSON.stringify(commandArgs), 'utf8').toString('base64'),
595
+ LIVEDESK_RESTART_CWD: process.cwd()
580
596
  },
581
- stdio: 'inherit',
597
+ stdio: 'ignore',
582
598
  detached: true,
583
- windowsHide: false
599
+ windowsHide: true
584
600
  });
585
- next.once('error', error => {
586
- console.error(`Failed to relaunch LiveDesk Hub from npm: ${error.message}`);
601
+ restartBootstrap.once('error', error => {
602
+ console.error(`Failed to prepare LiveDesk Hub restart: ${error.message}`);
587
603
  });
588
- next.unref();
589
- console.log('[LiveDesk Hub] Update approved. The latest Hub launcher is starting.');
604
+ restartBootstrap.once('spawn', () => restartBootstrap.unref());
605
+ console.log('[LiveDesk Hub] Update approved. The current Hub launcher is exiting and the latest Hub will start automatically.');
590
606
  setTimeout(() => process.exit(0), 100);
591
607
  };
592
608
 
@@ -99,7 +99,7 @@ export function createHubUdpTransport({ env = process.env, logEvent = () => {},
99
99
 
100
100
  function onRendezvousPeer(message, rinfo) {
101
101
  const session = [...sessions.values()].find(item => item.sessionId === safeText(message.roomId, 160));
102
- if (!session || !rendezvousHost || rinfo.address !== rendezvousHost) return;
102
+ if (!session || !rendezvousHost || Number(rinfo.port) !== rendezvousPort) return;
103
103
  const address = safeText(message.host, 128);
104
104
  const port = Number(message.port);
105
105
  if (!address || !Number.isInteger(port) || port < 1 || port > 65535) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "livedesk",
3
- "version": "0.1.285",
3
+ "version": "0.1.287",
4
4
  "description": "LiveDesk Hub and client launcher",
5
5
  "type": "module",
6
6
  "bin": {