openrtc 0.1.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 (122) hide show
  1. package/README.md +106 -0
  2. package/dist/OpenRTC.d.ts +71 -0
  3. package/dist/OpenRTC.js +130 -0
  4. package/dist/api/MediaTransport.d.ts +7 -0
  5. package/dist/api/MediaTransport.js +262 -0
  6. package/dist/api/PlutoPeerConnection.d.ts +50 -0
  7. package/dist/api/PlutoPeerConnection.js +434 -0
  8. package/dist/api/PlutoWebSocket.d.ts +24 -0
  9. package/dist/api/PlutoWebSocket.js +113 -0
  10. package/dist/api/PlutoWebTransport.d.ts +29 -0
  11. package/dist/api/PlutoWebTransport.js +105 -0
  12. package/dist/auth/host.d.ts +73 -0
  13. package/dist/auth/host.js +513 -0
  14. package/dist/auth/index.d.ts +1 -0
  15. package/dist/auth/index.js +1 -0
  16. package/dist/auth/internal.d.ts +1 -0
  17. package/dist/auth/internal.js +1 -0
  18. package/dist/compat/index.d.ts +20 -0
  19. package/dist/compat/index.js +20 -0
  20. package/dist/core/Client.d.ts +352 -0
  21. package/dist/core/Client.js +3689 -0
  22. package/dist/core/Connection.d.ts +67 -0
  23. package/dist/core/Connection.js +404 -0
  24. package/dist/core/IEngineBridge.d.ts +18 -0
  25. package/dist/core/IEngineBridge.js +1 -0
  26. package/dist/core/ISignalingTransport.d.ts +13 -0
  27. package/dist/core/ISignalingTransport.js +1 -0
  28. package/dist/core/PeerLifecycleManager.d.ts +43 -0
  29. package/dist/core/PeerLifecycleManager.js +330 -0
  30. package/dist/core/PeerProjectionStore.d.ts +43 -0
  31. package/dist/core/PeerProjectionStore.js +327 -0
  32. package/dist/core/PlutoRTC.d.ts +13 -0
  33. package/dist/core/PlutoRTC.js +26 -0
  34. package/dist/core/Room.d.ts +47 -0
  35. package/dist/core/Room.js +376 -0
  36. package/dist/core/Signaling.d.ts +39 -0
  37. package/dist/core/Signaling.js +147 -0
  38. package/dist/core/bridges/BridgeCodecs.d.ts +19 -0
  39. package/dist/core/bridges/BridgeCodecs.js +317 -0
  40. package/dist/core/bridges/BrowserFirestoreRooms.d.ts +36 -0
  41. package/dist/core/bridges/BrowserFirestoreRooms.js +169 -0
  42. package/dist/core/bridges/BrowserFirestoreSignaling.d.ts +111 -0
  43. package/dist/core/bridges/BrowserFirestoreSignaling.js +1010 -0
  44. package/dist/core/bridges/NativeIpcBridge.d.ts +156 -0
  45. package/dist/core/bridges/NativeIpcBridge.js +1472 -0
  46. package/dist/core/bridges/RtdbPresence.d.ts +122 -0
  47. package/dist/core/bridges/RtdbPresence.js +201 -0
  48. package/dist/core/bridges/TauriBridge.d.ts +8 -0
  49. package/dist/core/bridges/TauriBridge.js +7 -0
  50. package/dist/core/bridges/WasmBridge.d.ts +233 -0
  51. package/dist/core/bridges/WasmBridge.js +1811 -0
  52. package/dist/core/config.d.ts +31 -0
  53. package/dist/core/config.js +138 -0
  54. package/dist/core/transports/ITransport.d.ts +12 -0
  55. package/dist/core/transports/ITransport.js +1 -0
  56. package/dist/core/transports/LocalDaemonBridge.d.ts +41 -0
  57. package/dist/core/transports/LocalDaemonBridge.js +227 -0
  58. package/dist/core/transports/TauriSignaling.d.ts +28 -0
  59. package/dist/core/transports/TauriSignaling.js +373 -0
  60. package/dist/core/transports/TransportFactory.d.ts +9 -0
  61. package/dist/core/transports/TransportFactory.js +59 -0
  62. package/dist/core/transports/WasmSignaling.d.ts +78 -0
  63. package/dist/core/transports/WasmSignaling.js +522 -0
  64. package/dist/core/transports/WebRTCTransport.d.ts +23 -0
  65. package/dist/core/transports/WebRTCTransport.js +132 -0
  66. package/dist/core/trust.d.ts +23 -0
  67. package/dist/core/trust.js +99 -0
  68. package/dist/core/types.d.ts +559 -0
  69. package/dist/core/types.js +19 -0
  70. package/dist/index.d.ts +3 -0
  71. package/dist/index.js +3 -0
  72. package/dist/moq/MoQMediaTransport.d.ts +6 -0
  73. package/dist/moq/MoQMediaTransport.js +106 -0
  74. package/dist/moq/MoQPublisher.d.ts +22 -0
  75. package/dist/moq/MoQPublisher.js +179 -0
  76. package/dist/moq/MoQSession.d.ts +35 -0
  77. package/dist/moq/MoQSession.js +166 -0
  78. package/dist/moq/MoQSubscriber.d.ts +19 -0
  79. package/dist/moq/MoQSubscriber.js +235 -0
  80. package/dist/moq/common.d.ts +47 -0
  81. package/dist/moq/common.js +304 -0
  82. package/dist/moq/messages.d.ts +105 -0
  83. package/dist/moq/messages.js +367 -0
  84. package/dist/presets/plutoHosted.d.ts +13 -0
  85. package/dist/presets/plutoHosted.js +18 -0
  86. package/dist/runtime/DelegatingRuntimeAdapter.d.ts +68 -0
  87. package/dist/runtime/DelegatingRuntimeAdapter.js +250 -0
  88. package/dist/runtime/IpcRuntimeAdapter.d.ts +9 -0
  89. package/dist/runtime/IpcRuntimeAdapter.js +13 -0
  90. package/dist/runtime/RuntimeClient.d.ts +257 -0
  91. package/dist/runtime/RuntimeClient.js +1484 -0
  92. package/dist/runtime/TauriRuntimeAdapter.d.ts +1 -0
  93. package/dist/runtime/TauriRuntimeAdapter.js +1 -0
  94. package/dist/runtime/WasmRuntimeAdapter.d.ts +6 -0
  95. package/dist/runtime/WasmRuntimeAdapter.js +11 -0
  96. package/dist/runtime/factories.d.ts +24 -0
  97. package/dist/runtime/factories.js +66 -0
  98. package/dist/runtime/index.d.ts +6 -0
  99. package/dist/runtime/index.js +5 -0
  100. package/dist/runtime/ipc.d.ts +8 -0
  101. package/dist/runtime/ipc.js +65 -0
  102. package/dist/runtime/ipcContract.d.ts +46 -0
  103. package/dist/runtime/ipcContract.js +1 -0
  104. package/dist/runtime/tauri.d.ts +16 -0
  105. package/dist/runtime/tauri.js +22 -0
  106. package/dist/runtime/types.d.ts +110 -0
  107. package/dist/runtime/types.js +1 -0
  108. package/dist/transports/TauriTransport.d.ts +17 -0
  109. package/dist/transports/TauriTransport.js +49 -0
  110. package/dist/transports/WebTransport.d.ts +23 -0
  111. package/dist/transports/WebTransport.js +71 -0
  112. package/dist/utils/debug.d.ts +4 -0
  113. package/dist/utils/debug.js +33 -0
  114. package/dist/utils/runtime.d.ts +1 -0
  115. package/dist/utils/runtime.js +10 -0
  116. package/package.json +97 -0
  117. package/wasm/README.md +64 -0
  118. package/wasm/openrtc.d.ts +284 -0
  119. package/wasm/openrtc.js +2132 -0
  120. package/wasm/openrtc_bg.wasm +0 -0
  121. package/wasm/openrtc_bg.wasm.d.ts +110 -0
  122. package/wasm/package.json +16 -0
