livedesk 0.1.252 → 0.1.254

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/README.md CHANGED
@@ -13,15 +13,13 @@ This starts the LiveDesk Hub, opens the local screen wall, and accepts clients.
13
13
  The Hub UI/API listens on `127.0.0.1` by default while the client endpoint
14
14
  continues to listen on the LAN.
15
15
 
16
- On startup, the launcher finds stale processes whose command line identifies
17
- them as a LiveDesk Hub, even if the old Hub is still starting and has not
18
- finished binding its ports. It also checks the Hub ports (`5179` and `5197`),
19
- waits for stale LiveDesk processes to exit, and then starts the new Hub. The
20
- client endpoint remains fixed at TCP `5197` by default so firewall rules,
21
- router forwarding, and direct clients keep a stable contract. An unrelated
22
- process is preserved and reported instead of being terminated; stop it or use
23
- an explicit `--remote-port` value. Pass `--no-clean` to disable the startup
24
- cleanup explicitly.
16
+ On startup, the launcher checks the Hub ports (`5179` and `5197`), stops every
17
+ process listening on those configured ports, waits for the ports to be released,
18
+ and then starts the new Hub. The client endpoint remains fixed at TCP `5197` by
19
+ default so firewall rules, router forwarding, and direct clients keep a stable
20
+ contract. If a process cannot be stopped or the port remains occupied, startup
21
+ fails with the owning PID and command line. Pass `--no-clean` to disable the
22
+ startup cleanup explicitly.
25
23
 
26
24
  ## Client
27
25
 
