openrtc 1.0.6 → 1.0.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.
@@ -1,937 +0,0 @@
1
- interface AppLimits {
2
- /** Max devices per authenticated user. -1 = unlimited. */
3
- devicesPerUser: number;
4
- /** Max total rooms the developer app can have open at once. -1 = unlimited. */
5
- maxRooms: number;
6
- /** Max members per room. -1 = unlimited. */
7
- maxMembersPerRoom: number;
8
- /** Max active devices across all provisioned spaces for this app. -1 = unlimited. */
9
- maxPersonalDevices: number;
10
- }
11
- interface PlutoRTCConfiguration extends RTCConfiguration {
12
- iceServers?: RTCIceServer[];
13
- /**
14
- * Populate public STUN defaults when no ICE servers are configured.
15
- * Set to false with `iceServers: []` for an intentional host-only lane.
16
- */
17
- useDefaultIceServers?: boolean;
18
- privacyMode?: boolean;
19
- useTurn?: boolean;
20
- /** Prefer host/srflx ICE candidates and upgrade aggressively on LAN. */
21
- lanMode?: boolean;
22
- }
23
- interface LocalPeerSnapshot {
24
- nodeId: string;
25
- discoveredAtMs: number;
26
- localReachable: boolean;
27
- }
28
- interface PlutoMoQServerCertificateHash {
29
- algorithm: 'sha-256';
30
- value: ArrayBuffer;
31
- }
32
- interface PlutoMoQConfiguration {
33
- relayUrl?: string;
34
- /** Relay JWT appended only at WebTransport connection time. Never include it in relayUrl. */
35
- accessToken?: string;
36
- /** Explicit certificate pins for self-signed development relays. */
37
- serverCertificateHashes?: PlutoMoQServerCertificateHash[];
38
- }
39
- interface PlutoIrohConfiguration {
40
- relayOnly?: boolean;
41
- relayTransportPolicy?: 'auto' | 'quicRequired' | 'websocketRequired';
42
- persistenceMode?: 'persistent' | 'ephemeral';
43
- /** Enable native iroh mDNS LAN discovery (native runtimes only). */
44
- localDiscovery?: boolean;
45
- /** When false, listen for LAN peers without advertising this endpoint. */
46
- localDiscoveryMode?: 'active' | 'passive';
47
- }
48
- interface PlutoBleConfiguration {
49
- /** Enable native BLE discovery + transport (native runtimes only). */
50
- enabled?: boolean;
51
- /** Timeout for a single BLE connection attempt. */
52
- connectTimeoutMs?: number;
53
- }
54
- interface TurnCredentials {
55
- iceServers?: RTCIceServer[];
56
- }
57
- type TurnCredentialsProvider = () => Promise<TurnCredentials | null | undefined>;
58
- type DiscoveryMode = 'space' | 'user-scoped';
59
- type AuthMode = 'external' | 'anonymous' | 'required';
60
- type SignalingMode = 'hosted' | 'ticket-only';
61
- type RoomCreationMode = 'client-open' | 'client-auth' | 'server-only';
62
- type EndpointKind = 'device' | 'ephemeral';
63
- type PeerLifecycleStatus = 'disconnected' | 'connecting' | 'connected' | 'failed' | 'closed';
64
- type PeerHealth = 'unknown' | 'healthy' | 'suspect' | 'stale';
65
- type DevicePresenceStatus = 'online' | 'idle' | 'offline';
66
- type PeerLifecycleStage = 'discovered' | 'dialing' | 'base-connected' | 'admitted' | 'protocol-ready' | 'upgrading' | 'webrtc-ready' | 'degraded' | 'reconnecting' | 'closed';
67
- type PeerBaseTransportState = 'unknown' | 'connecting' | 'connected' | 'degraded' | 'closed';
68
- type PeerAdmissionState = 'unknown' | 'pending' | 'admitted' | 'rejected' | 'expired';
69
- type PeerWebRtcState = 'unknown' | 'disabled' | 'connecting' | 'transport-open' | 'route-probing' | 'ready' | 'failed' | 'closed';
70
- /**
71
- * Lifecycle label attached to a projected peer while the runtime tracks local ownership.
72
- *
73
- * This is not an admission grant. Use `GrantScope` for ticket/token authorization labels
74
- * such as `"share"`, `"friend"`, or `"user-device"`.
75
- */
76
- type PeerScope = 'persistent' | 'session' | string;
77
- /**
78
- * Admission-grant label embedded in restricted compound tickets and session tokens.
79
- *
80
- * `GrantScope` controls authorization and bulk revoke behavior in the Rust admission layer.
81
- * It is distinct from `PeerScope`, which only labels local peer lifecycle ownership.
82
- */
83
- type GrantScope = string;
84
- type ChannelOwnership = 'shared' | 'exclusive';
85
- type ChannelPeerModel = 'device-first' | 'node-first' | 'anonymous-ticket';
86
- type ChannelRoutingMode = 'stream-envelope' | 'session-default';
87
- type ChannelReadinessMode = 'settled-peer' | 'transport-only';
88
- type ChannelPromotionPolicy = 'eligible' | 'never';
89
- type ChannelSignalingPolicy = 'hosted' | 'ticket-only';
90
- interface ChannelDescriptor {
91
- id: string;
92
- kind: 'system' | 'auth' | 'share' | 'transfer' | 'sync' | string;
93
- ownership: ChannelOwnership;
94
- peerModel: ChannelPeerModel;
95
- routing: ChannelRoutingMode;
96
- readiness: ChannelReadinessMode;
97
- promotionPolicy?: ChannelPromotionPolicy;
98
- signalingPolicy?: ChannelSignalingPolicy;
99
- description?: string;
100
- }
101
- type ProtocolName = 'iroh' | 'iroh-quic' | 'iroh-relay' | 'iroh-lan' | 'ble' | 'webrtc' | 'webrtc-lan' | 'webrtc-turn' | 'moq';
102
- type ProtocolMaturity = 'stable' | 'experimental' | 'unsupported';
103
- type ProtocolBaseName = 'iroh' | 'webrtc' | 'moq';
104
- type RouteFamily = 'iroh-path' | 'iroh-physical' | 'optional-route';
105
- type RouteImplementationKind = 'core' | 'host-installed' | 'route-adapter' | 'path-label';
106
- /**
107
- * Public compatibility type. `native` and `plugin` are legacy capability
108
- * labels; generated route descriptors use `RouteImplementationKind`.
109
- */
110
- type ProtocolImplementationKind = RouteImplementationKind | 'native' | 'plugin';
111
- type ProtocolLocality = 'nearby' | 'direct-internet' | 'relay' | 'mixed';
112
- interface RouteDescriptor {
113
- id: ProtocolName;
114
- baseProtocol: ProtocolBaseName;
115
- family: RouteFamily;
116
- implementation: RouteImplementationKind;
117
- locality: ProtocolLocality;
118
- maturity: ProtocolMaturity;
119
- defaultRank: number;
120
- browser: boolean;
121
- native: boolean;
122
- independentlyInstantiable: boolean;
123
- }
124
- interface ProtocolCapability {
125
- /** Canonical descriptor id; additive to the legacy capability shape. */
126
- id?: ProtocolName;
127
- /** Compatibility alias for `id`. */
128
- protocol: ProtocolName;
129
- baseProtocol: ProtocolBaseName;
130
- /** Canonical route family; additive to the legacy capability shape. */
131
- family?: RouteFamily;
132
- implementation: ProtocolImplementationKind;
133
- locality: ProtocolLocality;
134
- maturity: ProtocolMaturity;
135
- /** Canonical descriptor rank; additive to the legacy capability shape. */
136
- defaultRank?: number;
137
- /** Canonical implementation taxonomy; `implementation` retains legacy values. */
138
- routeImplementation?: RouteImplementationKind;
139
- /** Compatibility alias for `defaultRank`. */
140
- preferredRank: number;
141
- browser: boolean;
142
- native: boolean;
143
- /** Canonical descriptor flag; additive to the legacy capability shape. */
144
- independentlyInstantiable?: boolean;
145
- configured?: boolean;
146
- available: boolean;
147
- reason?: string;
148
- }
149
- type ProtocolCapabilityMap = Record<ProtocolName, ProtocolCapability>;
150
- /** Space discovery always uses namespace-scoped Firebase tokens. */
151
- type SpaceAuthMode = 'scoped-token';
152
- type SpaceTokenProvider = () => Promise<{
153
- customToken: string;
154
- uid?: string;
155
- } | null | undefined>;
156
- interface ClientOptions {
157
- /**
158
- * API key issued from the Pluto developer dashboard (https://api.openrtc.app/developer).
159
- * The runtime derives its app namespace from this key.
160
- */
161
- apiKey?: string;
162
- /**
163
- * Discovery avenue for this runtime.
164
- *
165
- * Set this explicitly in new apps:
166
- * - `space`: a small live shared namespace backed by scoped space tokens.
167
- * - `user-scoped`: a signed-in user's durable owned-device roster.
168
- *
169
- * Rooms and ticket/share grants are separate layers. Do not use `space`
170
- * as a generic account device list, and do not expect `user-scoped`
171
- * discovery to show other users unless a room or explicit grant connects them.
172
- */
173
- discoveryMode?: DiscoveryMode;
174
- /**
175
- * Shared space name for `space` discovery mode. Use this for lightweight
176
- * lobbies, demos, cursors, and other live-only collaboration surfaces.
177
- * This is the beginner-facing name for `spaceKey`; if both are set,
178
- * `spaceKey` wins.
179
- */
180
- space?: string;
181
- /**
182
- * Compatibility name for `space`. The SDK derives a namespace from
183
- * apiKey + spaceKey, then authenticates with spaceTokenProvider.
184
- *
185
- * Prefer `space` in public app code. Only used when discoveryMode is
186
- * `space`; ignored for user-scoped discovery.
187
- */
188
- spaceKey?: string;
189
- /**
190
- * Pre-minted session token from your backend (for managed modes).
191
- * Your backend calls PlutoRTC's /v1/tokens endpoint and passes the token here.
192
- */
193
- sessionToken?: string;
194
- authMode?: AuthMode;
195
- /**
196
- * Allows first-party demos to use hosted defaults when an API key is omitted.
197
- * Product apps should pass an API key.
198
- */
199
- allowAnonymousHostedDefaults?: boolean;
200
- signalingMode?: SignalingMode;
201
- projectId?: string;
202
- storagePrefix?: string;
203
- deviceTTL?: number;
204
- deviceName?: string;
205
- /**
206
- * Persistence of the app-facing logical device identity. Defaults to
207
- * `persistent` in browsers so a reload updates one durable device record.
208
- */
209
- deviceIdPersistence?: 'persistent' | 'ephemeral';
210
- /**
211
- * Persistence of the Iroh endpoint secret/EndpointId. Browser runtimes
212
- * default to `ephemeral` so each tab/process incarnation has an unambiguous
213
- * transport identity. Native hosts may persist their endpoint explicitly.
214
- */
215
- endpointIdPersistence?: 'persistent' | 'ephemeral';
216
- /**
217
- * @deprecated Use `deviceIdPersistence` and `endpointIdPersistence`.
218
- * When supplied, this legacy option remains an explicit override for both.
219
- */
220
- nodeIdPersistence?: 'persistent' | 'ephemeral';
221
- secretKey?: string;
222
- strictMode?: boolean;
223
- /**
224
- * Optional application-provided TURN credential loader.
225
- *
226
- * OpenRTC never needs long-lived TURN secrets in the client. When strict/privacy
227
- * WebRTC needs relay candidates, provide a backend-backed loader that returns
228
- * short-lived RTCIceServer entries. Leave unset for the production default of
229
- * no paid TURN usage.
230
- */
231
- turnCredentialsProvider?: TurnCredentialsProvider;
232
- localDeviceId?: string;
233
- onDevices?: (devices: Device[]) => void;
234
- onAutoConnect?: (devices: Device[]) => void;
235
- onIncomingSession?: (session: SignalingSession) => Promise<void>;
236
- transports?: {
237
- iroh?: boolean | PlutoIrohConfiguration;
238
- webrtc?: boolean | PlutoRTCConfiguration;
239
- ble?: boolean | PlutoBleConfiguration;
240
- moq?: boolean | PlutoMoQConfiguration;
241
- };
242
- transportPriority?: ProtocolName[];
243
- /** Subscribe to native LAN peer discovery events. */
244
- onLocalPeer?: (peer: LocalPeerSnapshot) => void;
245
- disableIrohFallback?: boolean;
246
- /**
247
- * Optional application-layer payload envelope. When configured, OpenRTC
248
- * protects public message/media payload bytes before they are handed to
249
- * iroh, WebRTC, or MoQ and opens them before app callbacks fire.
250
- */
251
- applicationCrypto?: ApplicationPayloadCrypto;
252
- /**
253
- * When manual `applicationCrypto` is not set, peers must negotiate an
254
- * ephemeral X25519 ECDH key during transport handshake. Disabling is not
255
- * supported in secure deployments.
256
- */
257
- automaticApplicationKeyAgreement?: boolean;
258
- /**
259
- * @internal Overrides orphan drift grace windows for tests and diagnostics.
260
- */
261
- orphanReconciliationGrace?: {
262
- tsConnectionMs?: number;
263
- rustRecordMs?: number;
264
- };
265
- /**
266
- * Mints a namespace-scoped Firebase custom token for space discovery.
267
- * Required when `discoveryMode` is `space` and `space`/`spaceKey` is set.
268
- * Use `spaceToken(...)` for browser demos and simple static sites.
269
- */
270
- spaceTokenProvider?: SpaceTokenProvider;
271
- }
272
- interface Device {
273
- deviceId: string;
274
- deviceName: string;
275
- online: boolean;
276
- ticket: string;
277
- presenceStatus?: DevicePresenceStatus;
278
- presenceUpdatedAt?: number;
279
- presenceExpiresAt?: number;
280
- connectable?: boolean;
281
- kind?: EndpointKind | string;
282
- nodeId?: string;
283
- platformType?: string;
284
- capabilities?: {
285
- canHost?: boolean;
286
- canSync?: boolean;
287
- readOnly?: boolean;
288
- can_host?: boolean;
289
- can_sync?: boolean;
290
- read_only?: boolean;
291
- };
292
- sessionId?: string;
293
- userId?: string;
294
- lastSeenAt?: any;
295
- expiresAt?: any;
296
- createdAt?: any;
297
- updatedAt?: any;
298
- metadata?: string;
299
- excludedPeers?: string[];
300
- availableTransports?: ProtocolName[];
301
- transports?: ProtocolName[];
302
- }
303
- interface PeerState {
304
- peerId: string;
305
- deviceId?: string;
306
- deviceIdHint?: string;
307
- nodeId?: string;
308
- connectionId?: string;
309
- connectionIds: string[];
310
- ticket?: string;
311
- online?: boolean;
312
- deviceName?: string;
313
- platformType?: string;
314
- status: PeerLifecycleStatus;
315
- health: PeerHealth;
316
- lifecycleStage?: PeerLifecycleStage;
317
- generation?: number;
318
- baseTransportState?: PeerBaseTransportState;
319
- admissionState?: PeerAdmissionState;
320
- transportState?: string;
321
- protocolState?: string;
322
- webrtcState?: PeerWebRtcState;
323
- routable?: boolean;
324
- activeTransportStableId?: number | null;
325
- transportGeneration?: number;
326
- routeGeneration?: number;
327
- activeTransport?: ProtocolName;
328
- fallbackTransport?: ProtocolName | null;
329
- parallelTransport?: ProtocolName | null;
330
- manualDisconnect?: boolean;
331
- lastAuthoritativeEventAt?: number;
332
- lastTransientEventAt?: number;
333
- promotionEligible?: boolean;
334
- scopes: PeerScope[];
335
- lastSeenAt?: number;
336
- error?: string;
337
- }
338
- interface BackendConnectionState {
339
- connectionId: string;
340
- deviceId?: string | null;
341
- deviceIdHint?: string | null;
342
- remoteNodeId?: string | null;
343
- state: string;
344
- transportState?: string;
345
- protocolState?: string;
346
- routable?: boolean;
347
- activeTransport?: ProtocolName;
348
- parallelTransport?: ProtocolName | null;
349
- readinessState?: string;
350
- readinessReason?: string;
351
- transportGeneration?: number;
352
- routeGeneration?: number;
353
- activeTransportStableId?: number | null;
354
- replacementInProgress?: boolean;
355
- lastLifecycleTransitionAtMs?: number;
356
- transitionCount?: number;
357
- connectingTransitionCount?: number;
358
- replacementCount?: number;
359
- retireCount?: number;
360
- lastDisconnectReason?: string | null;
361
- lastReconnectReason?: string | null;
362
- error?: string;
363
- createdAt?: number;
364
- updatedAt?: number;
365
- }
366
- interface NativeConnectResult {
367
- connectionId: string;
368
- deviceId?: string | null;
369
- deviceIdHint?: string | null;
370
- remoteNodeId?: string | null;
371
- state: string;
372
- approvedScope?: string | null;
373
- }
374
- interface NativeConnectParams {
375
- deviceId?: string | null;
376
- endpointTicket: string;
377
- /** Total native dial/admission budget. The host command must enforce it. */
378
- timeoutMs?: number;
379
- }
380
- interface BackendPeerBiStream {
381
- readable: ReadableStream<Uint8Array>;
382
- writable: WritableStream<Uint8Array>;
383
- }
384
- interface BackendPeerUniStream {
385
- writable: WritableStream<Uint8Array>;
386
- }
387
- interface IncomingStreamChannelMetadata {
388
- channelId: string;
389
- metadata?: Record<string, unknown> | null;
390
- }
391
- interface LocalDeviceInfo {
392
- deviceId: string;
393
- deviceName: string;
394
- platformType?: string;
395
- capabilities?: Device['capabilities'];
396
- lastSeenAt?: string;
397
- }
398
- interface NativeManagedSessionStartResult {
399
- localNodeId: string | null;
400
- ticket?: string | null;
401
- ticketScope?: string | null;
402
- presenceStarted: boolean;
403
- autoConnectStarted: boolean;
404
- localDevice?: LocalDeviceInfo | null;
405
- }
406
- interface RoomMember {
407
- nodeId: string;
408
- userId: string;
409
- ticket: string;
410
- joinedAt: number;
411
- lastSeenAt: number;
412
- expiresAt?: number;
413
- }
414
- interface JoinRoomOptions {
415
- bootstrapPeers?: boolean;
416
- }
417
- interface SignalingEnvelope {
418
- name?: string;
419
- appTag?: string;
420
- senderId: string;
421
- targetId: string;
422
- senderUserId?: string;
423
- targetUserId?: string;
424
- state?: string;
425
- payload: string;
426
- replyPayload?: string;
427
- timestamp?: number;
428
- expiresAt?: number;
429
- }
430
- interface SignalingSession {
431
- connectionId: string;
432
- initiator?: string;
433
- target?: string;
434
- initiatorDeviceId: string;
435
- targetDeviceId: string;
436
- connectionType?: string;
437
- offer?: any;
438
- offerE2ee?: any;
439
- answer?: any;
440
- answerE2ee?: any;
441
- iceCandidates: any[];
442
- initiatorNodeId?: string;
443
- targetNodeId?: string;
444
- initiatorEndpointAddr?: string;
445
- targetEndpointAddr?: string;
446
- intent?: string;
447
- /**
448
- * @deprecated Internal namespace metadata. Public integrations should not depend on `appTag`.
449
- * Removal target: v0.2.0.
450
- */
451
- appTag?: string;
452
- createdAt?: number;
453
- expiresAt?: number;
454
- state: string;
455
- }
456
- interface ScanningLoopOptions {
457
- localDeviceId: string;
458
- autoConnect?: boolean;
459
- autoConnectDebounceMs?: number;
460
- retryThrottleMs?: number;
461
- tieBreaker?: (localDeviceId: string, remoteDeviceId: string) => boolean;
462
- shouldSkipDevice?: (device: Device) => boolean;
463
- isConnected?: (deviceId: string) => boolean;
464
- isConnecting?: (deviceId: string) => boolean;
465
- onDevices?: (devices: Device[]) => void;
466
- onAutoConnect?: (device: Device) => Promise<void> | void;
467
- onIncomingSession?: (session: SignalingSession) => Promise<void> | void;
468
- hasProtectedConnectionIntent?: (deviceId: string) => boolean;
469
- cleanupStaleConnection?: (deviceId: string) => Promise<void>;
470
- allowIncomingNodeId?: (nodeId: string) => Promise<void>;
471
- acceptIncomingSession?: (sessionId: string, initiatorDeviceId: string) => Promise<{
472
- success: boolean;
473
- error?: string;
474
- }>;
475
- onIncomingSessionAccepted?: (session: SignalingSession) => Promise<void> | void;
476
- }
477
- interface ScanningLoopHandle {
478
- stop: () => void;
479
- }
480
- interface ConnectDeviceHooks {
481
- getConnectionState?: (deviceId: string) => Promise<string | undefined> | string | undefined;
482
- forceDisconnect?: (deviceId: string) => Promise<void>;
483
- refreshState?: () => Promise<void>;
484
- directConnect: (device: Device) => Promise<void>;
485
- signalConnect: (params: {
486
- localDeviceId: string;
487
- targetDeviceId: string;
488
- targetUserId?: string;
489
- device: Device;
490
- }) => Promise<{
491
- success: boolean;
492
- error?: string;
493
- }>;
494
- onConnected?: (device: Device) => Promise<void> | void;
495
- onRetry?: (device: Device, attempt: number, delayMs: number) => void;
496
- }
497
- interface ConnectDeviceOptions {
498
- localDeviceId: string;
499
- targetUserId?: string;
500
- maxRetries?: number;
501
- initialBackoffMs?: number;
502
- }
503
- interface ConnectDeviceResult {
504
- success: boolean;
505
- skipped?: 'already-connecting' | 'missing-local-device-id';
506
- error?: string;
507
- attempts: number;
508
- }
509
- interface ManagedDeviceConnectOptions {
510
- localDeviceId: string;
511
- targetUserId?: string;
512
- maxRetries?: number;
513
- initialBackoffMs?: number;
514
- onRetry?: (device: Device, attempt: number, delayMs: number) => void;
515
- onConnected?: (device: Device) => void | Promise<void>;
516
- }
517
- interface DeviceStatusSnapshot extends Device {
518
- /**
519
- * Presence/liveness for the roster entry. This is separate from
520
- * `connectionStatus`, which describes the runtime route to the peer.
521
- */
522
- presenceStatus: DevicePresenceStatus;
523
- presenceUpdatedAt?: number;
524
- presenceExpiresAt?: number;
525
- connectable: boolean;
526
- connectionStatus: PeerLifecycleStatus | 'online';
527
- settledReady?: boolean;
528
- readinessState?: string;
529
- readinessReason?: string;
530
- peerHealth: PeerHealth;
531
- peerId?: string;
532
- promotionEligible?: boolean;
533
- scopes: PeerScope[];
534
- connectionId?: string;
535
- deviceIdHint?: string;
536
- activeTransportStableId?: number | null;
537
- transportGeneration?: number;
538
- routeGeneration?: number;
539
- activeTransport?: ProtocolName;
540
- parallelTransport?: ProtocolName | null;
541
- availableTransports?: ProtocolName[];
542
- /** Latest transport-owned RTT sample for the active route. */
543
- latencyMs?: number | null;
544
- /** Passive RTT samples keyed by the exact usable route label. */
545
- latencyByTransport?: TransportLatencySnapshot;
546
- }
547
- interface TransportLatencySnapshot {
548
- webrtc?: number | null;
549
- webrtcLan?: number | null;
550
- webrtcTurn?: number | null;
551
- iroh?: number | null;
552
- irohLan?: number | null;
553
- irohRelay?: number | null;
554
- ble?: number | null;
555
- moq?: number | null;
556
- }
557
- interface ManagedConnectionRecord {
558
- connectionId: string;
559
- nodeId?: string | null;
560
- deviceId?: string | null;
561
- deviceIdHint?: string | null;
562
- endpointId?: string | null;
563
- transportGeneration: number;
564
- routeGeneration?: number;
565
- transportStableId?: number | null;
566
- transportSource?: string | null;
567
- lastTransportChangeAtMs: number;
568
- lastRouteChangeAtMs?: number;
569
- state: string;
570
- statusReason?: string | null;
571
- transitionCount?: number;
572
- connectingTransitionCount?: number;
573
- replacementCount?: number;
574
- retireCount?: number;
575
- lastDisconnectReason?: string | null;
576
- lastReconnectReason?: string | null;
577
- createdAtMs: number;
578
- updatedAtMs: number;
579
- }
580
- interface ResolvedPeerIdentity {
581
- peerId?: string | null;
582
- deviceId?: string | null;
583
- deviceIdHint?: string | null;
584
- nodeId?: string | null;
585
- }
586
- interface PeerSessionSnapshot {
587
- peerId: string;
588
- deviceId?: string | null;
589
- deviceIdHint?: string | null;
590
- nodeId?: string | null;
591
- activeConnectionId?: string | null;
592
- candidateConnectionIds: string[];
593
- status: PeerLifecycleStatus;
594
- health: PeerHealth;
595
- settledReady?: boolean;
596
- readinessState?: string;
597
- activeTransportStableId?: number | null;
598
- transportGeneration?: number;
599
- routeGeneration?: number;
600
- activeTransport?: ProtocolName;
601
- parallelTransport?: ProtocolName | null;
602
- replacementPending?: boolean;
603
- lastLifecycleTransitionAtMs?: number;
604
- readinessReason?: string;
605
- transitionCount?: number;
606
- connectingTransitionCount?: number;
607
- replacementCount?: number;
608
- retireCount?: number;
609
- lastDisconnectReason?: string | null;
610
- lastReconnectReason?: string | null;
611
- scopes: PeerScope[];
612
- lastSeenAtMs: number;
613
- error?: string | null;
614
- }
615
- interface RuntimeBootstrapOptions {
616
- platform: 'native' | 'web';
617
- initializeWeb?: () => Promise<void>;
618
- isNativeReady?: () => Promise<boolean>;
619
- retryNativeInit?: () => Promise<void>;
620
- waitForNativeInitEvent?: (timeoutMs: number) => Promise<boolean>;
621
- quickPollAttempts?: number;
622
- quickPollIntervalMs?: number;
623
- retryPollAttempts?: number;
624
- retryPollIntervalMs?: number;
625
- nativeInitEventTimeoutMs?: number;
626
- initializeClient?: boolean;
627
- }
628
- interface RuntimeBootstrapResult {
629
- ready: boolean;
630
- mode: 'native' | 'web';
631
- }
632
- interface RuntimeIdentity {
633
- id: string;
634
- email?: string | null;
635
- displayName?: string | null;
636
- isAnonymous?: boolean;
637
- getToken?: (forceRefresh?: boolean) => Promise<string | null>;
638
- }
639
- type DeviceEvent = {
640
- type: 'added';
641
- device: Device;
642
- } | {
643
- type: 'modified';
644
- device: Device;
645
- } | {
646
- type: 'removed';
647
- deviceId: string;
648
- };
649
- type SessionEvent = {
650
- type: 'added';
651
- session: SignalingSession;
652
- } | {
653
- type: 'modified';
654
- session: SignalingSession;
655
- } | {
656
- type: 'removed';
657
- sessionId: string;
658
- };
659
- interface ExplicitFileDataSendParams {
660
- connectionId?: string;
661
- connection?: {
662
- send: (message: unknown) => Promise<void>;
663
- deviceId?: string;
664
- remoteNodeId?: string;
665
- requireApplicationCrypto?: boolean;
666
- getUpgradeState?: () => string;
667
- isWebRtcApplicationRouteReady?: () => boolean;
668
- sendOnWebRTC?: (data: Uint8Array) => Promise<void>;
669
- getWebRTCTransport?: () => {
670
- getBufferedAmount?: () => number;
671
- waitForDrain?: (lowWaterMark: number) => Promise<void>;
672
- } | null;
673
- };
674
- remoteNodeId?: string;
675
- file: File;
676
- transferId: string;
677
- channelId?: string;
678
- receiverPlatformType?: string | null;
679
- applicationCrypto?: ApplicationPayloadCrypto;
680
- requireApplicationCrypto?: boolean;
681
- }
682
- interface ISignalingBackend {
683
- currentUser: RuntimeIdentity | null;
684
- signInAnonymously(): Promise<void>;
685
- signInWithPluto?(): Promise<void>;
686
- signOut(): Promise<void>;
687
- stopAuthScopedActivity?(): Promise<void>;
688
- getTurnCredentials(): Promise<any>;
689
- updatePresence(localNodeId: string, ticketStr: string, isOnline: boolean, ttlMs: number, metadata?: string): Promise<void>;
690
- refreshLivePresence?(localNodeId: string, ticketStr: string, metadata?: string): Promise<void>;
691
- setOffline(localNodeId: string): Promise<void>;
692
- cleanupStaleDevices(): Promise<void>;
693
- searchDevices(excludeNodeId?: string): Promise<Device[]>;
694
- listDevicesWithStatus?(): Promise<DeviceStatusSnapshot[]>;
695
- getPeerSession?(id: string): Promise<PeerSessionSnapshot | null>;
696
- listPeerSessions?(): Promise<PeerSessionSnapshot[]>;
697
- waitForSettledPeer?(id: string, timeoutMs?: number): Promise<PeerSessionSnapshot | null>;
698
- resolvePeerIdentity?(id: string): Promise<ResolvedPeerIdentity>;
699
- resolvePeerConnectionRecords?(id: string): Promise<ManagedConnectionRecord[]>;
700
- updateDevice(deviceId: string, updates: {
701
- deviceName?: string;
702
- capabilities?: Device['capabilities'];
703
- metadata?: string;
704
- }): Promise<void>;
705
- deleteDevice(deviceId: string): Promise<void>;
706
- onDevicesChange(callback: (devices: Device[]) => void, excludeNodeId?: string): () => void;
707
- onAuthChange(callback: (user: RuntimeIdentity | null) => void): () => void;
708
- checkForSSOToken(): Promise<void>;
709
- waitForAuth(): Promise<void>;
710
- sendMessage(targetId: string, payload: string, state?: string, replyPayload?: string): Promise<string>;
711
- pollMessages(targetId: string): Promise<SignalingEnvelope[]>;
712
- subscribeDevices(userId: string): Promise<ReadableStream<DeviceEvent[]>>;
713
- startAutoConnectOnce?(userId: string, localDeviceId: string): Promise<void>;
714
- startAutoConnect(userId: string, localDeviceId: string): void;
715
- notifyDisconnectRequested?(remoteNodeId: string): void;
716
- startPresenceLoopOnce?(userId: string, localNodeId: string, deviceName: string, ticket: string, metadata?: string): Promise<void>;
717
- startPresenceLoop(userId: string, localNodeId: string, deviceName: string, ticket: string, metadata?: string): void;
718
- createSession(session: SignalingSession): Promise<void>;
719
- updateSession(sessionId: string, updateData: any): Promise<void>;
720
- subscribeSessions(localDeviceId: string): Promise<ReadableStream<SessionEvent[]>>;
721
- forceReconnectSnapshot(): void;
722
- getLocalDeviceId?(): Promise<string | null>;
723
- getLocalDeviceInfo?(): Promise<LocalDeviceInfo | null>;
724
- updateLocalDeviceName?(deviceName: string): Promise<LocalDeviceInfo | null>;
725
- startManagedSessionNative?(options: {
726
- userId: string;
727
- deviceName?: string;
728
- localDeviceId?: string | null;
729
- metadata?: string;
730
- autoConnect?: boolean;
731
- presence?: boolean;
732
- }): Promise<NativeManagedSessionStartResult>;
733
- reconcileNativeManagedSession?(options?: {
734
- reason?: string;
735
- }): Promise<unknown>;
736
- notifyNetworkChange?(options?: {
737
- reason?: string;
738
- }): Promise<unknown>;
739
- getManagedNodeId?(options?: {
740
- initializeIfMissing?: boolean;
741
- }): Promise<string | null>;
742
- getEndpointTicket?(): Promise<string>;
743
- openPeerBi?(id: string, timeoutMs?: number): Promise<BackendPeerBiStream>;
744
- openPeerNativeBi?(id: string, label: string, timeoutMs?: number): Promise<BackendPeerBiStream>;
745
- openPeerUni?(id: string, timeoutMs?: number): Promise<BackendPeerUniStream>;
746
- connectToDevice?(params: {
747
- deviceId?: string | null;
748
- endpointTicket: string;
749
- }): Promise<NativeConnectResult>;
750
- /**
751
- * Optional backchannel so a backend (e.g. WasmBridge) can access the narrow
752
- * facade surface needed to escalate runtime transport dials into registered
753
- * TS connections.
754
- */
755
- setCoreClient?(client: CoreClientBridgeHost | null): void;
756
- disconnectDevice?(deviceId: string): Promise<void>;
757
- setAutoConnectExcluded?(deviceId: string, excluded: boolean): Promise<void>;
758
- isConnected(nodeId: string): Promise<boolean>;
759
- getConnectionStates?(): Promise<BackendConnectionState[]>;
760
- onConnectionStateChange?(callback: (state: BackendConnectionState) => void): Promise<() => void> | (() => void);
761
- /** @deprecated Implement file protocols over named channels, or use `openrtc-file-transfer`. */
762
- sendExplicitFilePath?(connectionId: string, filePath: string, transferId?: string): Promise<string>;
763
- /** @deprecated Implement file protocols over named channels, or use `openrtc-file-transfer`. */
764
- sendExplicitFileData?(params: ExplicitFileDataSendParams): Promise<void>;
765
- /** @deprecated Transfer history is consumer-owned application state. */
766
- getTransferHistory?(limit?: number): Promise<Array<[string, unknown]>>;
767
- /** @deprecated Transfer history is consumer-owned application state. */
768
- deleteTransferJob?(jobId: string): Promise<void>;
769
- }
770
- interface CoreClientBridgeHost {
771
- connect(ticket: string, timeoutMs?: number, expectedDeviceId?: string | null, channelId?: string, options?: {
772
- admissionAlreadyPresented?: boolean;
773
- approvedScope?: string | null;
774
- }): Promise<{
775
- id?: string | null;
776
- remoteNodeId?: string | null;
777
- deviceId?: string | null;
778
- } | unknown>;
779
- ensureManagedApplicationRoute?(options: ManagedApplicationRouteOptions): Promise<{
780
- id?: string | null;
781
- remoteNodeId?: string | null;
782
- deviceId?: string | null;
783
- } | unknown>;
784
- waitForApplicationCryptoForPeer?(peerId?: string, timeoutMs?: number): Promise<unknown>;
785
- hasApplicationRouteForPeer?(connectionId?: string, remoteNodeId?: string): boolean;
786
- rememberRouteRepairTokenFromTicket?(ticket: string): Promise<boolean>;
787
- }
788
- interface ManagedApplicationRouteOptions {
789
- ticket: string;
790
- connectionId?: string | null;
791
- remoteNodeId?: string | null;
792
- expectedDeviceId?: string | null;
793
- timeoutMs?: number;
794
- }
795
- interface SignalingOptions {
796
- apiKey?: string;
797
- authMode?: AuthMode;
798
- projectId?: string;
799
- storagePrefix?: string;
800
- nodeIdPersistence?: 'persistent' | 'ephemeral';
801
- }
802
- interface TransportContext {
803
- sendMoQ: (data: Uint8Array, options?: {
804
- alreadyProtected?: boolean;
805
- }) => Promise<void>;
806
- /**
807
- * Send one plaintext typed frame over a fresh runtime-owned Iroh application
808
- * stream. The runtime applies the negotiated application-crypto stream
809
- * envelope; callers must not pre-encrypt the frame a second time.
810
- */
811
- sendIrohApplicationFrame?: (frame: Uint8Array) => Promise<void>;
812
- priorities: ProtocolName[];
813
- /**
814
- * Orders already-eligible route candidates through the Rust/WASM policy
815
- * owner. This is a pure decision call: it must not dial, retry, promote,
816
- * demote, or mutate connection state.
817
- */
818
- rankRoutes?: (candidates: ProtocolName[]) => ProtocolName[];
819
- disableIrohFallback: boolean;
820
- isMoQReady: () => boolean;
821
- isMoQDataReady?: () => boolean;
822
- isMoQApplicationRouteProven?: () => boolean;
823
- requestMoQApplicationRouteProof?: () => void;
824
- clearMoQApplicationRouteProof?: () => void;
825
- runtimeFlow?: 'default' | 'ticket-only';
826
- readerCloseStrategy?: 'cancel' | 'release-lock';
827
- }
828
- interface ApplicationPayloadCrypto {
829
- /**
830
- * When true, incoming application payloads that are not encrypted by this
831
- * envelope are dropped before app callbacks fire.
832
- */
833
- requireEncrypted?: boolean;
834
- protectPayload: (typeId: number, payload: Uint8Array) => Uint8Array;
835
- openPayload: (expectedTypeId: number, payload: Uint8Array) => Uint8Array | null;
836
- }
837
- interface ApplicationCryptoBiStream {
838
- send: WritableStream<Uint8Array>;
839
- recv: ReadableStream<Uint8Array>;
840
- endpoint_id?: string;
841
- }
842
- interface ApplicationCryptoStreamTools {
843
- readonly typeId: number;
844
- protectFrame: (payload: Uint8Array) => Uint8Array;
845
- openFrame: (payload: Uint8Array) => Uint8Array | null;
846
- createOutboundTransform: () => TransformStream<Uint8Array, Uint8Array>;
847
- createInboundTransform: () => TransformStream<Uint8Array, Uint8Array>;
848
- wrapReadable: (readable: ReadableStream<Uint8Array>) => ReadableStream<Uint8Array>;
849
- wrapWritable: (writable: WritableStream<Uint8Array>) => WritableStream<Uint8Array>;
850
- wrapBiStream: <T extends ApplicationCryptoBiStream>(stream: T) => T;
851
- }
852
- interface ApplicationPayloadReadinessOptions {
853
- /**
854
- * When provided, a connection is considered ready only once its active
855
- * application route is one of these transports.
856
- */
857
- preferredTransports?: ProtocolName[];
858
- /**
859
- * If a preferred upgraded route cannot be established, allow the connection's
860
- * proven application route to carry payloads instead of remaining pending.
861
- */
862
- allowFallbackAfterPreferredTransportFailure?: boolean;
863
- }
864
- interface ApplicationPayloadRouteOptions extends ApplicationPayloadReadinessOptions {
865
- /**
866
- * Include the parallel/fallback transport in diagnostic route listings.
867
- * Normal app payload probes should leave this disabled so they measure the
868
- * route OpenRTC would actually prefer for application data.
869
- */
870
- includeFallbackTransports?: boolean;
871
- }
872
- interface ApplicationPayloadSendOptions extends ApplicationPayloadRouteOptions {
873
- }
874
- interface ApplicationRouteReadyObservation {
875
- connectionId: string;
876
- remoteNodeId: string;
877
- activeTransport: ProtocolName;
878
- parallelTransport?: ProtocolName | null;
879
- reason: 'webrtc-route-ready' | 'webrtc-heartbeat-healthy' | 'webrtc-application-send' | 'base-transport-loss-preserved';
880
- transportStableId?: number;
881
- transportGeneration?: number;
882
- routeGeneration?: number;
883
- }
884
- interface ConnectionOptions {
885
- reliable?: boolean;
886
- rtcConfig?: PlutoRTCConfiguration;
887
- transportContext?: TransportContext;
888
- applicationCrypto?: ApplicationPayloadCrypto;
889
- /**
890
- * Whether the constructor's reader/writer represent a routable base
891
- * application stream. Transport-only ticket channels set this to false:
892
- * their placeholder streams exist only to satisfy the compatibility object,
893
- * while application bytes use named runtime channels.
894
- */
895
- hasBaseApplicationStream?: boolean;
896
- /** Framing used by the underlying iroh control stream. */
897
- controlFrameMode?: 'typed' | 'native-main';
898
- /**
899
- * When true, public application payload sends wait for applicationCrypto to
900
- * be installed and fail closed if key negotiation never completes.
901
- * Internal handshake/control frames are sent through a separate control path.
902
- */
903
- requireApplicationCrypto?: boolean;
904
- applicationCryptoWaitMs?: number;
905
- onTransportStatusChange?: (status: {
906
- activeTransport: ProtocolName;
907
- parallelTransport?: ProtocolName | null;
908
- transportStableId?: number;
909
- transportGeneration?: number;
910
- routeGeneration?: number;
911
- }) => boolean | void | Promise<boolean | void>;
912
- /**
913
- * Fired when a connection-owned application route has proven it can carry
914
- * app traffic. Consumers should use this as a lifecycle signal for the same
915
- * connection record, not as an independent projection source.
916
- */
917
- onApplicationRouteReady?: (event: ApplicationRouteReadyObservation) => void;
918
- /**
919
- * Fired when the WebRTC data plane has proven a ping/pong round trip but the
920
- * mandatory application crypto route is not installed yet. Connection owns
921
- * transport proof; Client owns the application-route handshake recovery.
922
- */
923
- onApplicationRouteMissing?: (event: {
924
- connectionId: string;
925
- remoteNodeId: string;
926
- reason: 'webrtc-heartbeat-before-crypto';
927
- negotiationId?: string | null;
928
- }) => void;
929
- }
930
- interface JoinRequest {
931
- id: string;
932
- userId: string;
933
- ticket: string;
934
- state: 'pending' | 'accepted' | 'rejected';
935
- }
936
-
937
- export type { RouteDescriptor as $, AuthMode as A, BackendPeerBiStream as B, ConnectDeviceResult as C, DiscoveryMode as D, ExplicitFileDataSendParams as E, PeerScope as F, GrantScope as G, DevicePresenceStatus as H, ISignalingBackend as I, JoinRoomOptions as J, PeerLifecycleStatus as K, LocalDeviceInfo as L, ManagedConnectionRecord as M, NativeManagedSessionStartResult as N, ProtocolCapability as O, PeerSessionSnapshot as P, ProtocolCapabilityMap as Q, ResolvedPeerIdentity as R, SignalingMode as S, TransportLatencySnapshot as T, ApplicationCryptoStreamTools as U, SpaceTokenProvider as V, AppLimits as W, ApplicationCryptoBiStream as X, ProtocolBaseName as Y, ProtocolImplementationKind as Z, ProtocolLocality as _, ConnectDeviceHooks as a, RouteFamily as a0, RouteImplementationKind as a1, SpaceAuthMode as a2, SignalingOptions as a3, RoomCreationMode as a4, ScanningLoopOptions as a5, ScanningLoopHandle as a6, RuntimeBootstrapOptions as a7, RuntimeBootstrapResult as a8, ManagedApplicationRouteOptions as a9, JoinRequest as aa, ConnectDeviceOptions as b, RuntimeIdentity as c, Device as d, DeviceStatusSnapshot as e, SignalingEnvelope as f, DeviceEvent as g, SignalingSession as h, SessionEvent as i, BackendPeerUniStream as j, NativeConnectParams as k, NativeConnectResult as l, BackendConnectionState as m, ClientOptions as n, ConnectionOptions as o, ApplicationPayloadCrypto as p, ApplicationPayloadReadinessOptions as q, ApplicationPayloadRouteOptions as r, ProtocolName as s, ApplicationPayloadSendOptions as t, ChannelDescriptor as u, IncomingStreamChannelMetadata as v, ManagedDeviceConnectOptions as w, PeerState as x, PeerHealth as y, RoomMember as z };