@elevenlabs/react-native 0.2.0 → 0.2.1
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.
- package/README.md +12 -2
- package/dist/ElevenLabsProvider.d.ts +1 -0
- package/dist/hooks/useConversationSession.d.ts +1 -1
- package/dist/hooks/useLiveKitRoom.d.ts +1 -1
- package/dist/lib.js +1 -1
- package/dist/lib.js.map +1 -1
- package/dist/lib.modern.js +1 -1
- package/dist/lib.modern.js.map +1 -1
- package/dist/lib.module.js +1 -1
- package/dist/lib.module.js.map +1 -1
- package/dist/lib.umd.js +1 -1
- package/dist/lib.umd.js.map +1 -1
- package/dist/utils/tokenUtils.d.ts +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/ElevenLabsProvider.tsx +7 -3
- package/src/hooks/useConversationSession.ts +13 -6
- package/src/hooks/useLiveKitRoom.ts +3 -3
- package/src/utils/tokenUtils.ts +5 -3
- package/src/version.ts +1 -1
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
} from "../types";
|
|
7
7
|
import {
|
|
8
8
|
getConversationToken,
|
|
9
|
-
|
|
9
|
+
extractConversationIdFromToken,
|
|
10
10
|
} from "../utils/tokenUtils";
|
|
11
11
|
|
|
12
12
|
export const useConversationSession = (
|
|
@@ -14,7 +14,7 @@ export const useConversationSession = (
|
|
|
14
14
|
setStatus: (status: ConversationStatus) => void,
|
|
15
15
|
setConnect: (connect: boolean) => void,
|
|
16
16
|
setToken: (token: string) => void,
|
|
17
|
-
|
|
17
|
+
setConversationId: (conversationId: string) => void,
|
|
18
18
|
tokenFetchUrl?: string
|
|
19
19
|
) => {
|
|
20
20
|
const [overrides, setOverrides] = useState<ConversationConfig["overrides"]>(
|
|
@@ -55,9 +55,9 @@ export const useConversationSession = (
|
|
|
55
55
|
throw new Error("Either conversationToken or agentId is required");
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
const extractedConversationId =
|
|
59
|
+
extractConversationIdFromToken(conversationToken);
|
|
60
|
+
setConversationId(extractedConversationId);
|
|
61
61
|
|
|
62
62
|
setToken(conversationToken);
|
|
63
63
|
setConnect(true);
|
|
@@ -68,7 +68,14 @@ export const useConversationSession = (
|
|
|
68
68
|
throw error;
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
|
-
[
|
|
71
|
+
[
|
|
72
|
+
callbacksRef,
|
|
73
|
+
setStatus,
|
|
74
|
+
setConnect,
|
|
75
|
+
setToken,
|
|
76
|
+
setConversationId,
|
|
77
|
+
tokenFetchUrl,
|
|
78
|
+
]
|
|
72
79
|
);
|
|
73
80
|
|
|
74
81
|
const endSession = useCallback(async () => {
|
|
@@ -6,7 +6,7 @@ import type { ConversationStatus, Callbacks } from "../types";
|
|
|
6
6
|
export const useLiveKitRoom = (
|
|
7
7
|
callbacksRef: { current: Callbacks },
|
|
8
8
|
setStatus: (status: ConversationStatus) => void,
|
|
9
|
-
|
|
9
|
+
conversationId: string
|
|
10
10
|
) => {
|
|
11
11
|
const [roomConnected, setRoomConnected] = useState(false);
|
|
12
12
|
const [localParticipant, setLocalParticipant] =
|
|
@@ -33,8 +33,8 @@ export const useLiveKitRoom = (
|
|
|
33
33
|
const handleConnected = useCallback(() => {
|
|
34
34
|
setRoomConnected(true);
|
|
35
35
|
setStatus("connected");
|
|
36
|
-
callbacksRef.current.onConnect?.({ conversationId
|
|
37
|
-
}, [
|
|
36
|
+
callbacksRef.current.onConnect?.({ conversationId });
|
|
37
|
+
}, [conversationId, callbacksRef, setStatus]);
|
|
38
38
|
|
|
39
39
|
const handleDisconnected = useCallback(() => {
|
|
40
40
|
setRoomConnected(false);
|
package/src/utils/tokenUtils.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { PACKAGE_VERSION } from "../version";
|
|
2
2
|
|
|
3
|
-
export const
|
|
3
|
+
export const extractConversationIdFromToken = (token: string): string => {
|
|
4
4
|
try {
|
|
5
5
|
const tokenPayload = JSON.parse(atob(token.split(".")[1]));
|
|
6
|
-
|
|
6
|
+
const roomId = tokenPayload.video?.room || "";
|
|
7
|
+
|
|
8
|
+
return roomId.match(/(conv_[a-zA-Z0-9]+)/)?.[0] || "";
|
|
7
9
|
} catch (error) {
|
|
8
|
-
console.warn("Could not extract
|
|
10
|
+
console.warn("Could not extract conversation ID from token");
|
|
9
11
|
return "";
|
|
10
12
|
}
|
|
11
13
|
};
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is auto-generated during build
|
|
2
|
-
export const PACKAGE_VERSION = "0.2.
|
|
2
|
+
export const PACKAGE_VERSION = "0.2.1";
|