@ringg/react-native 0.0.1-alpha.10

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 (112) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +250 -0
  3. package/app.plugin.js +51 -0
  4. package/lib/module/adapters/index.js +4 -0
  5. package/lib/module/adapters/index.js.map +1 -0
  6. package/lib/module/adapters/livekit-rn-adapter.js +216 -0
  7. package/lib/module/adapters/livekit-rn-adapter.js.map +1 -0
  8. package/lib/module/components/RinggWidget.js +554 -0
  9. package/lib/module/components/RinggWidget.js.map +1 -0
  10. package/lib/module/components/steps/ButtonsStep.js +146 -0
  11. package/lib/module/components/steps/ButtonsStep.js.map +1 -0
  12. package/lib/module/components/steps/CalendarStep.js +190 -0
  13. package/lib/module/components/steps/CalendarStep.js.map +1 -0
  14. package/lib/module/components/steps/ConfirmationStep.js +175 -0
  15. package/lib/module/components/steps/ConfirmationStep.js.map +1 -0
  16. package/lib/module/components/steps/FormStep.js +346 -0
  17. package/lib/module/components/steps/FormStep.js.map +1 -0
  18. package/lib/module/components/steps/InteractiveFlow.js +249 -0
  19. package/lib/module/components/steps/InteractiveFlow.js.map +1 -0
  20. package/lib/module/components/ui/ActionButton.js +92 -0
  21. package/lib/module/components/ui/ActionButton.js.map +1 -0
  22. package/lib/module/components/ui/CallControls.js +168 -0
  23. package/lib/module/components/ui/CallControls.js.map +1 -0
  24. package/lib/module/components/ui/FeedbackScreen.js +180 -0
  25. package/lib/module/components/ui/FeedbackScreen.js.map +1 -0
  26. package/lib/module/components/ui/Icons.js +294 -0
  27. package/lib/module/components/ui/Icons.js.map +1 -0
  28. package/lib/module/components/ui/MessageBubble.js +80 -0
  29. package/lib/module/components/ui/MessageBubble.js.map +1 -0
  30. package/lib/module/components/ui/TabSelector.js +80 -0
  31. package/lib/module/components/ui/TabSelector.js.map +1 -0
  32. package/lib/module/components/ui/WidgetHeader.js +168 -0
  33. package/lib/module/components/ui/WidgetHeader.js.map +1 -0
  34. package/lib/module/context/RinggProvider.js +134 -0
  35. package/lib/module/context/RinggProvider.js.map +1 -0
  36. package/lib/module/context/index.js +4 -0
  37. package/lib/module/context/index.js.map +1 -0
  38. package/lib/module/globals.d.js +2 -0
  39. package/lib/module/globals.d.js.map +1 -0
  40. package/lib/module/hooks/index.js +10 -0
  41. package/lib/module/hooks/index.js.map +1 -0
  42. package/lib/module/hooks/useRinggCall.js +259 -0
  43. package/lib/module/hooks/useRinggCall.js.map +1 -0
  44. package/lib/module/hooks/useRinggChat.js +141 -0
  45. package/lib/module/hooks/useRinggChat.js.map +1 -0
  46. package/lib/module/hooks/useRinggComponents.js +236 -0
  47. package/lib/module/hooks/useRinggComponents.js.map +1 -0
  48. package/lib/module/hooks/useRinggFeedback.js +66 -0
  49. package/lib/module/hooks/useRinggFeedback.js.map +1 -0
  50. package/lib/module/hooks/useRinggTheme.js +39 -0
  51. package/lib/module/hooks/useRinggTheme.js.map +1 -0
  52. package/lib/module/hooks/useRinggTranscripts.js +70 -0
  53. package/lib/module/hooks/useRinggTranscripts.js.map +1 -0
  54. package/lib/module/hooks/useRinggWidgetState.js +51 -0
  55. package/lib/module/hooks/useRinggWidgetState.js.map +1 -0
  56. package/lib/module/index.js +56 -0
  57. package/lib/module/index.js.map +1 -0
  58. package/lib/module/package.json +1 -0
  59. package/lib/typescript/adapters/index.d.ts +2 -0
  60. package/lib/typescript/adapters/index.d.ts.map +1 -0
  61. package/lib/typescript/adapters/livekit-rn-adapter.d.ts +38 -0
  62. package/lib/typescript/adapters/livekit-rn-adapter.d.ts.map +1 -0
  63. package/lib/typescript/components/RinggWidget.d.ts +44 -0
  64. package/lib/typescript/components/RinggWidget.d.ts.map +1 -0
  65. package/lib/typescript/components/steps/ButtonsStep.d.ts +17 -0
  66. package/lib/typescript/components/steps/ButtonsStep.d.ts.map +1 -0
  67. package/lib/typescript/components/steps/CalendarStep.d.ts +16 -0
  68. package/lib/typescript/components/steps/CalendarStep.d.ts.map +1 -0
  69. package/lib/typescript/components/steps/ConfirmationStep.d.ts +16 -0
  70. package/lib/typescript/components/steps/ConfirmationStep.d.ts.map +1 -0
  71. package/lib/typescript/components/steps/FormStep.d.ts +17 -0
  72. package/lib/typescript/components/steps/FormStep.d.ts.map +1 -0
  73. package/lib/typescript/components/steps/InteractiveFlow.d.ts +23 -0
  74. package/lib/typescript/components/steps/InteractiveFlow.d.ts.map +1 -0
  75. package/lib/typescript/components/ui/ActionButton.d.ts +22 -0
  76. package/lib/typescript/components/ui/ActionButton.d.ts.map +1 -0
  77. package/lib/typescript/components/ui/CallControls.d.ts +22 -0
  78. package/lib/typescript/components/ui/CallControls.d.ts.map +1 -0
  79. package/lib/typescript/components/ui/FeedbackScreen.d.ts +24 -0
  80. package/lib/typescript/components/ui/FeedbackScreen.d.ts.map +1 -0
  81. package/lib/typescript/components/ui/Icons.d.ts +28 -0
  82. package/lib/typescript/components/ui/Icons.d.ts.map +1 -0
  83. package/lib/typescript/components/ui/MessageBubble.d.ts +17 -0
  84. package/lib/typescript/components/ui/MessageBubble.d.ts.map +1 -0
  85. package/lib/typescript/components/ui/TabSelector.d.ts +21 -0
  86. package/lib/typescript/components/ui/TabSelector.d.ts.map +1 -0
  87. package/lib/typescript/components/ui/WidgetHeader.d.ts +20 -0
  88. package/lib/typescript/components/ui/WidgetHeader.d.ts.map +1 -0
  89. package/lib/typescript/context/RinggProvider.d.ts +53 -0
  90. package/lib/typescript/context/RinggProvider.d.ts.map +1 -0
  91. package/lib/typescript/context/index.d.ts +3 -0
  92. package/lib/typescript/context/index.d.ts.map +1 -0
  93. package/lib/typescript/hooks/index.d.ts +15 -0
  94. package/lib/typescript/hooks/index.d.ts.map +1 -0
  95. package/lib/typescript/hooks/useRinggCall.d.ts +41 -0
  96. package/lib/typescript/hooks/useRinggCall.d.ts.map +1 -0
  97. package/lib/typescript/hooks/useRinggChat.d.ts +29 -0
  98. package/lib/typescript/hooks/useRinggChat.d.ts.map +1 -0
  99. package/lib/typescript/hooks/useRinggComponents.d.ts +52 -0
  100. package/lib/typescript/hooks/useRinggComponents.d.ts.map +1 -0
  101. package/lib/typescript/hooks/useRinggFeedback.d.ts +23 -0
  102. package/lib/typescript/hooks/useRinggFeedback.d.ts.map +1 -0
  103. package/lib/typescript/hooks/useRinggTheme.d.ts +40 -0
  104. package/lib/typescript/hooks/useRinggTheme.d.ts.map +1 -0
  105. package/lib/typescript/hooks/useRinggTranscripts.d.ts +30 -0
  106. package/lib/typescript/hooks/useRinggTranscripts.d.ts.map +1 -0
  107. package/lib/typescript/hooks/useRinggWidgetState.d.ts +38 -0
  108. package/lib/typescript/hooks/useRinggWidgetState.d.ts.map +1 -0
  109. package/lib/typescript/index.d.ts +44 -0
  110. package/lib/typescript/index.d.ts.map +1 -0
  111. package/lib/typescript/package.json +1 -0
  112. package/package.json +80 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ringg AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,250 @@
