@elevenlabs/react-native 0.4.2 → 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.
@@ -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.2";
2
+ export const PACKAGE_VERSION = "0.4.3";