@livedesk/client 0.1.12 → 0.1.14
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 +5 -4
- package/bin/livedesk-client.js +37 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,10 +7,11 @@ npx @livedesk/client
|
|
|
7
7
|
npx @livedesk/client 3
|
|
8
8
|
```
|
|
9
9
|
|
|
10
|
-
The default flow opens Google sign-in,
|
|
11
|
-
published by the same account, and connects locally.
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
The default flow opens Google sign-in, waits for the active LiveDesk manager
|
|
11
|
+
published by the same account, and connects locally. If the manager is not
|
|
12
|
+
ready yet, the client keeps checking every 5 seconds instead of exiting. Omit the
|
|
13
|
+
number for first-available placement, or pass `1` to `999` to pin this machine
|
|
14
|
+
to a screen wall slot.
|
|
14
15
|
|
|
15
16
|
On the manager computer, open the LiveDesk dashboard and sign in first. The
|
|
16
17
|
dashboard keeps its local hub address and private pair token refreshed in the
|
package/bin/livedesk-client.js
CHANGED
|
@@ -30,8 +30,9 @@ Usage:
|
|
|
30
30
|
npx @livedesk/client 3
|
|
31
31
|
|
|
32
32
|
Default flow:
|
|
33
|
-
Opens Google sign-in,
|
|
33
|
+
Opens Google sign-in, waits for the signed-in manager, and connects locally.
|
|
34
34
|
Omit the number for first-available placement, or pass 1-999 to pin a slot.
|
|
35
|
+
If no manager is active yet, the client keeps checking every 5 seconds.
|
|
35
36
|
|
|
36
37
|
Options:
|
|
37
38
|
--slot <number> Screen wall slot number for this computer.
|
|
@@ -259,7 +260,7 @@ async function createSupabaseClient() {
|
|
|
259
260
|
const { createClient } = await import('@supabase/supabase-js');
|
|
260
261
|
return createClient(SUPABASE_URL, SUPABASE_PUBLISHABLE_KEY, {
|
|
261
262
|
auth: {
|
|
262
|
-
autoRefreshToken:
|
|
263
|
+
autoRefreshToken: true,
|
|
263
264
|
persistSession: true,
|
|
264
265
|
detectSessionInUrl: false,
|
|
265
266
|
flowType: 'pkce',
|
|
@@ -492,13 +493,17 @@ function canConnectToEndpoint(endpoint, timeoutMs = 1200) {
|
|
|
492
493
|
});
|
|
493
494
|
}
|
|
494
495
|
|
|
495
|
-
|
|
496
|
+
function sleep(ms) {
|
|
497
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
async function chooseReachableEndpoint(candidates, options = {}) {
|
|
496
501
|
for (const endpoint of candidates) {
|
|
497
502
|
if (await canConnectToEndpoint(endpoint)) {
|
|
498
503
|
return endpoint;
|
|
499
504
|
}
|
|
500
505
|
}
|
|
501
|
-
return candidates[0] || DEFAULT_MANAGER;
|
|
506
|
+
return options.requireReachable ? '' : (candidates[0] || DEFAULT_MANAGER);
|
|
502
507
|
}
|
|
503
508
|
|
|
504
509
|
function normalizeEndpointCandidates(target) {
|
|
@@ -509,7 +514,7 @@ function normalizeEndpointCandidates(target) {
|
|
|
509
514
|
return [...new Set(rawCandidates.map(value => String(value || '').trim()).filter(Boolean))];
|
|
510
515
|
}
|
|
511
516
|
|
|
512
|
-
async function resolveManagerFromSupabase(supabase) {
|
|
517
|
+
async function resolveManagerFromSupabase(supabase, options = {}) {
|
|
513
518
|
const { data, error } = await supabase
|
|
514
519
|
.from('livedesk_remote_host_targets')
|
|
515
520
|
.select('endpoint, endpoint_candidates, pair_token, active, expires_at, updated_at, manager_version')
|
|
@@ -531,7 +536,10 @@ async function resolveManagerFromSupabase(supabase) {
|
|
|
531
536
|
if (endpointCandidates.length === 0) {
|
|
532
537
|
throw new Error('The LiveDesk manager record does not contain a reachable local address.');
|
|
533
538
|
}
|
|
534
|
-
const manager = await chooseReachableEndpoint(endpointCandidates);
|
|
539
|
+
const manager = await chooseReachableEndpoint(endpointCandidates, { requireReachable: options.requireReachable === true });
|
|
540
|
+
if (!manager) {
|
|
541
|
+
throw new Error(`No reachable LiveDesk manager endpoint yet. Checked ${endpointCandidates.join(', ')}.`);
|
|
542
|
+
}
|
|
535
543
|
return {
|
|
536
544
|
manager,
|
|
537
545
|
pair: data.pair_token,
|
|
@@ -539,6 +547,28 @@ async function resolveManagerFromSupabase(supabase) {
|
|
|
539
547
|
};
|
|
540
548
|
}
|
|
541
549
|
|
|
550
|
+
async function waitForManagerFromSupabase(supabase, options = {}) {
|
|
551
|
+
const intervalMs = Math.max(1000, Number(options.intervalMs || 5000));
|
|
552
|
+
const intervalSeconds = Math.max(1, Math.round(intervalMs / 1000));
|
|
553
|
+
let attempts = 0;
|
|
554
|
+
let lastMessage = '';
|
|
555
|
+
console.log(`Waiting for a LiveDesk manager. This client will keep trying every ${intervalSeconds}s.`);
|
|
556
|
+
while (true) {
|
|
557
|
+
attempts += 1;
|
|
558
|
+
try {
|
|
559
|
+
return await resolveManagerFromSupabase(supabase, { requireReachable: true });
|
|
560
|
+
} catch (err) {
|
|
561
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
562
|
+
if (message !== lastMessage || attempts === 1 || attempts % 6 === 0) {
|
|
563
|
+
const suffix = attempts === 1 ? '' : ` attempt ${attempts}`;
|
|
564
|
+
console.log(`Still waiting for LiveDesk manager${suffix}: ${message}`);
|
|
565
|
+
lastMessage = message;
|
|
566
|
+
}
|
|
567
|
+
await sleep(intervalMs);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
542
572
|
async function prepareLoginConnection(parsed) {
|
|
543
573
|
if (parsed.logout) {
|
|
544
574
|
rmSync(CLIENT_AUTH_PATH, { force: true });
|
|
@@ -556,7 +586,7 @@ async function prepareLoginConnection(parsed) {
|
|
|
556
586
|
const session = await signInWithGoogle(supabase, { authPort: parsed.authPort });
|
|
557
587
|
const email = session.user?.email ? ` as ${session.user.email}` : '';
|
|
558
588
|
console.log(`Signed in to LiveDesk${email}.`);
|
|
559
|
-
const resolved = await
|
|
589
|
+
const resolved = await waitForManagerFromSupabase(supabase);
|
|
560
590
|
manager = resolved.manager;
|
|
561
591
|
pair = resolved.pair;
|
|
562
592
|
console.log(`Found LiveDesk manager at ${manager}.`);
|