@elevenlabs/react-native 0.4.1 → 0.4.3

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.
@@ -205,16 +205,24 @@ export const ElevenLabsProvider: React.FC<ElevenLabsProviderProps> = ({ children
205
205
  const handleParticipantReadyWithOverrides = React.useCallback((participant: LocalParticipant) => {
206
206
  handleParticipantReady(participant);
207
207
 
208
- if (localParticipant) {
209
- const overridesEvent = constructOverrides({
210
- overrides,
211
- customLlmExtraBody,
212
- dynamicVariables,
213
- userId,
214
- });
215
- sendMessage(overridesEvent);
208
+ const overridesEvent = constructOverrides({
209
+ overrides,
210
+ customLlmExtraBody,
211
+ dynamicVariables,
212
+ userId,
213
+ });
214
+
215
+ if (overridesEvent) {
216
+ try {
217
+ const encoder = new TextEncoder();
218
+ const data = encoder.encode(JSON.stringify(overridesEvent));
219
+ participant.publishData(data, { reliable: true });
220
+ } catch (error) {
221
+ console.error("Failed to send overrides:", error);
222
+ callbacksRef.current.onError?.(error as string);
223
+ }
216
224
  }
217
- }, [handleParticipantReady, localParticipant, overrides, customLlmExtraBody, dynamicVariables, userId, sendMessage]);
225
+ }, [handleParticipantReady, overrides, customLlmExtraBody, dynamicVariables, userId, callbacksRef]);
218
226
 
219
227
  const conversation: Conversation = {
220
228
  startSession,
@@ -46,11 +46,6 @@ export const LiveKitRoomWrapper = ({
46
46
  options={{
47
47
  adaptiveStream: { pixelDensity: 'screen' },
48
48
  }}
49
- connectOptions={{
50
- rtcConfig: {
51
- iceTransportPolicy: 'relay',
52
- },
53
- }}
54
49
  onConnected={onConnected}
55
50
  onDisconnected={onDisconnected}
56
51
  onError={onError}
@@ -1,4 +1,4 @@
1
- import { useState, useEffect, useCallback } from "react";
1
+ import { useState, useEffect, useCallback, useRef } from "react";
2
2
  import { AudioSession } from "@livekit/react-native";
3
3
  import type { LocalParticipant } from "livekit-client";
4
4
  import type { ConversationStatus, Callbacks } from "../types";
@@ -11,6 +11,7 @@ export const useLiveKitRoom = (
11
11
  const [roomConnected, setRoomConnected] = useState(false);
12
12
  const [localParticipant, setLocalParticipant] =
13
13
  useState<LocalParticipant | null>(null);
14
+ const hasCalledOnConnectRef = useRef(false);
14
15
 
15
16
  useEffect(() => {
16
17
  const start = async () => {
@@ -23,23 +24,35 @@ export const useLiveKitRoom = (
23
24
  };
24
25
  }, []);
25
26
 
27
+ // Fire onConnect when both participant and room are fully ready
28
+ useEffect(() => {
29
+ if (localParticipant && roomConnected && !hasCalledOnConnectRef.current) {
30
+ hasCalledOnConnectRef.current = true;
31
+ callbacksRef.current.onConnect?.({ conversationId });
32
+ }
33
+ }, [localParticipant, roomConnected, conversationId, callbacksRef]);
34
+
26
35
  const handleParticipantReady = useCallback(
27
36
  (participant: LocalParticipant) => {
37
+ if (localParticipant) {
38
+ return;
39
+ }
40
+
28
41
  setLocalParticipant(participant);
42
+ setStatus("connected");
29
43
  },
30
- []
44
+ [localParticipant, setStatus]
31
45
  );
32
46
 
33
47
  const handleConnected = useCallback(() => {
34
48
  setRoomConnected(true);
35
- setStatus("connected");
36
- callbacksRef.current.onConnect?.({ conversationId });
37
- }, [conversationId, callbacksRef, setStatus]);
49
+ }, []);
38
50
 
39
51
  const handleDisconnected = useCallback(() => {
40
52
  setRoomConnected(false);
41
53
  setStatus("disconnected");
42
54
  setLocalParticipant(null);
55
+ hasCalledOnConnectRef.current = false;
43
56
  callbacksRef.current.onDisconnect?.({ reason: "user" });
44
57
  }, [callbacksRef, setStatus]);
45
58
 
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // This file is auto-generated during build
2
- export const PACKAGE_VERSION = "0.4.1";
2
+ export const PACKAGE_VERSION = "0.4.3";