yaver-feedback-react-native 0.7.8 → 0.7.9

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/dist/Discovery.js CHANGED
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.YaverDiscovery = void 0;
4
37
  function getAsyncStorage() {
@@ -201,38 +234,20 @@ class YaverDiscovery {
201
234
  * does on same-LAN.
202
235
  */
203
236
  static async raceProbe(urls) {
204
- if (!urls || urls.length === 0)
205
- return null;
206
- const attempts = urls.map((url) => YaverDiscovery.probe(url).then((r) => {
207
- if (!r)
208
- throw new Error('no-200');
209
- return r;
210
- }));
211
- try {
212
- // `Promise.any` isn't on every RN runtime yet (older Hermes).
213
- // Hand-roll the same behaviour so we don't need a polyfill.
214
- return await new Promise((resolve) => {
215
- let remaining = attempts.length;
216
- let settled = false;
217
- attempts.forEach((p) => {
218
- p.then((r) => {
219
- if (settled)
220
- return;
221
- settled = true;
222
- resolve(r);
223
- }).catch(() => {
224
- remaining -= 1;
225
- if (remaining <= 0 && !settled) {
226
- settled = true;
227
- resolve(null);
228
- }
229
- });
230
- });
231
- });
232
- }
233
- catch {
237
+ // Delegate to the canonical client-core implementation so mobile +
238
+ // SDK run the same race logic. Returned shape is `ProbeResult` —
239
+ // structurally compatible with DiscoveryResult minus the required
240
+ // hostname/version fields, which we backfill with sane defaults.
241
+ const { raceHealthProbes } = await Promise.resolve().then(() => __importStar(require('./_core/device')));
242
+ const res = await raceHealthProbes(urls, { timeoutMs: PROBE_TIMEOUT_MS });
243
+ if (!res)
234
244
  return null;
235
- }
245
+ return {
246
+ url: res.url,
247
+ hostname: res.hostname ?? 'Unknown',
248
+ version: res.version ?? 'unknown',
249
+ latency: res.latency ?? 0,
250
+ };
236
251
  }
237
252
  /**
238
253
  * Discover agent via relay HTTP proxy. Uses the user's configured
@@ -0,0 +1,79 @@
1
+ export interface CoreDevice {
2
+ /** Convex-issued device id. */
3
+ deviceId: string;
4
+ /** Display name — usually hostname. */
5
+ name: string;
6
+ /** OS family — "darwin", "linux", "windows". */
7
+ platform: string;
8
+ isOnline: boolean;
9
+ needsAuth: boolean;
10
+ runnerDown: boolean;
11
+ /** Unix ms of the latest heartbeat the agent sent to Convex. */
12
+ lastHeartbeat: number;
13
+ isGuest: boolean;
14
+ hostName?: string;
15
+ hostEmail?: string;
16
+ accessScope?: 'owner' | 'shared-scoped' | 'shared-legacy';
17
+ /** Primary LAN IP (or tunnel host) the agent advertised. */
18
+ quicHost: string;
19
+ quicPort: number;
20
+ /** HTTP port the agent listens on (usually 18080). */
21
+ httpPort?: number;
22
+ publicKey?: string;
23
+ /** Stable hardware identifier — dedup key for re-pair events. */
24
+ hwid?: string;
25
+ /**
26
+ * Every LAN IP the agent reported in its last heartbeat. Used by
27
+ * Discovery.raceProbe to try all interfaces in parallel.
28
+ */
29
+ localIps?: string[];
30
+ }
31
+ export declare function deviceIdentityKey(d: CoreDevice): string;
32
+ export declare function deviceAliasKey(d: CoreDevice): string | null;
33
+ export declare function deviceEndpointKey(d: CoreDevice): string | null;
34
+ export declare function mergeDeviceEntries(a: CoreDevice, b: CoreDevice): CoreDevice;
35
+ /**
36
+ * Collapse duplicate Convex rows so each physical machine appears
37
+ * exactly once. Three passes — identity key → alias key → endpoint key.
38
+ * Safe on empty lists; idempotent on already-deduped input.
39
+ */
40
+ export declare function collapseDevices(devices: CoreDevice[]): CoreDevice[];
41
+ /**
42
+ * "Fresh" matches the mobile app: online + heartbeat < 90 s. Clients
43
+ * read Convex's `isOnline` first (backend already applies its own 90 s
44
+ * gate from the server clock), then use this helper when they need the
45
+ * phone-side freshness opinion too — e.g. for auto-connect picks.
46
+ */
47
+ export declare function isDeviceFresh(d: CoreDevice, now?: number): boolean;
48
+ /**
49
+ * Choose the best candidate for an auto-connect attempt. Preference:
50
+ * 1. explicit `preferredDeviceId` that's still fresh
51
+ * 2. fresh (online + recent heartbeat) + has a quicHost
52
+ * 3. online + has a quicHost
53
+ * 4. first with a quicHost
54
+ */
55
+ export declare function pickTargetDevice(devices: CoreDevice[], preferredDeviceId?: string): CoreDevice | null;
56
+ /**
57
+ * Build the set of `/health` candidate URLs for a target device —
58
+ * `quicHost` plus every LAN IP the agent reported in `localIps`,
59
+ * uniqued and formatted. This is the thing that makes direct LAN
60
+ * reloads "just work" on multi-homed hosts (en0 + utun tailscale +
61
+ * docker0 etc.) — the mobile app races them in parallel via
62
+ * Promise.any.
63
+ */
64
+ export declare function buildProbeCandidates(target: CoreDevice, defaultHttpPort?: number): string[];
65
+ export interface ProbeResult {
66
+ url: string;
67
+ hostname?: string;
68
+ version?: string;
69
+ latency?: number;
70
+ }
71
+ /**
72
+ * Race `/health` probes across N URLs. First 200 wins; everything else
73
+ * is abandoned. Older Hermes doesn't have Promise.any, so we hand-roll
74
+ * the same semantic.
75
+ */
76
+ export declare function raceHealthProbes(urls: string[], opts?: {
77
+ timeoutMs?: number;
78
+ headers?: Record<string, string>;
79
+ }): Promise<ProbeResult | null>;
@@ -0,0 +1,310 @@
1
+ "use strict";
2
+ // AUTO-SYNCED from shared/client-core/src/device.ts.
3
+ // DO NOT EDIT IN PLACE. Edit the source and re-run
4
+ // scripts/sync-client-core.sh. CI checks drift via `--check`.
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.deviceIdentityKey = deviceIdentityKey;
7
+ exports.deviceAliasKey = deviceAliasKey;
8
+ exports.deviceEndpointKey = deviceEndpointKey;
9
+ exports.mergeDeviceEntries = mergeDeviceEntries;
10
+ exports.collapseDevices = collapseDevices;
11
+ exports.isDeviceFresh = isDeviceFresh;
12
+ exports.pickTargetDevice = pickTargetDevice;
13
+ exports.buildProbeCandidates = buildProbeCandidates;
14
+ exports.raceHealthProbes = raceHealthProbes;
15
+ /**
16
+ * Device dedup, merging, freshness, and target-picking.
17
+ *
18
+ * Phase-2 extract of the Yaver-mobile logic that lives at
19
+ * mobile/src/context/DeviceContext.tsx:193-413. Ported faithfully —
20
+ * mobile's collapseAliasDevices has been battle-tested through
21
+ * multiple Convex schema changes and the re-pair edge cases; this
22
+ * file is byte-identical in behaviour, only renamed for the shared
23
+ * RemoteDevice shape. The Feedback SDK used to carry its own copy
24
+ * (sdk/feedback/react-native/src/deviceDedup.ts) that drifted on
25
+ * `hwid` strong-identity and `runners`/`local` field preservation.
26
+ *
27
+ * Canonical device shape shared across every surface:
28
+ * - Mobile app: mobile/src/context/DeviceContext.tsx::Device (adapts
29
+ * into this shape at the Convex /devices/list fetch
30
+ * site).
31
+ * - Feedback SDK: src/auth.ts::RemoteDevice re-exports this type.
32
+ * - Web / Desktop: same.
33
+ *
34
+ * The mobile app may have extra view-model fields it wants to keep on
35
+ * its own Device interface (edgeProfile, sessionBinding, etc.) — those
36
+ * stay as local extensions; the core operates only on the fields
37
+ * declared here.
38
+ */
39
+ const constants_1 = require("./constants");
40
+ // ── Normalisers ───────────────────────────────────────────────────────
41
+ function normName(name) {
42
+ return String(name || '').trim().toLowerCase().replace(/\.local$/i, '');
43
+ }
44
+ function normHost(host) {
45
+ return String(host || '').trim().toLowerCase().replace(/\.local$/i, '');
46
+ }
47
+ // ── Keys ──────────────────────────────────────────────────────────────
48
+ function deviceIdentityKey(d) {
49
+ if (d.hwid)
50
+ return `hwid:${d.hwid}`;
51
+ if (d.publicKey)
52
+ return `pub:${d.publicKey}`;
53
+ if (d.isGuest) {
54
+ const scope = d.hostEmail || d.hostName || 'guest';
55
+ return `guest:${scope}:${d.deviceId || d.name}`;
56
+ }
57
+ const n = normName(d.name);
58
+ const os = String(d.platform || '').trim().toLowerCase();
59
+ if (n && os)
60
+ return `host:${os}:${n}`;
61
+ if (d.deviceId)
62
+ return `id:${d.deviceId}`;
63
+ return `name:${d.name}`;
64
+ }
65
+ function deviceAliasKey(d) {
66
+ if (d.isGuest)
67
+ return null;
68
+ const n = normName(d.name);
69
+ const os = String(d.platform || '').trim().toLowerCase();
70
+ if (!n || !os)
71
+ return null;
72
+ return `${os}:${n}`;
73
+ }
74
+ function deviceEndpointKey(d) {
75
+ if (d.isGuest)
76
+ return null;
77
+ const h = normHost(d.quicHost);
78
+ if (!h)
79
+ return null;
80
+ return `${h}:${d.quicPort || 0}`;
81
+ }
82
+ // ── Merge rules ───────────────────────────────────────────────────────
83
+ function mergeDeviceEntries(a, b) {
84
+ const incomingWins = (!!a.needsAuth && !b.needsAuth) ||
85
+ (b.lastHeartbeat || 0) > (a.lastHeartbeat || 0) ||
86
+ (!!b.isOnline && !a.isOnline);
87
+ const base = incomingWins ? b : a;
88
+ const other = incomingWins ? a : b;
89
+ return {
90
+ ...other,
91
+ ...base,
92
+ quicHost: base.quicHost || other.quicHost,
93
+ quicPort: base.quicPort || other.quicPort,
94
+ httpPort: base.httpPort || other.httpPort,
95
+ isOnline: base.isOnline || other.isOnline,
96
+ runnerDown: base.runnerDown && other.runnerDown,
97
+ publicKey: base.publicKey || other.publicKey,
98
+ hwid: base.hwid || other.hwid,
99
+ lastHeartbeat: Math.max(a.lastHeartbeat || 0, b.lastHeartbeat || 0),
100
+ localIps: (() => {
101
+ const set = new Set();
102
+ for (const ip of a.localIps || [])
103
+ if (ip)
104
+ set.add(ip);
105
+ for (const ip of b.localIps || [])
106
+ if (ip)
107
+ set.add(ip);
108
+ return set.size > 0 ? [...set] : undefined;
109
+ })(),
110
+ };
111
+ }
112
+ // When two rows share the same alias (hostname + OS) but differ on
113
+ // hwid / publicKey, prefer the authenticated + online row over a
114
+ // stale "needsAuth + offline" leftover. That leftover pattern is
115
+ // what re-pair / wipe-and-reinstall produces on Convex.
116
+ function pickActiveOverStaleNeedsAuth(a, b) {
117
+ const aDead = a.needsAuth && !a.isOnline;
118
+ const bDead = b.needsAuth && !b.isOnline;
119
+ const aLive = !a.needsAuth && a.isOnline;
120
+ const bLive = !b.needsAuth && b.isOnline;
121
+ if (aDead && bLive)
122
+ return b;
123
+ if (bDead && aLive)
124
+ return a;
125
+ return null;
126
+ }
127
+ // ── Collapse (three-pass dedup) ───────────────────────────────────────
128
+ /**
129
+ * Collapse duplicate Convex rows so each physical machine appears
130
+ * exactly once. Three passes — identity key → alias key → endpoint key.
131
+ * Safe on empty lists; idempotent on already-deduped input.
132
+ */
133
+ function collapseDevices(devices) {
134
+ if (!Array.isArray(devices) || devices.length === 0)
135
+ return [];
136
+ // Pass 1: identity key (hwid / publicKey / name+os).
137
+ const byIdentity = new Map();
138
+ for (const d of devices) {
139
+ const k = deviceIdentityKey(d);
140
+ const prev = byIdentity.get(k);
141
+ byIdentity.set(k, prev ? mergeDeviceEntries(prev, d) : d);
142
+ }
143
+ // Pass 2: alias key (os + normalised hostname), with strong-identity
144
+ // conflict resolution so two genuinely-different machines sharing a
145
+ // hostname don't silently merge.
146
+ const byAlias = new Map();
147
+ for (const d of byIdentity.values()) {
148
+ const k = deviceAliasKey(d);
149
+ if (!k) {
150
+ byAlias.set(`id:${d.deviceId}`, d);
151
+ continue;
152
+ }
153
+ const prev = byAlias.get(k);
154
+ if (!prev) {
155
+ byAlias.set(k, d);
156
+ continue;
157
+ }
158
+ const strongConflict = (!!prev.hwid && !!d.hwid && prev.hwid !== d.hwid) ||
159
+ (!!prev.publicKey && !!d.publicKey && prev.publicKey !== d.publicKey);
160
+ if (strongConflict) {
161
+ const winner = pickActiveOverStaleNeedsAuth(prev, d);
162
+ if (winner) {
163
+ byAlias.set(k, winner);
164
+ continue;
165
+ }
166
+ }
167
+ byAlias.set(k, mergeDeviceEntries(prev, d));
168
+ }
169
+ // Pass 3: endpoint key (host:port) — last-chance dedup for rows
170
+ // that share a LAN address but slipped through identity + alias.
171
+ const byEndpoint = new Map();
172
+ for (const d of byAlias.values()) {
173
+ const k = deviceEndpointKey(d);
174
+ if (!k) {
175
+ byEndpoint.set(`id:${d.deviceId}`, d);
176
+ continue;
177
+ }
178
+ const prev = byEndpoint.get(k);
179
+ byEndpoint.set(k, prev ? mergeDeviceEntries(prev, d) : d);
180
+ }
181
+ return [...byEndpoint.values()];
182
+ }
183
+ // ── Freshness + target pick ───────────────────────────────────────────
184
+ /**
185
+ * "Fresh" matches the mobile app: online + heartbeat < 90 s. Clients
186
+ * read Convex's `isOnline` first (backend already applies its own 90 s
187
+ * gate from the server clock), then use this helper when they need the
188
+ * phone-side freshness opinion too — e.g. for auto-connect picks.
189
+ */
190
+ function isDeviceFresh(d, now = Date.now()) {
191
+ if (!d.isOnline)
192
+ return false;
193
+ if (!d.lastHeartbeat)
194
+ return true;
195
+ return now - d.lastHeartbeat < constants_1.HEARTBEAT_STALE_MS;
196
+ }
197
+ /**
198
+ * Choose the best candidate for an auto-connect attempt. Preference:
199
+ * 1. explicit `preferredDeviceId` that's still fresh
200
+ * 2. fresh (online + recent heartbeat) + has a quicHost
201
+ * 3. online + has a quicHost
202
+ * 4. first with a quicHost
203
+ */
204
+ function pickTargetDevice(devices, preferredDeviceId) {
205
+ if (!devices.length)
206
+ return null;
207
+ if (preferredDeviceId) {
208
+ const preferred = devices.find((d) => d.deviceId === preferredDeviceId && d.quicHost);
209
+ if (preferred && isDeviceFresh(preferred))
210
+ return preferred;
211
+ if (preferred)
212
+ return preferred;
213
+ }
214
+ const fresh = devices.find((d) => isDeviceFresh(d) && d.quicHost);
215
+ if (fresh)
216
+ return fresh;
217
+ const online = devices.find((d) => d.isOnline && d.quicHost);
218
+ if (online)
219
+ return online;
220
+ return devices.find((d) => d.quicHost) || devices[0] || null;
221
+ }
222
+ // ── Probe candidate assembly ──────────────────────────────────────────
223
+ /**
224
+ * Build the set of `/health` candidate URLs for a target device —
225
+ * `quicHost` plus every LAN IP the agent reported in `localIps`,
226
+ * uniqued and formatted. This is the thing that makes direct LAN
227
+ * reloads "just work" on multi-homed hosts (en0 + utun tailscale +
228
+ * docker0 etc.) — the mobile app races them in parallel via
229
+ * Promise.any.
230
+ */
231
+ function buildProbeCandidates(target, defaultHttpPort = 18080) {
232
+ const port = target.httpPort ?? target.quicPort ?? defaultHttpPort;
233
+ const ips = new Set();
234
+ if (target.quicHost)
235
+ ips.add(target.quicHost);
236
+ for (const ip of target.localIps ?? []) {
237
+ if (ip)
238
+ ips.add(ip);
239
+ }
240
+ return [...ips].map((ip) => `http://${ip}:${port}`);
241
+ }
242
+ /**
243
+ * Race `/health` probes across N URLs. First 200 wins; everything else
244
+ * is abandoned. Older Hermes doesn't have Promise.any, so we hand-roll
245
+ * the same semantic.
246
+ */
247
+ async function raceHealthProbes(urls, opts = {}) {
248
+ if (!urls || urls.length === 0)
249
+ return null;
250
+ const timeoutMs = opts.timeoutMs ?? 2500;
251
+ const probeOne = async (url) => {
252
+ const base = url.replace(/\/$/, '');
253
+ const start = Date.now();
254
+ try {
255
+ const controller = new AbortController();
256
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
257
+ const res = await fetch(`${base}/health`, {
258
+ method: 'GET',
259
+ headers: opts.headers,
260
+ signal: controller.signal,
261
+ });
262
+ clearTimeout(timer);
263
+ if (!res.ok)
264
+ return null;
265
+ const latency = Date.now() - start;
266
+ let hostname;
267
+ let version;
268
+ try {
269
+ const data = await res.json();
270
+ hostname = data?.hostname ?? data?.name;
271
+ version = data?.version;
272
+ }
273
+ catch {
274
+ // /health may return plain text
275
+ }
276
+ return { url: base, hostname, version, latency };
277
+ }
278
+ catch {
279
+ return null;
280
+ }
281
+ };
282
+ return new Promise((resolve) => {
283
+ let remaining = urls.length;
284
+ let settled = false;
285
+ for (const url of urls) {
286
+ probeOne(url)
287
+ .then((r) => {
288
+ if (settled)
289
+ return;
290
+ if (r) {
291
+ settled = true;
292
+ resolve(r);
293
+ return;
294
+ }
295
+ remaining -= 1;
296
+ if (remaining <= 0 && !settled) {
297
+ settled = true;
298
+ resolve(null);
299
+ }
300
+ })
301
+ .catch(() => {
302
+ remaining -= 1;
303
+ if (remaining <= 0 && !settled) {
304
+ settled = true;
305
+ resolve(null);
306
+ }
307
+ });
308
+ }
309
+ });
310
+ }
@@ -12,3 +12,4 @@
12
12
  */
13
13
  export * from './constants';
14
14
  export * from './endpoints';
15
+ export * from './device';
@@ -31,3 +31,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
31
31
  */
32
32
  __exportStar(require("./constants"), exports);
33
33
  __exportStar(require("./endpoints"), exports);
34
+ __exportStar(require("./device"), exports);
@@ -1,45 +1,21 @@
1
1
  /**
2
- * Device deduplication + online-signal merging, ported from the Yaver
3
- * mobile app's DeviceContext.collapseAliasDevices.
2
+ * Re-export the canonical dedup / freshness / race-probe helpers from
3
+ * @yaver/client-core (mirrored into `./_core/`).
4
4
  *
5
- * Convex stores one row per pair (device, re-install). After a re-pair
6
- * or hostname change the list can contain 2-3 rows for the same
7
- * physical machine, with different hwid/publicKey values. The picker
8
- * then shows duplicates and the user can't tell which one is live.
5
+ * The SDK previously carried its own ~180-line copy of
6
+ * `collapseAliasDevices` ported by hand from mobile's
7
+ * DeviceContext.tsx. The copies drifted on `hwid` strong-identity,
8
+ * `runners` / `local` field preservation, and a few other subtle
9
+ * merge rules. Canonicalising via client-core eliminates that drift
10
+ * class — mobile's test case automatically covers the SDK's dedup
11
+ * behaviour too.
9
12
  *
10
- * This file collapses rows in three passes:
11
- * 1. Identity key (hwid publicKey "host:os:name" → id → name)
12
- * 2. Alias key (os + normalized-hostname) catches re-pairs that
13
- * mint a new hwid
14
- * 3. Endpoint key (host:port)
15
- *
16
- * When collapsing, `mergeDeviceEntries` prefers: authenticated over
17
- * needsAuth, online over offline, freshest lastHeartbeat.
13
+ * The shared module operates on a `CoreDevice` shape. The SDK's
14
+ * `RemoteDevice` is structurally compatible (same field names, same
15
+ * types), so the casts here are a no-op at runtime.
18
16
  */
19
17
  import type { RemoteDevice } from './auth';
20
- /**
21
- * Collapse a Convex device list so each physical machine appears once.
22
- * Safe on an empty list; idempotent on an already-deduped list.
23
- */
18
+ export { HEARTBEAT_STALE_MS } from './_core/constants';
24
19
  export declare function collapseRemoteDevices(devices: RemoteDevice[]): RemoteDevice[];
25
- /**
26
- * Threshold for "online" based on heartbeat age, in milliseconds.
27
- * Re-exported from `@yaver/client-core` so mobile + SDK + backend
28
- * agree on one number at all times.
29
- */
30
- import { HEARTBEAT_STALE_MS } from './_core/constants';
31
- export { HEARTBEAT_STALE_MS };
32
- /**
33
- * Returns a freshness flag consistent with the mobile app. A device is
34
- * "fresh" when it was online per Convex AND its heartbeat is within
35
- * `HEARTBEAT_STALE_MS`.
36
- */
37
20
  export declare function isDeviceFresh(d: RemoteDevice): boolean;
38
- /**
39
- * Pick the best candidate for an auto-connect attempt. Preference:
40
- * 1. matches the preferred deviceId when supplied + still fresh
41
- * 2. fresh (online + recent heartbeat) + has a quicHost
42
- * 3. online + has a quicHost
43
- * 4. first with a quicHost
44
- */
45
21
  export declare function pickTargetDevice(devices: RemoteDevice[], preferredDeviceId?: string): RemoteDevice | null;