openrtc 0.2.0 → 1.0.0

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.
Files changed (39) hide show
  1. package/LICENSE +92 -0
  2. package/README.md +100 -10
  3. package/dist/{DelegatingRuntimeAdapter-CjHzBEBA.d.ts → DelegatingRuntimeAdapter-By7pziBs.d.ts} +36 -15
  4. package/dist/IEngineBridge-C7OT2CRv.d.ts +10 -0
  5. package/dist/{IpcRuntimeAdapter-CtckyMol.d.ts → IpcRuntimeAdapter-DymXAsNU.d.ts} +6 -3
  6. package/dist/auth/index.js +1 -1
  7. package/dist/auth/internal.js +1 -1
  8. package/dist/chunk-3KDNLXT6.js +3 -0
  9. package/dist/chunk-5RXNKNPH.js +2 -0
  10. package/dist/chunk-6TIOSMVJ.js +1 -0
  11. package/dist/chunk-BLOEZIFJ.js +1 -0
  12. package/dist/chunk-CK6WQV7J.js +1 -0
  13. package/dist/chunk-KH227SE4.js +1 -0
  14. package/dist/chunk-KYDLXXNM.js +1 -0
  15. package/dist/chunk-W5JHUOK5.js +2 -0
  16. package/dist/device-status-nkXepu97.d.ts +560 -0
  17. package/dist/{factories-CwZiIRg1.d.ts → framing-BUtu0oZK.d.ts} +47 -520
  18. package/dist/index.d.ts +113 -9
  19. package/dist/index.js +2 -2
  20. package/dist/openrtc_bg.wasm +0 -0
  21. package/dist/runtime/WasmRuntimeAdapter.d.ts +3 -2
  22. package/dist/runtime/WasmRuntimeAdapter.js +1 -1
  23. package/dist/runtime/device-status.d.ts +3 -0
  24. package/dist/runtime/device-status.js +1 -0
  25. package/dist/runtime/index.d.ts +94 -84
  26. package/dist/runtime/index.js +1 -1
  27. package/dist/runtime/tauri.d.ts +4 -3
  28. package/dist/runtime/tauri.js +1 -1
  29. package/dist/transport/index.d.ts +1 -1
  30. package/dist/transport/index.js +1 -1
  31. package/dist/{types-DyCGvj9l.d.ts → types-CzIpGV9x.d.ts} +117 -14
  32. package/package.json +22 -10
  33. package/dist/chunk-3VTF5RKW.js +0 -1
  34. package/dist/chunk-JXGKO7SX.js +0 -1
  35. package/dist/chunk-MFT6SOZ6.js +0 -3
  36. package/dist/chunk-SGZWR63E.js +0 -1
  37. package/dist/chunk-VARALO7G.js +0 -1
  38. package/dist/chunk-WOHFM6DI.js +0 -2
  39. package/dist/chunk-YHJOXD46.js +0 -2