package/bin/livedesk.js CHANGED
@@ -223,7 +223,6 @@ async function stopProcessesOnPorts(ports) {
223
223
  '$ErrorActionPreference = "SilentlyContinue";',
224
224
  `$ports = @(${uniquePorts.join(',')});`,
225
225
  `$currentNodePid = ${process.pid};`,
226
- " $hubProcessPattern = '(?i)(?:livedesk|@livedesk).*hub[\\\\/].*server\\.js';",
227
226
  'function Get-ListenConnections($port) {',
228
227
  ' $connections = @(Get-NetTCPConnection -LocalPort $port -State Listen -ErrorAction SilentlyContinue);',
229
228
  ' if ($connections.Count -gt 0) { return $connections }',
@@ -236,38 +235,29 @@ async function stopProcessesOnPorts(ports) {
236
235
  ' }',
237
236
  '}',
238
237
  '$records = foreach ($port in $ports) {',
239
- ' $connections = @(Get-ListenConnections $port | Where-Object { $_.OwningProcess -and $_.OwningProcess -ne $currentNodePid });',
238
+ ' $connections = @(Get-ListenConnections $port | Where-Object { $_.OwningProcess -and $_.OwningProcess -ne $currentNodePid -and $_.OwningProcess -ne $PID });',
240
239
  ' foreach ($connection in $connections) {',
241
240
  ' $owner = [int]$connection.OwningProcess;',
242
241
  ' $proc = Get-CimInstance Win32_Process -Filter "ProcessId = $owner" -ErrorAction SilentlyContinue;',
243
242
  ' $processName = if ($proc) { [string]$proc.Name } else { "" };',
244
243
  ' $commandLine = if ($proc) { [string]$proc.CommandLine } else { "" };',
245
- ' $knownLiveDesk = $commandLine -match "(?i)(?:livedesk|@livedesk).*hub[\\\\/].*server\\.js";',
246
- ' [pscustomobject]@{ Port = [int]$port; Pid = $owner; ProcessName = $processName; CommandLine = $commandLine; KnownLiveDesk = [bool]$knownLiveDesk; Action = "preserved"; PortAvailable = $false; ProcessGone = $false }',
244
+ ' [pscustomobject]@{ Port = [int]$port; Pid = $owner; ProcessName = $processName; CommandLine = $commandLine; Action = "preserved"; PortAvailable = $false }',
247
245
  ' }',
248
246
  '}',
249
247
  '$records = @($records | Sort-Object Port,Pid -Unique);',
250
- '$hubProcesses = @(Get-CimInstance Win32_Process -ErrorAction SilentlyContinue | Where-Object { $_.ProcessId -and $_.ProcessId -ne $currentNodePid -and ([string]$_.Name) -ieq "node.exe" -and ([string]$_.CommandLine) -match $hubProcessPattern });',
251
- 'foreach ($proc in $hubProcesses) {',
252
- ' if (-not (@($records | Where-Object { $_.Pid -eq [int]$proc.ProcessId }).Count)) {',
253
- ' $records += [pscustomobject]@{ Port = 0; Pid = [int]$proc.ProcessId; ProcessName = [string]$proc.Name; CommandLine = [string]$proc.CommandLine; KnownLiveDesk = $true; Action = "preserved"; PortAvailable = $false; ProcessGone = $false }',
254
- ' }',
255
- '}',
256
- 'foreach ($record in @($records | Where-Object { $_.KnownLiveDesk })) {',
248
+ 'foreach ($record in $records) {',
257
249
  ' Stop-Process -Id $record.Pid -Force -ErrorAction SilentlyContinue;',
258
250
  ' $record.Action = "stopped";',
259
251
  '}',
260
252
  '$deadline = (Get-Date).ToUniversalTime().AddMilliseconds(3000);',
261
253
  'do {',
262
- ' $busyPorts = @($ports | ForEach-Object { Get-ListenConnections $_ });',
263
- ' $busyHubPids = @($records | Where-Object { $_.KnownLiveDesk } | ForEach-Object { Get-Process -Id $_.Pid -ErrorAction SilentlyContinue });',
264
- ' if (($busyPorts.Count -eq 0 -and $busyHubPids.Count -eq 0) -or (Get-Date).ToUniversalTime() -ge $deadline) { break }',
254
+ ' $busyConnections = @($ports | ForEach-Object { Get-ListenConnections $_ });',
255
+ ' if ($busyConnections.Count -eq 0 -or (Get-Date).ToUniversalTime() -ge $deadline) { break }',
265
256
  ' Start-Sleep -Milliseconds 100;',
266
257
  '} while ($true);',
267
- '$busyPortNumbers = @($busyPorts | Select-Object -ExpandProperty LocalPort -Unique);',
258
+ '$busyPortNumbers = @($busyConnections | Select-Object -ExpandProperty LocalPort -Unique);',
268
259
  'foreach ($record in $records) {',
269
260
  ' $record.PortAvailable = $busyPortNumbers -notcontains $record.Port;',
270
- ' $record.ProcessGone = -not (Get-Process -Id $record.Pid -ErrorAction SilentlyContinue);',
271
261
  '}',
272
262
  '$records | ConvertTo-Json -Compress'
273
263
  ].join(' ');
@@ -287,12 +277,12 @@ async function stopProcessesOnPorts(ports) {
287
277
  const stopped = records.filter(record => record?.Action === 'stopped');
288
278
  if (stopped.length > 0) {
289
279
  const summary = stopped.map(record => `${record.Pid}:${record.ProcessName || 'node'}${record.Port ? `@${record.Port}` : ''}`).join(', ');
290
- console.log(`Restarting LiveDesk Hub. Stopped stale LiveDesk owner(s): ${summary}`);
280
+ console.log(`Restarting LiveDesk Hub. Stopped Hub port owner(s): ${summary}`);
291
281
  }
292
- const blocked = records.filter(record => record?.PortAvailable !== true || (record?.Port === 0 && record?.ProcessGone !== true));
282
+ const blocked = records.filter(record => record?.PortAvailable !== true);
293
283
  if (blocked.length > 0) {
294
- const summary = blocked.map(record => `${record.Pid}:${record.ProcessName || 'unknown'}@${record.Port}[port-free=${record.PortAvailable === true},process-gone=${record.ProcessGone === true}]`).join(', ');
295
- throw new Error(`LiveDesk Hub startup cleanup could not release port/process owner(s): ${summary}. LiveDesk keeps the configured port fixed; stop that process or choose an explicit --port/--remote-port value.`);
284
+ const summary = blocked.map(record => `${record.Pid}:${record.ProcessName || 'unknown'}@${record.Port}[port-free=${record.PortAvailable === true},cmd=${String(record.CommandLine || 'unavailable').replace(/\s+/g, ' ').slice(0, 240)}]`).join(', ');
285
+ throw new Error(`LiveDesk Hub startup cleanup could not release port/process owner(s): ${summary}. Stop that process manually or choose an explicit --port/--remote-port value.`);
296
286
  }
297
287
  return;
298
288
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "livedesk",
3
- "version": "0.1.252",
3
+ "version": "0.1.254",
4
4
  "description": "LiveDesk Hub and client launcher",
5
5
  "type": "module",
6
6
  "bin": {