livedesk 0.1.7 → 0.1.8
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 +41 -2
- package/package.json +2 -2
package/bin/livedesk.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
|
-
import { dirname, resolve } from 'node:path';
|
|
4
|
+
import { dirname, join, resolve } from 'node:path';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { execFile, spawn } from 'node:child_process';
|
|
7
|
-
import { existsSync } from 'node:fs';
|
|
7
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
8
|
+
import { randomBytes } from 'node:crypto';
|
|
8
9
|
import os from 'node:os';
|
|
9
10
|
|
|
10
11
|
const require = createRequire(import.meta.url);
|
|
@@ -13,6 +14,8 @@ const packageRoot = resolve(__dirname, '..');
|
|
|
13
14
|
const DEFAULT_MANAGER_HTTP_PORT = 5179;
|
|
14
15
|
const DEFAULT_REMOTE_HUB_PORT = 5197;
|
|
15
16
|
const DEFAULT_MANAGER_URL = `http://127.0.0.1:${DEFAULT_MANAGER_HTTP_PORT}`;
|
|
17
|
+
const MANAGER_STATE_DIR = join(os.homedir(), '.livedesk');
|
|
18
|
+
const MANAGER_STATE_PATH = join(MANAGER_STATE_DIR, 'manager.json');
|
|
16
19
|
|
|
17
20
|
function printHelp() {
|
|
18
21
|
process.stdout.write(`
|
|
@@ -139,6 +142,37 @@ function normalizePort(value, fallback) {
|
|
|
139
142
|
return number;
|
|
140
143
|
}
|
|
141
144
|
|
|
145
|
+
function readStablePairToken() {
|
|
146
|
+
try {
|
|
147
|
+
const state = JSON.parse(readFileSync(MANAGER_STATE_PATH, 'utf8'));
|
|
148
|
+
const pairToken = String(state?.pairToken || '').trim();
|
|
149
|
+
if (pairToken.length >= 20) {
|
|
150
|
+
return pairToken;
|
|
151
|
+
}
|
|
152
|
+
} catch {
|
|
153
|
+
// A missing or unreadable state file is repaired below.
|
|
154
|
+
}
|
|
155
|
+
return '';
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function getStablePairToken() {
|
|
159
|
+
const existing = readStablePairToken();
|
|
160
|
+
if (existing) {
|
|
161
|
+
return existing;
|
|
162
|
+
}
|
|
163
|
+
const pairToken = randomBytes(18).toString('hex');
|
|
164
|
+
try {
|
|
165
|
+
mkdirSync(MANAGER_STATE_DIR, { recursive: true });
|
|
166
|
+
writeFileSync(MANAGER_STATE_PATH, JSON.stringify({
|
|
167
|
+
pairToken,
|
|
168
|
+
createdAt: new Date().toISOString()
|
|
169
|
+
}, null, 2));
|
|
170
|
+
} catch {
|
|
171
|
+
// If disk persistence is blocked, keep this manager process usable.
|
|
172
|
+
}
|
|
173
|
+
return pairToken;
|
|
174
|
+
}
|
|
175
|
+
|
|
142
176
|
function openBrowser(url) {
|
|
143
177
|
if (!url) {
|
|
144
178
|
return;
|
|
@@ -253,6 +287,10 @@ async function runManager(args) {
|
|
|
253
287
|
const openUrl = options.openUrlExplicit
|
|
254
288
|
? (options.openUrl || `http://127.0.0.1:${httpPort}`)
|
|
255
289
|
: `http://127.0.0.1:${httpPort}`;
|
|
290
|
+
const pairToken = process.env.REMOTE_HUB_PAIR_TOKEN
|
|
291
|
+
|| process.env.LIVEDESK_CLIENT_PAIR_TOKEN
|
|
292
|
+
|| process.env.MINDEXEC_REMOTE_PAIR_TOKEN
|
|
293
|
+
|| getStablePairToken();
|
|
256
294
|
|
|
257
295
|
if (options.cleanPortsOnStart) {
|
|
258
296
|
await stopProcessesOnPorts([httpPort, remotePort]);
|
|
@@ -268,6 +306,7 @@ async function runManager(args) {
|
|
|
268
306
|
LIVEDESK_HUB_HTTP_HOST: options.host || process.env.LIVEDESK_HUB_HTTP_HOST || '0.0.0.0',
|
|
269
307
|
LIVEDESK_HUB_HTTP_PORT: String(httpPort),
|
|
270
308
|
REMOTE_HUB_PORT: String(remotePort),
|
|
309
|
+
REMOTE_HUB_PAIR_TOKEN: pairToken,
|
|
271
310
|
LIVEDESK_WEB_DIST: existsSync(resolve(packagedWebDist, 'index.html')) ? packagedWebDist : (process.env.LIVEDESK_WEB_DIST || '')
|
|
272
311
|
};
|
|
273
312
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "livedesk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "LiveDesk manager and client launcher",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"node": ">=20"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@livedesk/client": "0.1.
|
|
33
|
+
"@livedesk/client": "0.1.20",
|
|
34
34
|
"cors": "^2.8.5",
|
|
35
35
|
"express": "^4.21.2",
|
|
36
36
|
"ws": "^8.18.3"
|