@@ -0,0 +1,560 @@
1
+ import { A as AuthContext } from './IEngineBridge-C7OT2CRv.js';
2
+ import { a4 as ConnectionOptions, r as ApplicationPayloadCrypto, w as ApplicationPayloadReadinessOptions, x as ApplicationPayloadRouteOptions, o as ProtocolName, y as ApplicationPayloadSendOptions, a2 as ChannelDescriptor$1, L as LocalDeviceInfo, U as IncomingStreamChannelMetadata, C as ClientOptions, a as Device, f as SignalingSession, R as RuntimeIdentity, b as DeviceStatusSnapshot, a5 as ManagedDeviceConnectOptions, $ as PeerState, a1 as PeerHealth, Q as JoinRoomOptions, T as RoomMember, a0 as PeerScope, k as BackendConnectionState, z as DevicePresenceStatus, a6 as PeerLifecycleStatus, P as PeerSessionSnapshot } from './types-CzIpGV9x.js';
3
+
4
+ interface ITransport {
5
+ readonly name: string;
6
+ readonly isReady: boolean;
7
+ init(localNodeId: string, remoteNodeId: string, options: any): Promise<void>;
8
+ send(data: Uint8Array): Promise<void>;
9
+ close(): void;
10
+ onMessage(callback: (data: Uint8Array) => void): void;
11
+ onStateChange(callback: (state: 'connecting' | 'connected' | 'failed' | 'disconnected') => void): void;
12
+ handleSignalingMessage?(msg: any): void;
13
+ getSignalingHandler?(): (msg: any) => Promise<void>;
14
+ getNativeTransport?(): any;
15
+ getNegotiationId?(): string | null;
16
+ getDataChannelReadyState?(): string | null;
17
+ }
18
+
19
+ type ConnectionHealth = 'unknown' | 'healthy' | 'suspect' | 'stale';
20
+
21
+ type UpgradeState = 'none' | 'upgrading' | 'upgraded' | 'failed';
22
+ declare class Connection {
23
+ private static readonly textDecoder;
24
+ private static readonly textEncoder;
25
+ private static readonly UPGRADE_RETRY_DELAY_MS;
26
+ private static readonly MAX_UPGRADE_RETRIES;
27
+ private static readonly MAX_UPGRADE_REDRIVES;
28
+ private static readonly UPGRADE_REDRIVE_DELAY_MS;
29
+ private static readonly WEBRTC_DISCONNECTED_GRACE_MS;
30
+ private static readonly MAX_PENDING_MESSAGES;
31
+ private static readonly DEFAULT_APPLICATION_CRYPTO_WAIT_MS;
32
+ /**
33
+ * Must exceed `WEBRTC_ICE_CONNECT_TIMEOUT_MS` in `WebRTCTransport`: the transport
34
+ * waits that long for ICE + DataChannel before `failed`. A shorter watchdog here
35
+ * tears the PC down early, burns `MAX_UPGRADE_RETRIES`, and stretches upgrades to ~60s+ under load.
36
+ */
37
+ private static readonly WEBRTC_UPGRADE_ATTEMPT_TIMEOUT_MS;
38
+ private static readonly MAX_PENDING_ENCRYPTED_APPLICATION_PAYLOADS;
39
+ private listeners;
40
+ private pendingMessages;
41
+ private pendingEncryptedApplicationPayloads;
42
+ private webrtcBinaryHandlers;
43
+ private closeListeners;
44
+ private upgradeStateListeners;
45
+ private writer;
46
+ private reader;
47
+ private _isClosed;
48
+ get isClosed(): boolean;
49
+ private receiveBuffer;
50
+ readonly id: string;
51
+ readonly remoteNodeId: string;
52
+ /** @deprecated Compatibility alias for legacy consumers. This is the remote node id, not a device id. */
53
+ readonly deviceId: string;
54
+ readonly localNodeId: string;
55
+ private options;
56
+ private writeMutex;
57
+ private applicationCryptoWaiters;
58
+ private applicationKeyAgreementObservationEpoch;
59
+ private nativeSignalSender;
60
+ private webrtcTransport;
61
+ private webRtcApplicationRouteReadyTransport;
62
+ private webRtcApplicationRouteReadyNegotiationId;
63
+ private upgradeState;
64
+ private upgradeRequested;
65
+ private negotiationSwitchCount;
66
+ private upgradeAttemptActive;
67
+ private upgradeRetryCount;
68
+ private upgradeReDriveCount;
69
+ private upgradeReDriveTimer;
70
+ private upgradeRetryTimer;
71
+ private upgradeAttemptTimeoutTimer;
72
+ private lastReportedTransportStatus;
73
+ private applicationRouteMissingNotified;
74
+ private upgradeTerminalFailure;
75
+ private pendingSignals;
76
+ private activeNegotiationId;
77
+ private webrtcHeartbeat;
78
+ private webRtcHeartbeatProbeInFlight;
79
+ private webRtcApplicationRouteProbeInFlight;
80
+ private webRtcHeartbeatConsecutiveProbeFailures;
81
+ private irohHealthListeners;
82
+ private webrtcHealthListeners;
83
+ private lastWebRtcHeartbeatOkAt;
84
+ private lastWebRtcDataChannelOpenAt;
85
+ private lastApplicationRouteReadyReportAt;
86
+ private static readonly WEBRTC_RENEGOTIATE_LIVENESS_WINDOW_MS;
87
+ private static readonly MAX_NEGOTIATION_SWITCHES;
88
+ private lastForegroundAt;
89
+ private webRtcDisconnectedGraceTimer;
90
+ private preferredWebRtcRole;
91
+ constructor(id: string, localNodeId: string, remoteNodeId: string, writer: WritableStreamDefaultWriter<Uint8Array>, reader: ReadableStreamDefaultReader<Uint8Array>, options?: ConnectionOptions);
92
+ setApplicationCrypto(applicationCrypto: ApplicationPayloadCrypto | undefined): void;
93
+ markApplicationKeyAgreementObserved(): number;
94
+ getApplicationKeyAgreementObservationEpoch(): number;
95
+ requireApplicationCrypto(): void;
96
+ isApplicationCryptoRequired(): boolean;
97
+ isReadyForApplicationPayload(options?: ApplicationPayloadReadinessOptions): boolean;
98
+ getApplicationPayloadTransports(options?: ApplicationPayloadRouteOptions): ProtocolName[];
99
+ private isTransportAvailableForApplicationPayload;
100
+ private resolveApplicationCryptoWaiters;
101
+ private rejectApplicationCryptoWaiters;
102
+ private waitForRequiredApplicationCrypto;
103
+ /**
104
+ * Starts WebRTC upgrade only when peer capability negotiation allows it.
105
+ * No-op when WebRTC is not configured or an upgrade already started.
106
+ */
107
+ requestWebRTCUpgrade(reason?: string): void;
108
+ /**
109
+ * Whether the current WebRTC route is provably alive: an open data channel
110
+ * plus either a recent heartbeat round trip or a freshly opened channel. An
111
+ * `open` readyState alone is not proof — it lingers for many seconds after the
112
+ * remote vanishes (e.g. a page reload), so a dead-but-`open` channel reports
113
+ * not-live and can be replaced rather than trusted.
114
+ */
115
+ private isWebRtcRouteHeartbeatLive;
116
+ requestTransportRecovery(reason: string, options?: {
117
+ forceRenegotiate?: boolean;
118
+ replaceExisting?: boolean;
119
+ }): void;
120
+ private static readonly FOREGROUND_PROBE_TIMEOUT_MS;
121
+ handleAppForeground(): void;
122
+ private beginWebRtcRecovery;
123
+ getUpgradeState(): UpgradeState;
124
+ updateRTCConfig(rtcConfig: ConnectionOptions['rtcConfig']): void;
125
+ onUpgradeStateChange(callback: (state: UpgradeState) => void): void;
126
+ /**
127
+ * Best-effort transport diagnostics for developer tooling.
128
+ *
129
+ * - `usesRelay=true` means the selected WebRTC candidate pair includes a relay candidate.
130
+ * - `usesRelay=false` means we found a selected pair and it is direct.
131
+ * - `usesRelay=null` means there is not enough data yet.
132
+ */
133
+ getTransportDiagnostics(): Promise<{
134
+ activeTransport: ProtocolName;
135
+ parallelTransport: ProtocolName | null;
136
+ usesRelay: boolean | null;
137
+ relaySource: string | null;
138
+ webrtc: {
139
+ iceConnectionState: string | null;
140
+ iceGatheringState: string | null;
141
+ localCandidateType: string | null;
142
+ remoteCandidateType: string | null;
143
+ localProtocol: string | null;
144
+ remoteProtocol: string | null;
145
+ candidateTypeSummary: string | null;
146
+ } | null;
147
+ }>;
148
+ private lastWebRtcLocalCandidateType;
149
+ private lastWebRtcRemoteCandidateType;
150
+ get transportType(): ProtocolName;
151
+ private _peerMoQReady;
152
+ get peerMoQReady(): boolean;
153
+ set peerMoQReady(value: boolean);
154
+ private _remoteSupportsWebRTC;
155
+ get remoteSupportsWebRTC(): boolean;
156
+ set remoteSupportsWebRTC(value: boolean);
157
+ private mediaListeners;
158
+ /**
159
+ * Send a message to the other peer.
160
+ * Messages can be strings or objects (JSON stringified).
161
+ */
162
+ send(message: string | object | ArrayBuffer | Uint8Array, options?: ApplicationPayloadSendOptions): Promise<void>;
163
+ /**
164
+ * Send media data (video/audio header + payload)
165
+ * Internal use for now.
166
+ */
167
+ sendMedia(type: 'audio' | 'video', data: Uint8Array): Promise<void>;
168
+ /**
169
+ * Send a data message on a specific transport without fallback.
170
+ * Throws when the requested transport is unavailable.
171
+ */
172
+ sendOnTransport(transport: ProtocolName, message: string | object | ArrayBuffer | Uint8Array): Promise<void>;
173
+ /**
174
+ * Send plaintext control traffic that is required to bootstrap application
175
+ * key agreement. This is intentionally separate from public app-data sends.
176
+ */
177
+ sendControl(message: string | object | ArrayBuffer | Uint8Array): Promise<void>;
178
+ /**
179
+ * Write an already-framed payload directly on the underlying iroh control stream.
180
+ * Used by native-main signaling paths that must preserve protocol framing.
181
+ */
182
+ sendRawIrohFrame(frame: Uint8Array): Promise<void>;
183
+ /**
184
+ * Compatibility/diagnostic view of currently usable transports.
185
+ *
186
+ * Lifecycle projection and route selection must use getTransportStatus().
187
+ * This legacy list intentionally remains for older callers and tests that
188
+ * need a human-readable inventory, but it is not an authority for active
189
+ * versus fallback transport state.
190
+ */
191
+ getAvailableTransports(): ProtocolName[];
192
+ onWebRTCBinaryMessage(handler: (data: Uint8Array) => boolean): void;
193
+ private dispatchWebRtcBinaryHandlers;
194
+ getWebRTCTransport(): ITransport | null;
195
+ sendOnWebRTC(data: Uint8Array): Promise<void>;
196
+ private encodePayload;
197
+ private protectApplicationPayload;
198
+ private openApplicationPayload;
199
+ private openUntypedApplicationPayload;
200
+ private isPlaintextBootstrapPayload;
201
+ private queueEncryptedApplicationPayload;
202
+ private flushPendingEncryptedApplicationPayloads;
203
+ private buildFrame;
204
+ private sendOverIroh;
205
+ private sendUsingTransport;
206
+ private sendTypedOnTransport;
207
+ private sendTyped;
208
+ private getSendTransportPriorities;
209
+ /**
210
+ * Disconnect the connection
211
+ */
212
+ disconnect(): Promise<void>;
213
+ /**
214
+ * Listen for incoming messages
215
+ */
216
+ onMessage(callback: (message: any) => void): void;
217
+ /**
218
+ * Listen for incoming media
219
+ */
220
+ onMedia(callback: (type: 'audio' | 'video', data: Uint8Array) => void): void;
221
+ /**
222
+ * Listen for disconnection
223
+ */
224
+ onDisconnect(callback: () => void): void;
225
+ private close;
226
+ private preserveWebRtcConnectionAfterBaseTransportLoss;
227
+ private readLoop;
228
+ injectData(chunk: Uint8Array): void;
229
+ private handleData;
230
+ private tryHandlePlaintextNativeSignal;
231
+ private static isUntypedDataFrame;
232
+ private processDataPayload;
233
+ private isLikelyTextPayload;
234
+ private emitMedia;
235
+ private emitMessage;
236
+ receiveMessage(msg: any): void;
237
+ receiveDataPayload(messageData: Uint8Array): void;
238
+ private trackListeners;
239
+ private warnedSrtpApplicationCryptoBoundary;
240
+ private warnSrtpApplicationCryptoBoundary;
241
+ addTrack(track: MediaStreamTrack): RTCRtpSender | null;
242
+ addTransceiver(trackOrKind: MediaStreamTrack | string, init?: RTCRtpTransceiverInit): RTCRtpTransceiver | null;
243
+ onTrack(callback: (event: RTCTrackEvent) => void): void;
244
+ private hasRecoverableBasePath;
245
+ private hasBaseApplicationStream;
246
+ private isWebRtcDataChannelOpen;
247
+ private clearWebRtcDisconnectedGraceTimer;
248
+ private transportStillLikelyAlive;
249
+ private handleUnhealthyWebRtcTransportStateWithGrace;
250
+ private attemptUpgrade;
251
+ private setUpgradeState;
252
+ private handleUpgradeFailure;
253
+ private scheduleUpgradeReDrive;
254
+ private clearUpgradeReDriveTimer;
255
+ private shouldRetryUpgrade;
256
+ private scheduleUpgradeRetry;
257
+ private clearUpgradeRetryTimer;
258
+ private startUpgradeAttemptTimeout;
259
+ private clearUpgradeAttemptTimeoutTimer;
260
+ private teardownWebRTCTransport;
261
+ private startWebRtcHeartbeat;
262
+ private stopWebRtcHeartbeat;
263
+ private notifyWebRtcApplicationRouteMissing;
264
+ private startWebRtcApplicationRouteProbe;
265
+ private sendIrohHeartbeatPong;
266
+ /** Register a listener for WebRTC heartbeat health changes. */
267
+ onWebRtcHeartbeatHealth(cb: (health: ConnectionHealth) => void): void;
268
+ /** Register a listener for iroh heartbeat health changes (WASM path). */
269
+ onIrohHeartbeatHealth(cb: (health: ConnectionHealth) => void): void;
270
+ reportTransportStatusIfChanged(): void;
271
+ private reportApplicationRouteReady;
272
+ /**
273
+ * Single connection-owned transport snapshot for status reporting,
274
+ * lifecycle projection, and diagnostics. The active route is application
275
+ * ready; the parallel route is its usable fallback or candidate.
276
+ */
277
+ getTransportStatus(): {
278
+ activeTransport: ProtocolName;
279
+ parallelTransport: ProtocolName | null;
280
+ };
281
+ private resolveParallelTransport;
282
+ setNativeSignalSender(sender: (envelope: any) => Promise<void>): void;
283
+ /**
284
+ * Structured connection-lifecycle log. One event per meaningful transition
285
+ * (upgrade requested/started/failed, route promoted, app route ready, …) with
286
+ * the connection's current lifecycle snapshot, so the whole connection flow
287
+ * can be reconstructed from logs. Emits both a human line and a JSON line.
288
+ */
289
+ private traceLifecycle;
290
+ getControlFrameMode(): NonNullable<ConnectionOptions['controlFrameMode']>;
291
+ /**
292
+ * Send a control envelope over the native-main signal route. Returns false
293
+ * (without sending) unless this connection is in `native-main` control-frame
294
+ * mode and has a native signal sender, so a typed connection never
295
+ * accidentally routes control through the native sender.
296
+ */
297
+ sendNativeControlEnvelope(envelope: any): Promise<boolean>;
298
+ /**
299
+ * Promote a connection to the native-main control plane: switch its
300
+ * control-frame mode to `native-main` and attach the native signal sender.
301
+ * Used when native-main evidence arrives for a connection that bootstrapped
302
+ * on a typed stream, so subsequent control traffic flows over the durable
303
+ * native-main route even if the bootstrap stream later closes.
304
+ */
305
+ promoteToNativeMainControlRoute(sender: (envelope: any) => Promise<void>): void;
306
+ private hasRequiredApplicationCrypto;
307
+ private clearWebRtcApplicationRouteReady;
308
+ private isCurrentWebRtcTransportApplicationRouteReady;
309
+ private isWebRtcApplicationRouteReadyForTransport;
310
+ /**
311
+ * Mark the upgraded WebRTC data plane as carrying a proven application route
312
+ * (data channel open + required crypto present). Idempotent. Promotes the
313
+ * active transport projection to `webrtc` via reportTransportStatusIfChanged.
314
+ */
315
+ private markWebRtcApplicationRouteReady;
316
+ /**
317
+ * True only when the WebRTC transport is upgraded AND its application route
318
+ * is proven (crypto present). The active route must not advertise `webrtc`
319
+ * until this holds, so a half-open data channel never looks routable.
320
+ */
321
+ isWebRtcApplicationRouteReady(): boolean;
322
+ /**
323
+ * MoQ has a different data-plane shape than WebRTC: it is a shared relay
324
+ * session on the Client plus a peer capability/subscription bit on this
325
+ * Connection. Even so, it follows the same lifecycle invariant as every
326
+ * custom transport: do not advertise it as the active application route until
327
+ * the local transport is ready, the peer route is enabled, and the required
328
+ * application crypto is available. Future MoQ route probes should tighten
329
+ * this predicate, not bypass it.
330
+ */
331
+ isMoQApplicationRouteReady(): boolean;
332
+ private isMoQDataRouteReady;
333
+ private sendInternalSignal;
334
+ receiveInternalSignal(content: any): void;
335
+ private handleInternalSignal;
336
+ private createNegotiationId;
337
+ private getDeterministicWebRtcRole;
338
+ private normalizeNegotiationId;
339
+ }
340
+
341
+ /**
342
+ * App-facing options intentionally hide transport node identifiers from callbacks.
343
+ */
344
+ type RuntimeClientOptions = Omit<ClientOptions, 'onDevices' | 'onAutoConnect' | 'onIncomingSession'> & {
345
+ onDevices?: (devices: RuntimeDevice[]) => void;
346
+ onAutoConnect?: (devices: RuntimeDevice[]) => void;
347
+ onIncomingSession?: (session: RuntimeSession) => Promise<void>;
348
+ };
349
+ /**
350
+ * App-facing device model. Runtime transport identifiers stay internal.
351
+ */
352
+ type RuntimeDevice = Omit<Device, 'nodeId'>;
353
+ /**
354
+ * App-facing session model. Node identifiers are runtime-internal metadata.
355
+ */
356
+ type RuntimeSession = Omit<SignalingSession, 'initiatorNodeId' | 'targetNodeId' | 'appTag'>;
357
+ type RuntimeAuthIdentity = RuntimeIdentity;
358
+ type RuntimeAuthContext = AuthContext;
359
+ /**
360
+ * App-facing peer state model. Runtime transport identifiers stay internal.
361
+ */
362
+ type RuntimePeerState = Omit<PeerState, 'nodeId'>;
363
+ type RuntimePeerHealth = PeerHealth;
364
+ type RuntimePeerLifecycleStatus = PeerLifecycleStatus;
365
+ type RuntimePeerScope = PeerScope;
366
+ /**
367
+ * App-facing peer session snapshot model. Runtime transport identifiers stay internal.
368
+ */
369
+ type RuntimePeerSessionSnapshot = Omit<PeerSessionSnapshot, 'nodeId'>;
370
+ type RuntimeLocalDeviceInfo = LocalDeviceInfo;
371
+ type RuntimeRoomMember = RoomMember;
372
+ type RuntimeDeviceConnectOptions = ManagedDeviceConnectOptions;
373
+ type RuntimeJoinRoomOptions = JoinRoomOptions;
374
+ type RuntimeChannelDescriptor = ChannelDescriptor$1;
375
+ interface RuntimeConnectionTarget {
376
+ ticket: string;
377
+ timeoutMs?: number;
378
+ }
379
+ interface RuntimePeerConnectOptions {
380
+ deviceId?: string;
381
+ ticket?: string;
382
+ scope?: RuntimePeerScope;
383
+ channelId?: string;
384
+ /** Total wall-clock budget for dial, admission, and peer settlement. */
385
+ timeoutMs?: number;
386
+ /**
387
+ * When true, automatic/observer dials fail fast if the peer has a sticky
388
+ * manual-disconnect projection for this app session. User-initiated manual
389
+ * reconnects should leave this unset and clear the exclusion explicitly.
390
+ */
391
+ respectManualDisconnect?: boolean;
392
+ }
393
+ interface RuntimePeerStreamOptions {
394
+ ticket?: string;
395
+ scope?: RuntimePeerScope;
396
+ channelId?: string;
397
+ timeoutMs?: number;
398
+ }
399
+ type RuntimeLogicalChannelFraming = 'raw' | 'u32be';
400
+ interface RuntimeScopedChannelOptions {
401
+ peerId?: string;
402
+ peerNodeId?: string;
403
+ deviceId?: string | null;
404
+ ticket?: string;
405
+ scope: RuntimePeerScope;
406
+ channelId: string;
407
+ timeoutMs?: number;
408
+ respectManualDisconnect?: boolean;
409
+ /**
410
+ * Native product protocols such as Plutonium drive-view expect a plaintext
411
+ * stream label before payload frames. OpenRTC owns that handshake here so
412
+ * apps do not need to choose raw transport APIs.
413
+ */
414
+ nativeLabel?: boolean;
415
+ framing?: RuntimeLogicalChannelFraming;
416
+ }
417
+ interface RuntimeScopedLogicalChannel {
418
+ channelId: string;
419
+ peerId: string;
420
+ connection: Connection;
421
+ send(payload: Uint8Array): Promise<void>;
422
+ onMessage(callback: (payload: Uint8Array) => void): () => void;
423
+ close(): Promise<void>;
424
+ diagnostics(): {
425
+ connectionId: string | null;
426
+ remoteNodeId: string | null;
427
+ transports: string[];
428
+ hasSendOnWebRTC?: boolean;
429
+ hasWebRTCTransport?: boolean;
430
+ lastSendTransport?: 'webrtc' | 'stream' | null;
431
+ framing: RuntimeLogicalChannelFraming;
432
+ nativeLabel: boolean;
433
+ };
434
+ }
435
+ /**
436
+ * App-facing device status snapshot model. Runtime transport identifiers stay internal.
437
+ */
438
+ type RuntimeDeviceStatusSnapshot = Omit<DeviceStatusSnapshot, 'nodeId'>;
439
+ type RuntimeDeviceStatus = RuntimeDeviceStatusSnapshot;
440
+ type RuntimeDevicePresenceStatus$1 = DevicePresenceStatus;
441
+ type RuntimeIncomingStream = {
442
+ type: 'bi' | 'uni';
443
+ stream: any;
444
+ remoteNodeId: string;
445
+ protocolHint?: 'control' | 'explicit' | 'native-main' | 'unknown';
446
+ channel?: IncomingStreamChannelMetadata | null;
447
+ };
448
+ type RuntimeConnectionEvent = {
449
+ type: 'connected' | 'disconnected';
450
+ connectionId: string;
451
+ localNodeId: string;
452
+ remoteNodeId: string;
453
+ transport: ProtocolName;
454
+ };
455
+ type RuntimeRawConnection = {
456
+ connectionId: string;
457
+ localNodeId: string;
458
+ remoteNodeId: string;
459
+ };
460
+ type RuntimePresenceLoopOptions = {
461
+ deviceName?: string;
462
+ ticket?: string;
463
+ metadata?: string;
464
+ };
465
+ type RuntimeManagedSessionPlatform = 'native' | 'web';
466
+ type RuntimeManagedSessionKind = 'app-user-device' | 'share-anonymous' | 'drive-grant-guest' | 'scoped-guest' | (string & {});
467
+ type RuntimeAutoConnectPolicy = 'enabled' | 'disabled' | 'scoped-only';
468
+ type RuntimePresencePolicy = 'online' | 'disabled';
469
+ type RuntimeConnectionStateSnapshot = BackendConnectionState;
470
+ type RuntimeApplicationPayloadReadinessOptions = ApplicationPayloadReadinessOptions;
471
+ type RuntimeUiConnectionStatus = 'connecting' | 'connected' | 'disconnected' | 'failed';
472
+ interface RuntimePeerReadinessSnapshot {
473
+ requestedId: string;
474
+ connected: boolean;
475
+ settledReady: boolean;
476
+ status: RuntimeUiConnectionStatus;
477
+ health: RuntimePeerHealth | 'unknown';
478
+ deviceId?: string | null;
479
+ deviceIdHint?: string | null;
480
+ activeConnectionId?: string | null;
481
+ readinessState?: string;
482
+ readinessReason?: string;
483
+ scopes: string[];
484
+ }
485
+ interface RuntimeLocalDeviceProfile {
486
+ deviceId: string | null;
487
+ deviceName: string;
488
+ platformType: string;
489
+ userId: string | null;
490
+ capabilities: NonNullable<RuntimeLocalDeviceInfo['capabilities']>;
491
+ lastSeenAt: string;
492
+ localNodeId?: string | null;
493
+ }
494
+ interface RuntimeManagedSessionOptions {
495
+ platform: RuntimeManagedSessionPlatform;
496
+ sessionKind?: RuntimeManagedSessionKind;
497
+ scope?: string | null;
498
+ autoConnectPolicy?: RuntimeAutoConnectPolicy;
499
+ presencePolicy?: RuntimePresencePolicy;
500
+ userId?: string | null;
501
+ deviceName?: string;
502
+ localDeviceId?: string | null;
503
+ metadata?: string;
504
+ autoConnect?: boolean;
505
+ presence?: boolean;
506
+ }
507
+ interface RuntimeManagedSession {
508
+ mode: RuntimeManagedSessionPlatform;
509
+ device: RuntimeLocalDeviceProfile;
510
+ stop: () => Promise<void>;
511
+ }
512
+ type ConnectionTarget = RuntimeConnectionTarget;
513
+ type PeerConnectOptions = RuntimePeerConnectOptions;
514
+ type PeerStreamOptions = RuntimePeerStreamOptions;
515
+ type ScopedChannelOptions = RuntimeScopedChannelOptions;
516
+ type ScopedLogicalChannel = RuntimeScopedLogicalChannel;
517
+ type IncomingStream = RuntimeIncomingStream;
518
+ type ConnectionEvent = RuntimeConnectionEvent;
519
+ type RawConnection = RuntimeRawConnection;
520
+ type PresenceLoopOptions = RuntimePresenceLoopOptions;
521
+ type PeerReadiness = RuntimePeerReadinessSnapshot;
522
+ type DeviceProfile = RuntimeLocalDeviceProfile;
523
+ type SessionOptions = RuntimeManagedSessionOptions;
524
+ type Session = RuntimeManagedSession;
525
+ type ChannelDescriptor = RuntimeChannelDescriptor;
526
+
527
+ interface RuntimeDeviceActiveOptions {
528
+ now?: number;
529
+ /**
530
+ * Optional local freshness window for durable roster rows. Leave undefined
531
+ * when the caller only wants to honor explicit online/expiresAt state.
532
+ */
533
+ staleAfterMs?: number;
534
+ }
535
+ type RuntimeDeviceActivityStatus = Pick<Partial<RuntimeDevice>, 'online' | 'lastSeenAt' | 'updatedAt' | 'createdAt' | 'expiresAt'>;
536
+ type RuntimeDeviceRouteStatus = Pick<Partial<RuntimeDeviceStatusSnapshot>, 'settledReady' | 'readinessState' | 'connectionStatus'>;
537
+ type RuntimeDevicePresenceStatus = Pick<RuntimeDevice, 'online' | 'ticket'> & Pick<Partial<RuntimeDeviceStatusSnapshot>, 'connectable' | 'presenceStatus' | 'online' | 'ticket'>;
538
+ /**
539
+ * True when a runtime device row is currently live enough to display or
540
+ * consider for app-level routing. This is deliberately separate from
541
+ * `isRuntimeDeviceConnectable`: a peer can be active/present before it has a
542
+ * usable ticket, and a stale durable row should not keep app UIs alive.
543
+ */
544
+ declare function isRuntimeDeviceActive(device: RuntimeDeviceActivityStatus, options?: RuntimeDeviceActiveOptions): boolean;
545
+ /**
546
+ * True once OpenRTC has a routable peer projection for normal app payloads.
547
+ *
548
+ * This intentionally does not inspect discovery metadata or device
549
+ * capabilities. Those fields describe the remote endpoint roster entry; they
550
+ * are not proof that an application-level protocol has exchanged its own
551
+ * ready/capability message over the mesh.
552
+ */
553
+ declare function isRuntimeDeviceRoutable(device: RuntimeDeviceRouteStatus): boolean;
554
+ /**
555
+ * True when the discovery row currently has enough fresh presence to attempt
556
+ * a dial. This is a discovery gate, not a connected/readiness gate.
557
+ */
558
+ declare function isRuntimeDeviceConnectable(device: RuntimeDevicePresenceStatus): boolean;
559
+
560
+ export { isRuntimeDeviceActive as $, type PeerReadiness as A, type PeerStreamOptions as B, Connection as C, type DeviceProfile as D, type PresenceLoopOptions as E, type RawConnection as F, type RuntimeAuthContext as G, type RuntimeAuthIdentity as H, type ITransport as I, type RuntimeAutoConnectPolicy as J, type RuntimeConnectionTarget as K, type RuntimeDevicePresenceStatus$1 as L, type RuntimeDeviceStatus as M, type RuntimeLogicalChannelFraming as N, type RuntimeManagedSessionKind as O, type PeerConnectOptions as P, type RuntimeManagedSessionPlatform as Q, type RuntimeClientOptions as R, type RuntimePeerLifecycleStatus as S, type RuntimePeerScope as T, type RuntimePeerSessionSnapshot as U, type RuntimePresenceLoopOptions as V, type RuntimePresencePolicy as W, type RuntimeSession as X, type RuntimeUiConnectionStatus as Y, type ScopedChannelOptions as Z, type ScopedLogicalChannel as _, type RuntimeManagedSessionOptions as a, isRuntimeDeviceConnectable as a0, isRuntimeDeviceRoutable as a1, type RuntimeDeviceActiveOptions as a2, type Session as a3, type SessionOptions as a4, type RuntimeManagedSession as b, type RuntimeDevice as c, type RuntimeDeviceStatusSnapshot as d, type RuntimeDeviceConnectOptions as e, type RuntimeLocalDeviceInfo as f, type RuntimeLocalDeviceProfile as g, type RuntimePeerState as h, type RuntimePeerConnectOptions as i, type RuntimePeerReadinessSnapshot as j, type RuntimePeerHealth as k, type RuntimeChannelDescriptor as l, type RuntimePeerStreamOptions as m, type RuntimeIncomingStream as n, type RuntimeScopedChannelOptions as o, type RuntimeScopedLogicalChannel as p, type RuntimeJoinRoomOptions as q, type RuntimeRoomMember as r, type RuntimeConnectionStateSnapshot as s, type RuntimeApplicationPayloadReadinessOptions as t, type RuntimeConnectionEvent as u, type RuntimeRawConnection as v, type ChannelDescriptor as w, type ConnectionEvent as x, type ConnectionTarget as y, type IncomingStream as z };