@@ -0,0 +1 @@
1
+ export { TauriRuntimeAdapter, createTauriIpcBridge, type TauriRuntimeAdapterOptions, } from './tauri';
@@ -0,0 +1 @@
1
+ export { TauriRuntimeAdapter, createTauriIpcBridge, } from './tauri';
@@ -0,0 +1,6 @@
1
+ import { type WasmBridgeOptions } from '../core/bridges/WasmBridge';
2
+ import { DelegatingRuntimeAdapter } from './DelegatingRuntimeAdapter';
3
+ export declare class WasmRuntimeAdapter extends DelegatingRuntimeAdapter {
4
+ constructor(options: WasmBridgeOptions);
5
+ setWasmClient(client: unknown): void;
6
+ }
@@ -0,0 +1,11 @@
1
+ import { WasmBridge } from '../core/bridges/WasmBridge';
2
+ import { DelegatingRuntimeAdapter } from './DelegatingRuntimeAdapter';
3
+ export class WasmRuntimeAdapter extends DelegatingRuntimeAdapter {
4
+ constructor(options) {
5
+ super(new WasmBridge(options));
6
+ }
7
+ setWasmClient(client) {
8
+ const backend = this.unwrap();
9
+ backend.setWasmClient(client);
10
+ }
11
+ }
@@ -0,0 +1,24 @@
1
+ import type { AuthContext } from '../core/IEngineBridge';
2
+ import { type ClientOptions, type ISignalingBackend } from '../core/types';
3
+ import { RuntimeClient } from './RuntimeClient';
4
+ import { IpcRuntimeAdapter } from './IpcRuntimeAdapter';
5
+ import { WasmRuntimeAdapter } from './WasmRuntimeAdapter';
6
+ import type { PlutoIpcBridge } from './ipc';
7
+ type RuntimeAdapterWithAuth = ISignalingBackend & {
8
+ setAuthContext?: (context: AuthContext | null) => Promise<void> | void;
9
+ };
10
+ export type RuntimeFactoryOptions = ClientOptions;
11
+ export interface PlutoRuntimeAssembly<TBackend extends RuntimeAdapterWithAuth = RuntimeAdapterWithAuth> {
12
+ runtime: RuntimeClient;
13
+ setAuthContext(context: AuthContext | null): Promise<void>;
14
+ syncPlutoAuth(options?: {
15
+ userId?: string | null;
16
+ forceRefresh?: boolean;
17
+ }): Promise<void>;
18
+ bindPlutoAuthHost(): () => void;
19
+ signInWithPluto(): Promise<void>;
20
+ signOut(): Promise<void>;
21
+ }
22
+ export declare function createWasmClient(options: RuntimeFactoryOptions): PlutoRuntimeAssembly<WasmRuntimeAdapter>;
23
+ export declare function createIpcClient(options: RuntimeFactoryOptions, bridge: PlutoIpcBridge): PlutoRuntimeAssembly<IpcRuntimeAdapter>;
24
+ export {};
@@ -0,0 +1,66 @@
1
+ import { getAuthHost } from '../auth/host';
2
+ import { withPlutoHostedDefaults } from '../presets/plutoHosted';
3
+ import { RuntimeClient } from './RuntimeClient';
4
+ import { IpcRuntimeAdapter } from './IpcRuntimeAdapter';
5
+ import { WasmRuntimeAdapter } from './WasmRuntimeAdapter';
6
+ function createAssembly(options, backend) {
7
+ const runtime = new RuntimeClient(options, backend);
8
+ const assembly = {
9
+ runtime,
10
+ async setAuthContext(context) {
11
+ if (typeof backend.setAuthContext !== 'function') {
12
+ throw new Error('Selected runtime adapter does not support auth context injection.');
13
+ }
14
+ await backend.setAuthContext(context);
15
+ },
16
+ async syncPlutoAuth(syncOptions) {
17
+ const authHost = getAuthHost();
18
+ const currentUser = authHost.getCurrentUser();
19
+ const explicitUserId = typeof syncOptions?.userId === 'string' ? syncOptions.userId.trim() : '';
20
+ const userId = explicitUserId || currentUser?.uid || null;
21
+ if (!userId) {
22
+ await assembly.setAuthContext(null);
23
+ return;
24
+ }
25
+ const token = await authHost.getIdToken({
26
+ forceRefresh: syncOptions?.forceRefresh ?? false,
27
+ }).catch(() => null);
28
+ const refreshToken = (authHost.getCurrentUser()?.refreshToken) ?? null;
29
+ const expiresAtMs = (authHost.getCurrentUser()?.stsTokenManager?.expirationTime) ?? null;
30
+ await assembly.setAuthContext({
31
+ userId,
32
+ token,
33
+ refreshToken,
34
+ tokenProvider: async (forceRefresh) => authHost.getIdToken({ forceRefresh: forceRefresh ?? true }),
35
+ expiresAtMs,
36
+ });
37
+ },
38
+ bindPlutoAuthHost() {
39
+ const authHost = getAuthHost();
40
+ void assembly.syncPlutoAuth({
41
+ userId: authHost.getCurrentUser()?.uid ?? null,
42
+ forceRefresh: false,
43
+ });
44
+ return authHost.onIdTokenChanged((user) => {
45
+ void assembly.syncPlutoAuth({
46
+ userId: user?.uid ?? null,
47
+ forceRefresh: false,
48
+ });
49
+ });
50
+ },
51
+ signInWithPluto: () => runtime.signInWithPluto(),
52
+ signOut: () => runtime.signOut(),
53
+ };
54
+ return assembly;
55
+ }
56
+ export function createWasmClient(options) {
57
+ const normalizedOptions = withPlutoHostedDefaults(options);
58
+ return createAssembly(normalizedOptions, new WasmRuntimeAdapter(normalizedOptions));
59
+ }
60
+ export function createIpcClient(options, bridge) {
61
+ const normalizedOptions = withPlutoHostedDefaults(options);
62
+ return createAssembly(normalizedOptions, new IpcRuntimeAdapter({
63
+ ...normalizedOptions,
64
+ bridge,
65
+ }));
66
+ }
@@ -0,0 +1,6 @@
1
+ export { RuntimeClient } from './RuntimeClient';
2
+ export * from './types';
3
+ export * from './factories';
4
+ export * from './IpcRuntimeAdapter';
5
+ export * from './WasmRuntimeAdapter';
6
+ export type { PlutoIpcBridge, PlutoIpcUnlisten, PlutoIpcBridge as NativeBridge } from './ipc';
@@ -0,0 +1,5 @@
1
+ export { RuntimeClient } from './RuntimeClient';
2
+ export * from './types';
3
+ export * from './factories';
4
+ export * from './IpcRuntimeAdapter';
5
+ export * from './WasmRuntimeAdapter';
@@ -0,0 +1,8 @@
1
+ export type PlutoIpcUnlisten = () => void | Promise<void>;
2
+ export interface PlutoIpcBridge {
3
+ invoke<T = unknown>(command: string, args?: Record<string, unknown>): Promise<T>;
4
+ listen<T = unknown>(event: string, handler: (payload: T) => void): Promise<PlutoIpcUnlisten>;
5
+ isAvailable?(): boolean | Promise<boolean>;
6
+ }
7
+ export declare function assertValidIpcBridge(bridge: PlutoIpcBridge | null | undefined, context?: string): PlutoIpcBridge;
8
+ export declare function createCompatTauriIpcBridge(): PlutoIpcBridge;
@@ -0,0 +1,65 @@
1
+ export function assertValidIpcBridge(bridge, context = 'native runtime') {
2
+ if (!bridge || typeof bridge !== 'object') {
3
+ throw new Error(`[openrtc] ${context} requires a valid IPC bridge object.`);
4
+ }
5
+ if (typeof bridge.invoke !== 'function') {
6
+ throw new Error(`[openrtc] ${context} IPC bridge is missing invoke(command, args).`);
7
+ }
8
+ if (typeof bridge.listen !== 'function') {
9
+ throw new Error(`[openrtc] ${context} IPC bridge is missing listen(event, handler).`);
10
+ }
11
+ return bridge;
12
+ }
13
+ let tauriAdapterModulePromise = null;
14
+ async function loadTauriAdapterModule() {
15
+ if (!tauriAdapterModulePromise) {
16
+ tauriAdapterModulePromise = (async () => {
17
+ const packageSpecifier = 'openrtc-tauri';
18
+ const workspaceSpecifier = '../../../tauri/src/runtime/ipc';
19
+ try {
20
+ return await import(/* @vite-ignore */ packageSpecifier);
21
+ }
22
+ catch (packageError) {
23
+ try {
24
+ return await import(/* @vite-ignore */ workspaceSpecifier);
25
+ }
26
+ catch (workspaceError) {
27
+ const error = new Error('[openrtc] Native support now lives in the first-party `openrtc-tauri` package. ' +
28
+ 'Install `openrtc-tauri` (and `@tauri-apps/api`) or pass an explicit IPC bridge to OpenRTC.native(...).');
29
+ error.cause = {
30
+ packageError,
31
+ workspaceError,
32
+ };
33
+ throw error;
34
+ }
35
+ }
36
+ })();
37
+ }
38
+ return tauriAdapterModulePromise;
39
+ }
40
+ export function createCompatTauriIpcBridge() {
41
+ let delegatePromise = null;
42
+ const getDelegate = async () => {
43
+ if (!delegatePromise) {
44
+ delegatePromise = loadTauriAdapterModule().then((mod) => assertValidIpcBridge(mod.createTauriIpcBridge(), 'openrtc-tauri'));
45
+ }
46
+ return delegatePromise;
47
+ };
48
+ return {
49
+ async invoke(command, args) {
50
+ return (await getDelegate()).invoke(command, args);
51
+ },
52
+ async listen(event, handler) {
53
+ return (await getDelegate()).listen(event, handler);
54
+ },
55
+ async isAvailable() {
56
+ try {
57
+ const bridge = await getDelegate();
58
+ return typeof bridge.isAvailable === 'function' ? !!(await bridge.isAvailable()) : true;
59
+ }
60
+ catch {
61
+ return false;
62
+ }
63
+ },
64
+ };
65
+ }
@@ -0,0 +1,46 @@
1
+ export interface NativeRtcIpcCommandMap {
2
+ nativeStatus: string;
3
+ signInWithPluto: string;
4
+ setAuthToken: string;
5
+ stopPresenceLoop: string;
6
+ stopAutoConnect: string;
7
+ setOffline: string;
8
+ searchDevices: string;
9
+ searchDevicesWithStatus: string;
10
+ getPeerSession: string;
11
+ listPeerSessions: string;
12
+ waitForSettledPeer: string;
13
+ resolvePeerConnectionRecords: string;
14
+ resolvePeerIdentity: string;
15
+ updateDevice: string;
16
+ deleteDevice: string;
17
+ getLocalDeviceInfo: string;
18
+ updateLocalDeviceName: string;
19
+ getManagedNodeId: string;
20
+ startManagedNode: string;
21
+ getEndpointTicket: string;
22
+ connectToDevice: string;
23
+ disconnectDevice: string;
24
+ setAutoConnectExcluded: string;
25
+ startDeviceSubscription: string;
26
+ startSessionSubscription: string;
27
+ stopSubscription: string;
28
+ updatePresence: string;
29
+ startAutoConnect: string;
30
+ forceReconnectSnapshot: string;
31
+ startPresenceLoop: string;
32
+ sendFile: string;
33
+ sendFileData: string;
34
+ listConnectionStates: string;
35
+ getTransferHistory: string;
36
+ deleteTransferJob: string;
37
+ }
38
+ export interface NativeRtcIpcEventMap {
39
+ deviceEvents: string;
40
+ sessionEvents: string;
41
+ connectionStateChanged: string;
42
+ }
43
+ export interface NativeRtcIpcContract {
44
+ commands: NativeRtcIpcCommandMap;
45
+ events: NativeRtcIpcEventMap;
46
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import type { TauriBridgeOptions } from '../core/bridges/TauriBridge';
2
+ import { IpcRuntimeAdapter } from './IpcRuntimeAdapter';
3
+ import { type PlutoIpcBridge } from './ipc';
4
+ /**
5
+ * @deprecated Native Tauri support now lives in the first-party `openrtc-tauri` package.
6
+ * This shim remains for one compatibility cycle.
7
+ */
8
+ export declare function createTauriIpcBridge(): PlutoIpcBridge;
9
+ /**
10
+ * @deprecated Native Tauri support now lives in the first-party `openrtc-tauri` package.
11
+ * This shim remains for one compatibility cycle.
12
+ */
13
+ export declare class TauriRuntimeAdapter extends IpcRuntimeAdapter {
14
+ constructor(options: TauriBridgeOptions);
15
+ }
16
+ export type TauriRuntimeAdapterOptions = TauriBridgeOptions;
@@ -0,0 +1,22 @@
1
+ import { IpcRuntimeAdapter } from './IpcRuntimeAdapter';
2
+ import { createCompatTauriIpcBridge } from './ipc';
3
+ /**
4
+ * @deprecated Native Tauri support now lives in the first-party `openrtc-tauri` package.
5
+ * This shim remains for one compatibility cycle.
6
+ */
7
+ export function createTauriIpcBridge() {
8
+ return createCompatTauriIpcBridge();
9
+ }
10
+ /**
11
+ * @deprecated Native Tauri support now lives in the first-party `openrtc-tauri` package.
12
+ * This shim remains for one compatibility cycle.
13
+ */
14
+ export class TauriRuntimeAdapter extends IpcRuntimeAdapter {
15
+ constructor(options) {
16
+ super({
17
+ ...options,
18
+ bridge: createCompatTauriIpcBridge(),
19
+ allowWasmFallback: options.allowWasmFallback ?? false,
20
+ });
21
+ }
22
+ }
@@ -0,0 +1,110 @@
1
+ import type { AuthContext } from '../core/IEngineBridge';
2
+ import type { BackendConnectionState, ChannelDescriptor as CoreChannelDescriptor, ClientOptions, DeviceStatusSnapshot, Device, IncomingStreamChannelMetadata, LocalDeviceInfo, ManagedDeviceConnectOptions, PeerSessionSnapshot, PeerHealth, PeerLifecycleStatus, PeerScope, PeerState, RoomMember, RuntimeIdentity, SignalingSession, JoinRoomOptions } from '../core/types';
3
+ export type RuntimeClientOptions = ClientOptions;
4
+ export type RuntimeDevice = Device;
5
+ export type RuntimeSession = SignalingSession;
6
+ export type RuntimeAuthIdentity = RuntimeIdentity;
7
+ export type RuntimeAuthContext = AuthContext;
8
+ export type RuntimePeerState = PeerState;
9
+ export type RuntimePeerHealth = PeerHealth;
10
+ export type RuntimePeerLifecycleStatus = PeerLifecycleStatus;
11
+ export type RuntimePeerScope = PeerScope;
12
+ export type RuntimePeerSessionSnapshot = PeerSessionSnapshot;
13
+ export type RuntimeLocalDeviceInfo = LocalDeviceInfo;
14
+ export type RuntimeRoomMember = RoomMember;
15
+ export type RuntimeDeviceConnectOptions = ManagedDeviceConnectOptions;
16
+ export type RuntimeJoinRoomOptions = JoinRoomOptions;
17
+ export type RuntimeChannelDescriptor = CoreChannelDescriptor;
18
+ export interface RuntimeConnectionTarget {
19
+ ticket: string;
20
+ timeoutMs?: number;
21
+ }
22
+ export interface RuntimePeerConnectOptions {
23
+ deviceId?: string;
24
+ ticket?: string;
25
+ scope?: RuntimePeerScope;
26
+ channelId?: string;
27
+ }
28
+ export interface RuntimePeerStreamOptions {
29
+ ticket?: string;
30
+ scope?: RuntimePeerScope;
31
+ channelId?: string;
32
+ timeoutMs?: number;
33
+ }
34
+ export type RuntimeDeviceStatusSnapshot = DeviceStatusSnapshot;
35
+ export type RuntimeDeviceStatus = RuntimeDeviceStatusSnapshot;
36
+ export type RuntimeIncomingStream = {
37
+ type: 'bi' | 'uni';
38
+ stream: any;
39
+ remoteNodeId: string;
40
+ protocolHint?: 'control' | 'explicit' | 'native-main' | 'unknown';
41
+ channel?: IncomingStreamChannelMetadata | null;
42
+ };
43
+ export type RuntimeConnectionEvent = {
44
+ type: 'connected' | 'disconnected';
45
+ connectionId: string;
46
+ localNodeId: string;
47
+ remoteNodeId: string;
48
+ transport: 'iroh' | 'webrtc' | 'moq';
49
+ };
50
+ export type RuntimeRawConnection = {
51
+ connectionId: string;
52
+ localNodeId: string;
53
+ remoteNodeId: string;
54
+ };
55
+ export type RuntimePresenceLoopOptions = {
56
+ deviceName?: string;
57
+ ticket?: string;
58
+ metadata?: string;
59
+ };
60
+ export type RuntimeManagedSessionPlatform = 'native' | 'web';
61
+ export type RuntimeConnectionStateSnapshot = BackendConnectionState;
62
+ export type RuntimeUiConnectionStatus = 'connecting' | 'connected' | 'disconnected' | 'failed';
63
+ export interface RuntimePeerReadinessSnapshot {
64
+ requestedId: string;
65
+ connected: boolean;
66
+ settledReady: boolean;
67
+ status: RuntimeUiConnectionStatus;
68
+ health: RuntimePeerHealth | 'unknown';
69
+ deviceId?: string | null;
70
+ deviceIdHint?: string | null;
71
+ activeConnectionId?: string | null;
72
+ readinessState?: string;
73
+ readinessReason?: string;
74
+ scopes: string[];
75
+ }
76
+ export interface RuntimeLocalDeviceProfile {
77
+ deviceId: string | null;
78
+ deviceName: string;
79
+ platformType: string;
80
+ userId: string | null;
81
+ capabilities: NonNullable<RuntimeLocalDeviceInfo['capabilities']>;
82
+ lastSeenAt: string;
83
+ localNodeId?: string | null;
84
+ }
85
+ export interface RuntimeManagedSessionOptions {
86
+ platform: RuntimeManagedSessionPlatform;
87
+ userId?: string | null;
88
+ deviceName?: string;
89
+ localDeviceId?: string | null;
90
+ metadata?: string;
91
+ autoConnect?: boolean;
92
+ presence?: boolean;
93
+ }
94
+ export interface RuntimeManagedSession {
95
+ mode: RuntimeManagedSessionPlatform;
96
+ device: RuntimeLocalDeviceProfile;
97
+ stop: () => Promise<void>;
98
+ }
99
+ export type ConnectionTarget = RuntimeConnectionTarget;
100
+ export type PeerConnectOptions = RuntimePeerConnectOptions;
101
+ export type PeerStreamOptions = RuntimePeerStreamOptions;
102
+ export type IncomingStream = RuntimeIncomingStream;
103
+ export type ConnectionEvent = RuntimeConnectionEvent;
104
+ export type RawConnection = RuntimeRawConnection;
105
+ export type PresenceLoopOptions = RuntimePresenceLoopOptions;
106
+ export type PeerReadiness = RuntimePeerReadinessSnapshot;
107
+ export type DeviceProfile = RuntimeLocalDeviceProfile;
108
+ export type SessionOptions = RuntimeManagedSessionOptions;
109
+ export type Session = RuntimeManagedSession;
110
+ export type ChannelDescriptor = RuntimeChannelDescriptor;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { Device, SignalingSession } from '../core/types';
2
+ import type { AuthContext, IEngineBridge } from '../core/IEngineBridge';
3
+ export declare class TauriTransport implements IEngineBridge {
4
+ private readonly backend;
5
+ constructor(options: {
6
+ apiKey?: string;
7
+ authMode?: 'external' | 'anonymous' | 'required';
8
+ storagePrefix?: string;
9
+ });
10
+ setAuthContext(context: AuthContext | null): void;
11
+ searchDevices(excludeNodeId?: string): Promise<Device[]>;
12
+ onDevicesChange(callback: (devices: Device[]) => void, excludeNodeId?: string): () => void;
13
+ subscribeSessions(localDeviceId: string, callback: (session: SignalingSession) => void): Promise<() => void>;
14
+ updatePresence(localNodeId: string, ticket: string, isOnline?: boolean, ttlMs?: number, metadata?: string): Promise<void>;
15
+ setOffline(localNodeId: string): Promise<void>;
16
+ forceReconnectSnapshot(): void;
17
+ }
@@ -0,0 +1,49 @@
1
+ import { TauriBridge } from '../core/bridges/TauriBridge';
2
+ export class TauriTransport {
3
+ constructor(options) {
4
+ this.backend = new TauriBridge({
5
+ apiKey: options.apiKey,
6
+ authMode: options.authMode,
7
+ storagePrefix: options.storagePrefix,
8
+ });
9
+ }
10
+ setAuthContext(context) {
11
+ this.backend.setAuthContext(context);
12
+ }
13
+ async searchDevices(excludeNodeId) {
14
+ return this.backend.searchDevices(excludeNodeId);
15
+ }
16
+ onDevicesChange(callback, excludeNodeId) {
17
+ return this.backend.onDevicesChange(callback, excludeNodeId);
18
+ }
19
+ async subscribeSessions(localDeviceId, callback) {
20
+ const stream = await this.backend.subscribeSessions(localDeviceId);
21
+ const reader = stream.getReader();
22
+ let cancelled = false;
23
+ void (async () => {
24
+ while (!cancelled) {
25
+ const { done, value } = await reader.read();
26
+ if (done || !value)
27
+ break;
28
+ for (const event of value) {
29
+ if ('session' in event && event.session) {
30
+ callback(event.session);
31
+ }
32
+ }
33
+ }
34
+ })();
35
+ return () => {
36
+ cancelled = true;
37
+ void reader.cancel();
38
+ };
39
+ }
40
+ async updatePresence(localNodeId, ticket, isOnline = true, ttlMs = 300000, metadata) {
41
+ await this.backend.updatePresence(localNodeId, ticket, isOnline, ttlMs, metadata);
42
+ }
43
+ async setOffline(localNodeId) {
44
+ await this.backend.setOffline(localNodeId);
45
+ }
46
+ forceReconnectSnapshot() {
47
+ this.backend.forceReconnectSnapshot();
48
+ }
49
+ }
@@ -0,0 +1,23 @@
1
+ import type { Device, SignalingSession } from '../core/types.js';
2
+ import type { AuthContext, IEngineBridge } from '../core/IEngineBridge.js';
3
+ export declare class WebTransport implements IEngineBridge {
4
+ private readonly options;
5
+ private readonly backend;
6
+ private readonly appTag;
7
+ private readonly projectId;
8
+ private wasmClient;
9
+ constructor(options: {
10
+ apiKey?: string;
11
+ authMode?: 'external' | 'anonymous' | 'required';
12
+ storagePrefix?: string;
13
+ projectId?: string;
14
+ });
15
+ initialize(): Promise<void>;
16
+ setAuthContext(context: AuthContext | null): Promise<void>;
17
+ searchDevices(excludeNodeId?: string): Promise<Device[]>;
18
+ onDevicesChange(callback: (devices: Device[]) => void, excludeNodeId?: string): () => void;
19
+ subscribeSessions(localDeviceId: string, callback: (session: SignalingSession) => void): Promise<() => void>;
20
+ updatePresence(localNodeId: string, ticket: string, isOnline?: boolean, ttlMs?: number, metadata?: string): Promise<void>;
21
+ setOffline(localNodeId: string): Promise<void>;
22
+ forceReconnectSnapshot(): void;
23
+ }
@@ -0,0 +1,71 @@
1
+ import initWasm, { WasmClient, start } from '../../wasm/openrtc.js';
2
+ import { WasmBridge } from '../core/bridges/WasmBridge.js';
3
+ import { resolveAppTag, resolveProjectId } from '../core/config.js';
4
+ export class WebTransport {
5
+ constructor(options) {
6
+ this.options = options;
7
+ this.wasmClient = null;
8
+ this.appTag = resolveAppTag(options);
9
+ this.projectId = resolveProjectId(options);
10
+ this.backend = new WasmBridge({
11
+ apiKey: options.apiKey,
12
+ authMode: options.authMode,
13
+ projectId: this.projectId,
14
+ storagePrefix: options.storagePrefix,
15
+ });
16
+ }
17
+ async initialize() {
18
+ if (this.wasmClient)
19
+ return;
20
+ await initWasm();
21
+ start();
22
+ this.wasmClient = new WasmClient(this.projectId, this.appTag);
23
+ this.backend.setWasmClient(this.wasmClient);
24
+ }
25
+ async setAuthContext(context) {
26
+ await this.initialize();
27
+ this.backend.setAuthContext(context);
28
+ }
29
+ async searchDevices(excludeNodeId) {
30
+ await this.initialize();
31
+ return this.backend.searchDevices(excludeNodeId);
32
+ }
33
+ onDevicesChange(callback, excludeNodeId) {
34
+ void this.initialize();
35
+ return this.backend.onDevicesChange(callback, excludeNodeId);
36
+ }
37
+ async subscribeSessions(localDeviceId, callback) {
38
+ await this.initialize();
39
+ const stream = await this.backend.subscribeSessions(localDeviceId);
40
+ const reader = stream.getReader();
41
+ let cancelled = false;
42
+ void (async () => {
43
+ while (!cancelled) {
44
+ const { done, value } = await reader.read();
45
+ if (done || !value)
46
+ break;
47
+ for (const event of value) {
48
+ if ('session' in event && event.session) {
49
+ callback(event.session);
50
+ }
51
+ }
52
+ }
53
+ })();
54
+ return () => {
55
+ cancelled = true;
56
+ void reader.cancel();
57
+ };
58
+ }
59
+ async updatePresence(localNodeId, ticket, isOnline = true, ttlMs = 300000, metadata) {
60
+ await this.initialize();
61
+ await this.backend.updatePresence(localNodeId, ticket, isOnline, ttlMs, metadata);
62
+ }
63
+ async setOffline(localNodeId) {
64
+ await this.initialize();
65
+ await this.backend.setOffline(localNodeId);
66
+ }
67
+ forceReconnectSnapshot() {
68
+ void this.initialize();
69
+ this.backend.forceReconnectSnapshot();
70
+ }
71
+ }
@@ -0,0 +1,4 @@
1
+ export declare function openRtcDebugEnabled(): boolean;
2
+ export declare function openRtcDebug(message: string, data?: unknown): void;
3
+ export declare function openRtcDebugInfo(message: string, data?: unknown): void;
4
+ export declare function openRtcDebugLog(message: string, data?: unknown): void;
@@ -0,0 +1,33 @@
1
+ export function openRtcDebugEnabled() {
2
+ if (typeof globalThis !== 'undefined' && globalThis.__OPENRTC_DEBUG__ === true) {
3
+ return true;
4
+ }
5
+ if (typeof localStorage !== 'undefined') {
6
+ try {
7
+ return localStorage.getItem('openrtc:debug') === '1';
8
+ }
9
+ catch {
10
+ return false;
11
+ }
12
+ }
13
+ return false;
14
+ }
15
+ function emit(method, message, data) {
16
+ if (!openRtcDebugEnabled()) {
17
+ return;
18
+ }
19
+ if (typeof data === 'undefined') {
20
+ console[method](message);
21
+ return;
22
+ }
23
+ console[method](message, data);
24
+ }
25
+ export function openRtcDebug(message, data) {
26
+ emit('debug', message, data);
27
+ }
28
+ export function openRtcDebugInfo(message, data) {
29
+ emit('info', message, data);
30
+ }
31
+ export function openRtcDebugLog(message, data) {
32
+ emit('log', message, data);
33
+ }
@@ -0,0 +1 @@
1
+ export declare function isTauriEnvironment(): boolean;
@@ -0,0 +1,10 @@
1
+ export function isTauriEnvironment() {
2
+ if (typeof window === 'undefined') {
3
+ return false;
4
+ }
5
+ return !!(window.__TAURI_IPC__ ||
6
+ window.__TAURI_INTERNALS__ ||
7
+ window.__TAURI__ ||
8
+ window.location.protocol === 'tauri:' ||
9
+ window.location.hostname === 'tauri.localhost');
10
+ }