1
+ # @ringg/react-native
2
+
3
+ Add AI voice and text agents to your React Native app with [Ringg AI](https://ringg.ai).
4
+
5
+ ## Setup
6
+
7
+ ### 1. Install
8
+
9
+ ```bash
10
+ npm install @ringg/react-native
11
+ ```
12
+
13
+ ### 2. Add the Expo plugin
14
+
15
+ In your `app.json`:
16
+
17
+ ```json
18
+ {
19
+ "expo": {
20
+ "plugins": ["@ringg/react-native"]
21
+ }
22
+ }
23
+ ```
24
+
25
+ ### 3. Rebuild
26
+
27
+ Voice calls require native modules, so you need a **development build** (Expo Go is not supported).
28
+
29
+ ```bash
30
+ npx expo prebuild --clean
31
+ npx expo run:ios
32
+ # or
33
+ npx expo run:android
34
+ ```
35
+
36
+ ## Drop-in widget
37
+
38
+ Add a complete voice/text chat widget with one component. It renders a floating action button that opens an animated chat panel.
39
+
40
+ ```tsx
41
+ import { RinggWidget } from "@ringg/react-native";
42
+
43
+ export default function App() {
44
+ return (
45
+ <RinggWidget
46
+ config={{
47
+ agentId: "your-agent-id",
48
+ xApiKey: "your-api-key",
49
+ variables: {
50
+ callee_name: "Jane Doe",
51
+ },
52
+ }}
53
+ />
54
+ );
55
+ }
56
+ ```
57
+
58
+ ### Widget props
59
+
60
+ | Prop | Type | Description |
61
+ | ------------- | -------------------------- | ----------------------------------------------------------- |
62
+ | `config` | `RinggWidgetConfig` | Agent ID, API key, variables, and customization (see below) |
63
+ | `onEvent` | `(event, payload) => void` | Callback for widget lifecycle events |
64
+ | `triggerSize` | `number` | FAB button size in pixels (default: `56`) |
65
+
66
+ ### Config options
67
+
68
+ ```ts
69
+ {
70
+ agentId: string; // Required — your agent ID
71
+ xApiKey: string; // Required — your API key
72
+ variables: Record<string, string>; // Custom variables sent to the agent
73
+ mode?: "prod" | "stage"; // Environment (default: "prod")
74
+ title?: string; // Header title
75
+ description?: string; // Header description
76
+ defaultTab?: "audio" | "text"; // Starting mode (default: "audio")
77
+ hideTabSelector?: boolean; // Hide the audio/text toggle
78
+ logoUrl?: string; // Custom logo URL
79
+ theme?: { // Theme overrides
80
+ primaryColor?: string;
81
+ backgroundColor?: string;
82
+ primaryTextColor?: string;
83
+ secondaryTextColor?: string;
84
+ buttonStyle?: "rounded" | "pill" | "square";
85
+ };
86
+ }
87
+ ```
88
+
89
+ ### Events
90
+
91
+ Listen to widget lifecycle events via `onEvent`:
92
+
93
+ ```tsx
94
+ <RinggWidget
95
+ config={config}
96
+ onEvent={(event, payload) => {
97
+ switch (event) {
98
+ case "ringg:conversation_status":
99
+ // { status: "started" | "ended", mode: "audio" | "text", callId: string }
100
+ break;
101
+ case "ringg:widget_status":
102
+ // { status: "maximised" | "minimised", mode: "audio" | "text" }
103
+ break;
104
+ case "ringg:feedback_status":
105
+ // { status: "submitted" | "skipped", callId: string, rating?: number }
106
+ break;
107
+ }
108
+ }}
109
+ />
110
+ ```
111
+
112
+ ## Headless hooks
113
+
114
+ Build a completely custom UI. Wrap your screen with `RinggProvider`, then use hooks to control calls, chat, and more.
115
+
116
+ ```tsx
117
+ import { RinggProvider, useRinggCall, useRinggChat } from "@ringg/react-native";
118
+
119
+ function App() {
120
+ return (
121
+ <RinggProvider
122
+ config={{
123
+ agentId: "your-agent-id",
124
+ xApiKey: "your-api-key",
125
+ variables: {},
126
+ }}
127
+ >
128
+ <ChatScreen />
129
+ </RinggProvider>
130
+ );
131
+ }
132
+
133
+ function ChatScreen() {
134
+ const call = useRinggCall();
135
+ const chat = useRinggChat();
136
+
137
+ if (!call.isConnected) {
138
+ return (
139
+ <View>
140
+ <Button title="Start voice call" onPress={() => call.startCall("audio")} disabled={call.isLoading} />
141
+ <Button title="Start text chat" onPress={() => call.startCall("text")} disabled={call.isLoading} />
142
+ </View>
143
+ );
144
+ }
145
+
146
+ return (
147
+ <View style={{ flex: 1 }}>
148
+ <FlatList data={chat.messages} keyExtractor={(item) => String(item.timestamp)} renderItem={({ item }) => <Text style={{ alignSelf: item.isSelf ? "flex-end" : "flex-start" }}>{item.message}</Text>} />
149
+
150
+ {call.callMode === "audio" && <Button title={call.isMicEnabled ? "Mute" : "Unmute"} onPress={call.toggleMic} />}
151
+
152
+ {call.callMode === "text" && (
153
+ <TextInput
154
+ placeholder="Type a message..."
155
+ onSubmitEditing={(e) => {
156
+ chat.sendMessage(e.nativeEvent.text);
157
+ }}
158
+ />
159
+ )}
160
+
161
+ <Button title="End call" onPress={call.endCall} />
162
+ </View>
163
+ );
164
+ }
165
+ ```
166
+
167
+ ### useRinggCall()
168
+
169
+ Controls call lifecycle and microphone.
170
+
171
+ | Property | Type | Description |
172
+ | ----------------- | ------------------------------------------------- | --------------------------------------- |
173
+ | `startCall(mode)` | `(mediaType: "audio" \| "text") => Promise<void>` | Start a voice or text session |
174
+ | `endCall()` | `() => Promise<void>` | End the current session |
175
+ | `isConnected` | `boolean` | Whether the agent is connected |
176
+ | `isLoading` | `boolean` | Loading state during connect/disconnect |
177
+ | `connectionState` | `"connected" \| "disconnected" \| "reconnecting"` | Detailed connection state |
178
+ | `callMode` | `"audio" \| "text"` | Current session mode |
179
+ | `callId` | `string \| null` | Current call ID |
180
+ | `isMicEnabled` | `boolean` | Microphone state |
181
+ | `toggleMic()` | `() => Promise<void>` | Toggle microphone on/off |
182
+ | `error` | `string \| null` | Error message if connection failed |
183
+ | `clearError()` | `() => void` | Clear the error state |
184
+
185
+ ### useRinggChat()
186
+
187
+ Send and receive text messages.
188
+
189
+ | Property | Type | Description |
190
+ | ------------------- | --------------------------------- | ----------------------------------- |
191
+ | `messages` | `ChatMessage[]` | All messages in chronological order |
192
+ | `sendMessage(text)` | `(text: string) => Promise<void>` | Send a message to the agent |
193
+ | `clearMessages()` | `() => void` | Clear message history |
194
+
195
+ Each `ChatMessage` has: `{ message: string, isSelf: boolean, name: string, timestamp: number }`.
196
+
197
+ ### useRinggTranscripts()
198
+
199
+ Real-time speech-to-text during voice calls.
200
+
201
+ | Property | Type | Description |
202
+ | ------------- | ------------------- | --------------------------- |
203
+ | `transcripts` | `TranscriptEntry[]` | Live transcription segments |
204
+
205
+ ### useRinggFeedback()
206
+
207
+ Post-call feedback collection.
208
+
209
+ | Property | Type | Description |
210
+ | --------------------------------- | ---------------------------------------------------- | ---------------------- |
211
+ | `submitFeedback(rating, comment)` | `(rating: number, comment: string) => Promise<void>` | Submit feedback |
212
+ | `skipFeedback()` | `() => void` | Skip feedback |
213
+ | `isSubmitting` | `boolean` | Submission in progress |
214
+
215
+ ### useRinggTheme()
216
+
217
+ Access the resolved theme for custom styling.
218
+
219
+ | Property | Type | Description |
220
+ | ---------------------- | ----------------------------- | ------------------------------------------ |
221
+ | `theme` | `ResolvedWidgetTheme` | Full theme with defaults applied |
222
+ | `getSolidColor(color)` | `(color: string) => string` | Extract solid color from gradient |
223
+ | `buttonRadius` | `string` | Border radius for the current button style |
224
+ | `getContrastText(bg)` | `(bgColor: string) => string` | Get black or white text for a background |
225
+
226
+ ## UI building blocks
227
+
228
+ When using headless hooks, you can still use our pre-built UI components individually:
229
+
230
+ ```tsx
231
+ import { MessageBubble, WidgetHeader, CallControls, ActionButton, FeedbackScreen, TabSelector } from "@ringg/react-native";
232
+ ```
233
+
234
+ ## Expo plugin options
235
+
236
+ ```json
237
+ ["@ringg/react-native", { "enableCamera": true }]
238
+ ```
239
+
240
+ | Option | Type | Default | Description |
241
+ | -------------- | --------- | ------- | ---------------------------------------------------- |
242
+ | `enableCamera` | `boolean` | `false` | Request camera permission (for future video support) |
243
+
244
+ ## Bare React Native
245
+
246
+ If you're not using Expo, see the [bare React Native setup guide](https://ringg.ai/docs/react-native/bare) for manual native configuration.
247
+
248
+ ## License
249
+
250
+ [MIT](./LICENSE)
package/app.plugin.js ADDED
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Expo config plugin for @ringg/react-native.
3
+ *
4
+ * Automatically configures the native project for voice calls:
5
+ * - Microphone permission (iOS + Android)
6
+ * - Audio background mode (iOS) — keeps calls alive when backgrounded
7
+ * - WebRTC build settings (bitcode disabled, network permissions)
8
+ * - LiveKit native lifecycle (auto-linked via expo-module.config.json)
9
+ *
10
+ * Usage in app.json:
11
+ * { "plugins": ["@ringg/react-native"] }
12
+ *
13
+ * Or with options:
14
+ * { "plugins": [["@ringg/react-native", { "enableCamera": true }]] }
15
+ */
16
+
17
+ const { createRunOncePlugin, withInfoPlist } = require("expo/config-plugins");
18
+ const pkg = require("./package.json");
19
+
20
+ /**
21
+ * @param {import('expo/config-plugins').ExpoConfig} config
22
+ * @param {{ enableCamera?: boolean, microphonePermission?: string }} [props]
23
+ */
24
+ function withRingg(config, props = {}) {
25
+ const { enableCamera = false, microphonePermission } = props;
26
+
27
+ // 1. WebRTC native setup: permissions, bitcode, Android manifest
28
+ const webrtcPlugin = require("@config-plugins/react-native-webrtc");
29
+ const withWebRTC = webrtcPlugin.default || webrtcPlugin;
30
+ config = withWebRTC(config, {
31
+ cameraPermission: enableCamera ? "This app uses the camera for video calls." : false,
32
+ microphonePermission: microphonePermission || "This app uses the microphone for voice calls with the AI agent.",
33
+ });
34
+
35
+ // 2. iOS background audio — keeps voice calls alive when app is backgrounded
36
+ config = withInfoPlist(config, (cfg) => {
37
+ const modes = cfg.modResults.UIBackgroundModes || [];
38
+ if (!modes.includes("audio")) {
39
+ cfg.modResults.UIBackgroundModes = [...modes, "audio"];
40
+ }
41
+ return cfg;
42
+ });
43
+
44
+ // LiveKit native lifecycle (iOS AppDelegate subscriber, Android audio config)
45
+ // is auto-linked by Expo via @livekit/react-native-expo-plugin's
46
+ // expo-module.config.json — no manual plugin call needed.
47
+
48
+ return config;
49
+ }
50
+
51
+ module.exports = createRunOncePlugin(withRingg, pkg.name, pkg.version);
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export { LiveKitRNAdapter } from "./livekit-rn-adapter.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["LiveKitRNAdapter"],"sourceRoot":"../../../src","sources":["adapters/index.ts"],"mappings":";;AAAA,SAASA,gBAAgB,QAAQ,yBAAsB","ignoreList":[]}
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * React Native implementation of the LiveKitAdapter interface.
5
+ *
6
+ * Wraps `livekit-client` (which @livekit/react-native patches for RN compatibility)
7
+ * to provide the same abstract interface that @ringg/core expects.
8
+ *
9
+ * Automatically calls `registerGlobals()` on first use — consumers don't need to
10
+ * call it themselves.
11
+ */
12
+
13
+ import { Platform } from "react-native";
14
+ import { Room, RoomEvent, LocalParticipant } from "livekit-client";
15
+ import { isAgentIdentity } from "@ringg/core";
16
+ /**
17
+ * Ensures WebRTC globals and polyfills are registered exactly once.
18
+ * Called lazily before the first room connection — not at module scope —
19
+ * so the native module has time to load.
20
+ */
21
+ let _globalsRegistered = false;
22
+ function ensureGlobals() {
23
+ if (_globalsRegistered || Platform.OS === "web") return;
24
+ try {
25
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
26
+ const {
27
+ registerGlobals
28
+ } = require("@livekit/react-native");
29
+ registerGlobals();
30
+ _globalsRegistered = true;
31
+ } catch {
32
+ // @livekit/react-native not available (e.g. SSR or test env) — skip
33
+ }
34
+ }
35
+ export class LiveKitRNAdapter {
36
+ cleanupFns = [];
37
+ constructor(roomOptions) {
38
+ ensureGlobals();
39
+ this.room = new Room({
40
+ dynacast: true,
41
+ adaptiveStream: true,
42
+ ...roomOptions
43
+ });
44
+ }
45
+
46
+ /** Expose the underlying Room for advanced usage or LiveKit hooks. */
47
+ getRoom() {
48
+ return this.room;
49
+ }
50
+
51
+ // ─── Connection ─────────────────────────────────────────────────────────
52
+
53
+ getConnectionState() {
54
+ switch (this.room.state) {
55
+ case "connected":
56
+ return "connected";
57
+ case "reconnecting":
58
+ return "reconnecting";
59
+ case "disconnected":
60
+ return "disconnected";
61
+ default:
62
+ return "disconnected";
63
+ }
64
+ }
65
+ async connect(url, token) {
66
+ await this.room.connect(url, token);
67
+ }
68
+ disconnect() {
69
+ try {
70
+ this.room.disconnect();
71
+ } catch (err) {
72
+ // Suppress "cannot send signal request before connected" errors —
73
+ // this happens when disconnect() races with a reconnection attempt
74
+ // and the room tries to send a leave signal while not fully connected.
75
+ // Suppress "cannot send signal request before connected" — races with reconnection
76
+ }
77
+ }
78
+
79
+ // ─── Microphone ─────────────────────────────────────────────────────────
80
+
81
+ async setMicrophoneEnabled(enabled) {
82
+ await this.room.localParticipant.setMicrophoneEnabled(enabled);
83
+ }
84
+ isMicrophoneEnabled() {
85
+ return this.room.localParticipant.isMicrophoneEnabled;
86
+ }
87
+
88
+ // ─── RPC ────────────────────────────────────────────────────────────────
89
+
90
+ registerRpcMethod(method, handler) {
91
+ this.room.registerRpcMethod(method, async data => {
92
+ return handler({
93
+ method,
94
+ payload: data.payload,
95
+ callerIdentity: data.callerIdentity
96
+ });
97
+ });
98
+ }
99
+ unregisterRpcMethod(method) {
100
+ this.room.unregisterRpcMethod(method);
101
+ }
102
+ async performRpc(destinationIdentity, method, payload) {
103
+ return this.room.localParticipant.performRpc({
104
+ destinationIdentity,
105
+ method,
106
+ payload
107
+ });
108
+ }
109
+
110
+ // ─── Text Streams ───────────────────────────────────────────────────────
111
+
112
+ registerTextStreamHandler(topic, handler) {
113
+ this.room.registerTextStreamHandler(topic, async (reader, participantInfo) => {
114
+ try {
115
+ const message = await reader.readAll();
116
+ handler({
117
+ message,
118
+ participantIdentity: participantInfo.identity ?? ""
119
+ });
120
+ } catch (err) {
121
+ console.error("[LiveKitRNAdapter] Error reading text stream:", err);
122
+ }
123
+ });
124
+ }
125
+ unregisterTextStreamHandler(topic) {
126
+ this.room.unregisterTextStreamHandler(topic);
127
+ }
128
+
129
+ // ─── Event Subscriptions ────────────────────────────────────────────────
130
+
131
+ onConnectionStateChange(handler) {
132
+ const mapState = () => this.getConnectionState();
133
+ const onConnected = () => handler(mapState());
134
+ const onDisconnected = () => handler("disconnected");
135
+ const onReconnecting = () => handler("reconnecting");
136
+ const onReconnected = () => handler(mapState());
137
+ this.room.on(RoomEvent.Connected, onConnected);
138
+ this.room.on(RoomEvent.Disconnected, onDisconnected);
139
+ this.room.on(RoomEvent.Reconnecting, onReconnecting);
140
+ this.room.on(RoomEvent.Reconnected, onReconnected);
141
+ const unsub = () => {
142
+ this.room.off(RoomEvent.Connected, onConnected);
143
+ this.room.off(RoomEvent.Disconnected, onDisconnected);
144
+ this.room.off(RoomEvent.Reconnecting, onReconnecting);
145
+ this.room.off(RoomEvent.Reconnected, onReconnected);
146
+ };
147
+ this.cleanupFns.push(unsub);
148
+ return unsub;
149
+ }
150
+ onParticipantDisconnected(handler) {
151
+ const onDisconnect = participant => {
152
+ handler(participant.identity);
153
+ };
154
+ this.room.on(RoomEvent.ParticipantDisconnected, onDisconnect);
155
+ const unsub = () => {
156
+ this.room.off(RoomEvent.ParticipantDisconnected, onDisconnect);
157
+ };
158
+ this.cleanupFns.push(unsub);
159
+ return unsub;
160
+ }
161
+ onDisconnected(handler) {
162
+ this.room.on(RoomEvent.Disconnected, handler);
163
+ const unsub = () => {
164
+ this.room.off(RoomEvent.Disconnected, handler);
165
+ };
166
+ this.cleanupFns.push(unsub);
167
+ return unsub;
168
+ }
169
+ onTranscription(handler) {
170
+ const onSegments = (segments, participant) => {
171
+ if (!participant) return;
172
+ for (const seg of segments) {
173
+ handler({
174
+ id: seg.id,
175
+ text: seg.text,
176
+ isFinal: seg.final,
177
+ participantIdentity: participant.identity,
178
+ isAgent: !(participant instanceof LocalParticipant)
179
+ });
180
+ }
181
+ };
182
+ this.room.on(RoomEvent.TranscriptionReceived, onSegments);
183
+ const unsub = () => {
184
+ this.room.off(RoomEvent.TranscriptionReceived, onSegments);
185
+ };
186
+ this.cleanupFns.push(unsub);
187
+ return unsub;
188
+ }
189
+
190
+ // ─── Participant Queries ────────────────────────────────────────────────
191
+
192
+ getAgentIdentity() {
193
+ for (const [, participant] of this.room.remoteParticipants) {
194
+ if (isAgentIdentity(participant.identity)) {
195
+ return participant.identity;
196
+ }
197
+ }
198
+ return null;
199
+ }
200
+ getLocalIdentity() {
201
+ return this.room.localParticipant.identity;
202
+ }
203
+
204
+ // ─── Cleanup ────────────────────────────────────────────────────────────
205
+
206
+ dispose() {
207
+ this.cleanupFns.forEach(fn => fn());
208
+ this.cleanupFns = [];
209
+ try {
210
+ this.room.disconnect();
211
+ } catch {
212
+ // Safe to ignore — room may already be disconnected
213
+ }
214
+ }
215
+ }
216
+ //# sourceMappingURL=livekit-rn-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Platform","Room","RoomEvent","LocalParticipant","isAgentIdentity","_globalsRegistered","ensureGlobals","OS","registerGlobals","require","LiveKitRNAdapter","cleanupFns","constructor","roomOptions","room","dynacast","adaptiveStream","getRoom","getConnectionState","state","connect","url","token","disconnect","err","setMicrophoneEnabled","enabled","localParticipant","isMicrophoneEnabled","registerRpcMethod","method","handler","data","payload","callerIdentity","unregisterRpcMethod","performRpc","destinationIdentity","registerTextStreamHandler","topic","reader","participantInfo","message","readAll","participantIdentity","identity","console","error","unregisterTextStreamHandler","onConnectionStateChange","mapState","onConnected","onDisconnected","onReconnecting","onReconnected","on","Connected","Disconnected","Reconnecting","Reconnected","unsub","off","push","onParticipantDisconnected","onDisconnect","participant","ParticipantDisconnected","onTranscription","onSegments","segments","seg","id","text","isFinal","final","isAgent","TranscriptionReceived","getAgentIdentity","remoteParticipants","getLocalIdentity","dispose","forEach","fn"],"sourceRoot":"../../../src","sources":["adapters/livekit-rn-adapter.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,QAAQ,QAAQ,cAAc;AACvC,SAASC,IAAI,EAAEC,SAAS,EAAyHC,gBAAgB,QAAe,gBAAgB;AAGhM,SAASC,eAAe,QAAQ,aAAa;AAI7C;AACA;AACA;AACA;AACA;AACA,IAAIC,kBAAkB,GAAG,KAAK;AAC9B,SAASC,aAAaA,CAAA,EAAS;EAC7B,IAAID,kBAAkB,IAAIL,QAAQ,CAACO,EAAE,KAAK,KAAK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