@convai/web-sdk 0.0.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 +239 -0
- package/dist/components/RTCWidget.d.ts +56 -0
- package/dist/components/RTCWidget.d.ts.map +1 -0
- package/dist/components/RTCWidget.js +419 -0
- package/dist/components/RTCWidget.js.map +1 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +5 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/rtc-widget/components/AudioSettingsPanel.d.ts +10 -0
- package/dist/components/rtc-widget/components/AudioSettingsPanel.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/AudioSettingsPanel.js +316 -0
- package/dist/components/rtc-widget/components/AudioSettingsPanel.js.map +1 -0
- package/dist/components/rtc-widget/components/ConviMessage.d.ts +10 -0
- package/dist/components/rtc-widget/components/ConviMessage.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/ConviMessage.js +14 -0
- package/dist/components/rtc-widget/components/ConviMessage.js.map +1 -0
- package/dist/components/rtc-widget/components/FloatingVideo.d.ts +9 -0
- package/dist/components/rtc-widget/components/FloatingVideo.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/FloatingVideo.js +122 -0
- package/dist/components/rtc-widget/components/FloatingVideo.js.map +1 -0
- package/dist/components/rtc-widget/components/MarkdownRenderer.d.ts +7 -0
- package/dist/components/rtc-widget/components/MarkdownRenderer.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/MarkdownRenderer.js +68 -0
- package/dist/components/rtc-widget/components/MarkdownRenderer.js.map +1 -0
- package/dist/components/rtc-widget/components/MessageBubble.d.ts +10 -0
- package/dist/components/rtc-widget/components/MessageBubble.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/MessageBubble.js +23 -0
- package/dist/components/rtc-widget/components/MessageBubble.js.map +1 -0
- package/dist/components/rtc-widget/components/MessageList.d.ts +11 -0
- package/dist/components/rtc-widget/components/MessageList.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/MessageList.js +89 -0
- package/dist/components/rtc-widget/components/MessageList.js.map +1 -0
- package/dist/components/rtc-widget/components/UserMessage.d.ts +9 -0
- package/dist/components/rtc-widget/components/UserMessage.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/UserMessage.js +15 -0
- package/dist/components/rtc-widget/components/UserMessage.js.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviButton.d.ts +6 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviButton.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviButton.js +15 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviButton.js.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviFooter.d.ts +25 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviFooter.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviFooter.js +172 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviFooter.js.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviHeader.d.ts +17 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviHeader.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviHeader.js +66 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviHeader.js.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/SettingsTray.d.ts +12 -0
- package/dist/components/rtc-widget/components/conviComponents/SettingsTray.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/SettingsTray.js +68 -0
- package/dist/components/rtc-widget/components/conviComponents/SettingsTray.js.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts +8 -0
- package/dist/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js +199 -0
- package/dist/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/index.d.ts +6 -0
- package/dist/components/rtc-widget/components/conviComponents/index.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/index.js +6 -0
- package/dist/components/rtc-widget/components/conviComponents/index.js.map +1 -0
- package/dist/components/rtc-widget/components/index.d.ts +9 -0
- package/dist/components/rtc-widget/components/index.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/index.js +13 -0
- package/dist/components/rtc-widget/components/index.js.map +1 -0
- package/dist/components/rtc-widget/index.d.ts +6 -0
- package/dist/components/rtc-widget/index.d.ts.map +1 -0
- package/dist/components/rtc-widget/index.js +7 -0
- package/dist/components/rtc-widget/index.js.map +1 -0
- package/dist/components/rtc-widget/styles/framerConfig.d.ts +116 -0
- package/dist/components/rtc-widget/styles/framerConfig.d.ts.map +1 -0
- package/dist/components/rtc-widget/styles/framerConfig.js +73 -0
- package/dist/components/rtc-widget/styles/framerConfig.js.map +1 -0
- package/dist/components/rtc-widget/styles/icons.d.ts +28 -0
- package/dist/components/rtc-widget/styles/icons.d.ts.map +1 -0
- package/dist/components/rtc-widget/styles/icons.js +257 -0
- package/dist/components/rtc-widget/styles/icons.js.map +1 -0
- package/dist/components/rtc-widget/styles/index.d.ts +6 -0
- package/dist/components/rtc-widget/styles/index.d.ts.map +1 -0
- package/dist/components/rtc-widget/styles/index.js +9 -0
- package/dist/components/rtc-widget/styles/index.js.map +1 -0
- package/dist/components/rtc-widget/styles/styledComponents.d.ts +90 -0
- package/dist/components/rtc-widget/styles/styledComponents.d.ts.map +1 -0
- package/dist/components/rtc-widget/styles/styledComponents.js +640 -0
- package/dist/components/rtc-widget/styles/styledComponents.js.map +1 -0
- package/dist/components/rtc-widget/styles/theme.d.ts +188 -0
- package/dist/components/rtc-widget/styles/theme.d.ts.map +1 -0
- package/dist/components/rtc-widget/styles/theme.js +290 -0
- package/dist/components/rtc-widget/styles/theme.js.map +1 -0
- package/dist/components/rtc-widget/types/index.d.ts +60 -0
- package/dist/components/rtc-widget/types/index.d.ts.map +1 -0
- package/dist/components/rtc-widget/types/index.js +2 -0
- package/dist/components/rtc-widget/types/index.js.map +1 -0
- package/dist/hooks/index.d.ts +13 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +14 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useAudioControls.d.ts +41 -0
- package/dist/hooks/useAudioControls.d.ts.map +1 -0
- package/dist/hooks/useAudioControls.js +219 -0
- package/dist/hooks/useAudioControls.js.map +1 -0
- package/dist/hooks/useCharacterInfo.d.ts +17 -0
- package/dist/hooks/useCharacterInfo.d.ts.map +1 -0
- package/dist/hooks/useCharacterInfo.js +61 -0
- package/dist/hooks/useCharacterInfo.js.map +1 -0
- package/dist/hooks/useConvaiClient.d.ts +37 -0
- package/dist/hooks/useConvaiClient.d.ts.map +1 -0
- package/dist/hooks/useConvaiClient.js +348 -0
- package/dist/hooks/useConvaiClient.js.map +1 -0
- package/dist/hooks/useDynamicInfoUpdater.d.ts +33 -0
- package/dist/hooks/useDynamicInfoUpdater.d.ts.map +1 -0
- package/dist/hooks/useDynamicInfoUpdater.js +51 -0
- package/dist/hooks/useDynamicInfoUpdater.js.map +1 -0
- package/dist/hooks/useLocalCameraTrack.d.ts +22 -0
- package/dist/hooks/useLocalCameraTrack.d.ts.map +1 -0
- package/dist/hooks/useLocalCameraTrack.js +34 -0
- package/dist/hooks/useLocalCameraTrack.js.map +1 -0
- package/dist/hooks/useMessageHandler.d.ts +28 -0
- package/dist/hooks/useMessageHandler.d.ts.map +1 -0
- package/dist/hooks/useMessageHandler.js +317 -0
- package/dist/hooks/useMessageHandler.js.map +1 -0
- package/dist/hooks/useScreenShare.d.ts +45 -0
- package/dist/hooks/useScreenShare.d.ts.map +1 -0
- package/dist/hooks/useScreenShare.js +198 -0
- package/dist/hooks/useScreenShare.js.map +1 -0
- package/dist/hooks/useTemplateKeysUpdater.d.ts +35 -0
- package/dist/hooks/useTemplateKeysUpdater.d.ts.map +1 -0
- package/dist/hooks/useTemplateKeysUpdater.js +53 -0
- package/dist/hooks/useTemplateKeysUpdater.js.map +1 -0
- package/dist/hooks/useTriggerMessageSender.d.ts +28 -0
- package/dist/hooks/useTriggerMessageSender.d.ts.map +1 -0
- package/dist/hooks/useTriggerMessageSender.js +52 -0
- package/dist/hooks/useTriggerMessageSender.js.map +1 -0
- package/dist/hooks/useTtsToggle.d.ts +37 -0
- package/dist/hooks/useTtsToggle.d.ts.map +1 -0
- package/dist/hooks/useTtsToggle.js +65 -0
- package/dist/hooks/useTtsToggle.js.map +1 -0
- package/dist/hooks/useUserTextMessageSender.d.ts +28 -0
- package/dist/hooks/useUserTextMessageSender.d.ts.map +1 -0
- package/dist/hooks/useUserTextMessageSender.js +61 -0
- package/dist/hooks/useUserTextMessageSender.js.map +1 -0
- package/dist/hooks/useVideoControls.d.ts +39 -0
- package/dist/hooks/useVideoControls.d.ts.map +1 -0
- package/dist/hooks/useVideoControls.js +211 -0
- package/dist/hooks/useVideoControls.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +225 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/logger.d.ts +27 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +96 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +94 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { logger } from "../utils/logger";
|
|
3
|
+
/**
|
|
4
|
+
* Hook for updating template keys in Convai.
|
|
5
|
+
*
|
|
6
|
+
* Updates dynamic template variables that can be used in AI responses
|
|
7
|
+
* to provide personalized and contextual information.
|
|
8
|
+
*
|
|
9
|
+
* @param {Room} room - LiveKit room instance
|
|
10
|
+
* @param {string} participantSid - Participant session ID
|
|
11
|
+
* @returns {Object} Object containing updateTemplateKeys function
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* function TemplateComponent() {
|
|
16
|
+
* const { updateTemplateKeys } = useTemplateKeysUpdater(room, participantSid);
|
|
17
|
+
*
|
|
18
|
+
* const handleUpdate = () => {
|
|
19
|
+
* updateTemplateKeys({
|
|
20
|
+
* user_name: "John",
|
|
21
|
+
* location: "New York",
|
|
22
|
+
* mood: "happy"
|
|
23
|
+
* });
|
|
24
|
+
* };
|
|
25
|
+
*
|
|
26
|
+
* return <button onClick={handleUpdate}>Update Templates</button>;
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export const useTemplateKeysUpdater = (room, participantSid) => {
|
|
31
|
+
const updateTemplateKeys = useCallback((templateKeys) => {
|
|
32
|
+
if (room &&
|
|
33
|
+
room.localParticipant &&
|
|
34
|
+
Object.keys(templateKeys).length > 0) {
|
|
35
|
+
const message = {
|
|
36
|
+
type: "update-template-keys",
|
|
37
|
+
data: {
|
|
38
|
+
template_keys: templateKeys,
|
|
39
|
+
participant_sid: participantSid || room.localParticipant.sid,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
const encodedData = new TextEncoder().encode(JSON.stringify(message));
|
|
43
|
+
room.localParticipant.publishData(encodedData, {
|
|
44
|
+
reliable: true,
|
|
45
|
+
});
|
|
46
|
+
logger.log("🔑 Template keys updated:", templateKeys, "SID:", participantSid || room.localParticipant.sid);
|
|
47
|
+
}
|
|
48
|
+
}, [room, participantSid]);
|
|
49
|
+
return {
|
|
50
|
+
updateTemplateKeys,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=useTemplateKeysUpdater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTemplateKeysUpdater.js","sourceRoot":"","sources":["../../src/hooks/useTemplateKeysUpdater.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAMzC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,IAAU,EACV,cAAsB,EACtB,EAAE;IACF,MAAM,kBAAkB,GAAG,WAAW,CACpC,CAAC,YAA0B,EAAE,EAAE;QAC7B,IACE,IAAI;YACJ,IAAI,CAAC,gBAAgB;YACrB,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,GAAG,CAAC,EACpC,CAAC;YACD,MAAM,OAAO,GAAG;gBACd,IAAI,EAAE,sBAAsB;gBAC5B,IAAI,EAAE;oBACJ,aAAa,EAAE,YAAY;oBAC3B,eAAe,EAAE,cAAc,IAAI,IAAI,CAAC,gBAAgB,CAAC,GAAG;iBAC7D;aACF,CAAC;YAEF,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;YACtE,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,WAAW,EAAE;gBAC7C,QAAQ,EAAE,IAAI;aACf,CAAC,CAAC;YAEH,MAAM,CAAC,GAAG,CAAC,2BAA2B,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc,IAAI,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;QAC7G,CAAC;IACH,CAAC,EACD,CAAC,IAAI,EAAE,cAAc,CAAC,CACvB,CAAC;IAEF,OAAO;QACL,kBAAkB;KACnB,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Room } from "livekit-client";
|
|
2
|
+
/**
|
|
3
|
+
* Hook for sending trigger messages to Convai.
|
|
4
|
+
*
|
|
5
|
+
* Sends system trigger messages that can activate specific behaviors
|
|
6
|
+
* or responses from the AI assistant.
|
|
7
|
+
*
|
|
8
|
+
* @param {Room} room - LiveKit room instance
|
|
9
|
+
* @param {string} participantSid - Participant session ID
|
|
10
|
+
* @returns {Object} Object containing sendTriggerMessage function
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* function TriggerComponent() {
|
|
15
|
+
* const { sendTriggerMessage } = useTriggerMessageSender(room, participantSid);
|
|
16
|
+
*
|
|
17
|
+
* const handleTrigger = () => {
|
|
18
|
+
* sendTriggerMessage("character_introduction", "User just entered the room");
|
|
19
|
+
* };
|
|
20
|
+
*
|
|
21
|
+
* return <button onClick={handleTrigger}>Send Trigger</button>;
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare const useTriggerMessageSender: (room: Room, participantSid: string) => {
|
|
26
|
+
sendTriggerMessage: (triggerName?: string, triggerMessage?: string) => void;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=useTriggerMessageSender.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTriggerMessageSender.d.ts","sourceRoot":"","sources":["../../src/hooks/useTriggerMessageSender.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAGtC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,uBAAuB,GAClC,MAAM,IAAI,EACV,gBAAgB,MAAM;uCAGL,MAAM,mBAAmB,MAAM;CA6BjD,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { logger } from "../utils/logger";
|
|
3
|
+
/**
|
|
4
|
+
* Hook for sending trigger messages to Convai.
|
|
5
|
+
*
|
|
6
|
+
* Sends system trigger messages that can activate specific behaviors
|
|
7
|
+
* or responses from the AI assistant.
|
|
8
|
+
*
|
|
9
|
+
* @param {Room} room - LiveKit room instance
|
|
10
|
+
* @param {string} participantSid - Participant session ID
|
|
11
|
+
* @returns {Object} Object containing sendTriggerMessage function
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* function TriggerComponent() {
|
|
16
|
+
* const { sendTriggerMessage } = useTriggerMessageSender(room, participantSid);
|
|
17
|
+
*
|
|
18
|
+
* const handleTrigger = () => {
|
|
19
|
+
* sendTriggerMessage("character_introduction", "User just entered the room");
|
|
20
|
+
* };
|
|
21
|
+
*
|
|
22
|
+
* return <button onClick={handleTrigger}>Send Trigger</button>;
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export const useTriggerMessageSender = (room, participantSid) => {
|
|
27
|
+
const sendTriggerMessage = useCallback((triggerName, triggerMessage) => {
|
|
28
|
+
if (room && room.localParticipant) {
|
|
29
|
+
const message = {
|
|
30
|
+
type: "trigger-message",
|
|
31
|
+
data: {
|
|
32
|
+
...(triggerName && { trigger_name: triggerName }),
|
|
33
|
+
...(triggerMessage && { trigger_message: triggerMessage }),
|
|
34
|
+
participant_sid: participantSid || room.localParticipant.sid,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
const encodedData = new TextEncoder().encode(JSON.stringify(message));
|
|
38
|
+
room.localParticipant.publishData(encodedData, {
|
|
39
|
+
reliable: true,
|
|
40
|
+
});
|
|
41
|
+
logger.log("🎯 Trigger message sent:", {
|
|
42
|
+
triggerName,
|
|
43
|
+
triggerMessage,
|
|
44
|
+
sid: participantSid || room.localParticipant.sid,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}, [room, participantSid]);
|
|
48
|
+
return {
|
|
49
|
+
sendTriggerMessage,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=useTriggerMessageSender.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTriggerMessageSender.js","sourceRoot":"","sources":["../../src/hooks/useTriggerMessageSender.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,C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ggle message to control whether the bot generates audio.
|
|
6
|
+
* This is more efficient than muting audio after generation, as it prevents
|
|
7
|
+
* audio generation at the source.
|
|
8
|
+
*
|
|
9
|
+
* @param {Room} room - LiveKit room instance
|
|
10
|
+
* @returns {Object} Object containing toggleTts function
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* function AudioControlComponent() {
|
|
15
|
+
* const { toggleTts } = useTtsToggle(room);
|
|
16
|
+
*
|
|
17
|
+
* const handleMute = () => {
|
|
18
|
+
* toggleTts(false); // Disable TTS generation
|
|
19
|
+
* };
|
|
20
|
+
*
|
|
21
|
+
* const handleUnmute = () => {
|
|
22
|
+
* toggleTts(true); // Enable TTS generation
|
|
23
|
+
* };
|
|
24
|
+
*
|
|
25
|
+
* return (
|
|
26
|
+
* <div>
|
|
27
|
+
* <button onClick={handleMute}>Mute TTS</button>
|
|
28
|
+
* <button onClick={handleUnmute}>Unmute TTS</button>
|
|
29
|
+
* </div>
|
|
30
|
+
* );
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare const useTtsToggle: (room: Room) => {
|
|
35
|
+
toggleTts: (enabled: boolean) => void;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=useTtsToggle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTtsToggle.d.ts","sourceRoot":"","sources":["../../src/hooks/useTtsToggle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAGtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,IAAI;yBAEzB,OAAO;CAiCpB,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { logger } from "../utils/logger";
|
|
3
|
+
/**
|
|
4
|
+
* Hook for toggling TTS (Text-to-Speech) generation in Convai.
|
|
5
|
+
*
|
|
6
|
+
* Sends a tts-toggle message to control whether the bot generates audio.
|
|
7
|
+
* This is more efficient than muting audio after generation, as it prevents
|
|
8
|
+
* audio generation at the source.
|
|
9
|
+
*
|
|
10
|
+
* @param {Room} room - LiveKit room instance
|
|
11
|
+
* @returns {Object} Object containing toggleTts function
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* function AudioControlComponent() {
|
|
16
|
+
* const { toggleTts } = useTtsToggle(room);
|
|
17
|
+
*
|
|
18
|
+
* const handleMute = () => {
|
|
19
|
+
* toggleTts(false); // Disable TTS generation
|
|
20
|
+
* };
|
|
21
|
+
*
|
|
22
|
+
* const handleUnmute = () => {
|
|
23
|
+
* toggleTts(true); // Enable TTS generation
|
|
24
|
+
* };
|
|
25
|
+
*
|
|
26
|
+
* return (
|
|
27
|
+
* <div>
|
|
28
|
+
* <button onClick={handleMute}>Mute TTS</button>
|
|
29
|
+
* <button onClick={handleUnmute}>Unmute TTS</button>
|
|
30
|
+
* </div>
|
|
31
|
+
* );
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export const useTtsToggle = (room) => {
|
|
36
|
+
const toggleTts = useCallback((enabled) => {
|
|
37
|
+
// Check if room is connected and localParticipant exists
|
|
38
|
+
if (!room || room.state === 'disconnected' || !room.localParticipant) {
|
|
39
|
+
logger.warn("Cannot toggle TTS: room is disconnected or localParticipant is unavailable");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const message = {
|
|
44
|
+
type: "tts-toggle",
|
|
45
|
+
data: {
|
|
46
|
+
"enabled": enabled
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const encodedData = new TextEncoder().encode(JSON.stringify(message));
|
|
50
|
+
room.localParticipant.publishData(encodedData, {
|
|
51
|
+
reliable: true,
|
|
52
|
+
});
|
|
53
|
+
logger.log(`🔊 TTS ${enabled ? 'enabled' : 'disabled'}`);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
logger.error("Failed to toggle TTS:", error);
|
|
57
|
+
// Re-throw to allow caller to handle
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
}, [room]);
|
|
61
|
+
return {
|
|
62
|
+
toggleTts,
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=useTtsToggle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTtsToggle.js","sourceRoot":"","sources":["../../src/hooks/useTtsToggle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAU,EAAE,EAAE;IACzC,MAAM,SAAS,GAAG,WAAW,CAC3B,CAAC,OAAgB,EAAE,EAAE;QACnB,yDAAyD;QACzD,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,KAAK,cAAc,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACrE,MAAM,CAAC,IAAI,CAAC,4EAA4E,CAAC,CAAC;YAC1F,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,MAAM,OAAO,GAAG;gBACd,IAAI,EAAE,YAAY;gBAClB,IAAI,EAAE;oBACJ,SAAS,EAAE,OAAO;iBACnB;aACF,CAAC;YAEF,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;YACtE,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,WAAW,EAAE;gBAC7C,QAAQ,EAAE,IAAI;aACf,CAAC,CAAC;YAEH,MAAM,CAAC,GAAG,CAAC,UAAU,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC;QAC3D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC;YAC7C,qCAAqC;YACrC,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC,EACD,CAAC,IAAI,CAAC,CACP,CAAC;IAEF,OAAO;QACL,SAAS;KACV,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Room } from "livekit-client";
|
|
2
|
+
/**
|
|
3
|
+
* Hook for sending user text messages to Convai.
|
|
4
|
+
*
|
|
5
|
+
* Sends programmatic text messages that are processed by the AI assistant
|
|
6
|
+
* but not displayed in the chat interface.
|
|
7
|
+
*
|
|
8
|
+
* @param {Room} room - LiveKit room instance
|
|
9
|
+
* @param {string} participantSid - Participant session ID
|
|
10
|
+
* @returns {Object} Object containing sendUserTextMessage function
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* function ChatComponent() {
|
|
15
|
+
* const { sendUserTextMessage } = useUserTextMessageSender(room, participantSid);
|
|
16
|
+
*
|
|
17
|
+
* const handleSendMessage = () => {
|
|
18
|
+
* sendUserTextMessage("Hello, how are you?");
|
|
19
|
+
* };
|
|
20
|
+
*
|
|
21
|
+
* return <button onClick={handleSendMessage}>Send Message</button>;
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare const useUserTextMessageSender: (room: Room, participantSid: string) => {
|
|
26
|
+
sendUserTextMessage: (text: string) => void;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=useUserTextMessageSender.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUserTextMessageSender.d.ts","sourceRoot":"","sources":["../../src/hooks/useUserTextMessageSender.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAGtC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,wBAAwB,GACnC,MAAM,IAAI,EACV,gBAAgB,MAAM;gCAGb,MAAM;CAuChB,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { logger } from "../utils/logger";
|
|
3
|
+
/**
|
|
4
|
+
* Hook for sending user text messages to Convai.
|
|
5
|
+
*
|
|
6
|
+
* Sends programmatic text messages that are processed by the AI assistant
|
|
7
|
+
* but not displayed in the chat interface.
|
|
8
|
+
*
|
|
9
|
+
* @param {Room} room - LiveKit room instance
|
|
10
|
+
* @param {string} participantSid - Participant session ID
|
|
11
|
+
* @returns {Object} Object containing sendUserTextMessage function
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* function ChatComponent() {
|
|
16
|
+
* const { sendUserTextMessage } = useUserTextMessageSender(room, participantSid);
|
|
17
|
+
*
|
|
18
|
+
* const handleSendMessage = () => {
|
|
19
|
+
* sendUserTextMessage("Hello, how are you?");
|
|
20
|
+
* };
|
|
21
|
+
*
|
|
22
|
+
* return <button onClick={handleSendMessage}>Send Message</button>;
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export const useUserTextMessageSender = (room, participantSid) => {
|
|
27
|
+
const sendUserTextMessage = useCallback((text) => {
|
|
28
|
+
// Check if room is connected and localParticipant exists
|
|
29
|
+
if (!room || room.state === 'disconnected' || !room.localParticipant) {
|
|
30
|
+
logger.warn("Cannot send message: room is disconnected or localParticipant is unavailable");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!text || !text.trim()) {
|
|
34
|
+
logger.warn("Cannot send message: text is empty");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const message = {
|
|
39
|
+
type: "user_text_message",
|
|
40
|
+
data: {
|
|
41
|
+
text: text.trim(),
|
|
42
|
+
participant_sid: participantSid || room.localParticipant.sid,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
const encodedData = new TextEncoder().encode(JSON.stringify(message));
|
|
46
|
+
room.localParticipant.publishData(encodedData, {
|
|
47
|
+
reliable: true,
|
|
48
|
+
});
|
|
49
|
+
logger.log("💬 User text message sent:", text.trim(), "SID:", participantSid || room.localParticipant.sid);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
logger.error("Failed to send user text message:", error);
|
|
53
|
+
// Re-throw to allow caller to handle
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}, [room, participantSid]);
|
|
57
|
+
return {
|
|
58
|
+
sendUserTextMessage,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=useUserTextMessageSender.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUserTextMessageSender.js","sourceRoot":"","sources":["../../src/hooks/useUserTextMessageSender.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,IAAU,EACV,cAAsB,EACtB,EAAE;IACF,MAAM,mBAAmB,GAAG,WAAW,CACrC,CAAC,IAAY,EAAE,EAAE;QACf,yDAAyD;QACzD,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,KAAK,cAAc,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACrE,MAAM,CAAC,IAAI,CAAC,8EAA8E,CAAC,CAAC;YAC5F,OAAO;QACT,CAAC;QAED,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;YAC1B,MAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;YAClD,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,MAAM,OAAO,GAAG;gBACd,IAAI,EAAE,mBAAmB;gBACzB,IAAI,EAAE;oBACJ,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE;oBACjB,eAAe,EAAE,cAAc,IAAI,IAAI,CAAC,gBAAgB,CAAC,GAAG;iBAC7D;aACF,CAAC;YAEF,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;YACtE,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,WAAW,EAAE;gBAC7C,QAAQ,EAAE,IAAI;aACf,CAAC,CAAC;YAEH,MAAM,CAAC,GAAG,CAAC,4BAA4B,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,cAAc,IAAI,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;QAC7G,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;YACzD,qCAAqC;YACrC,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC,EACD,CAAC,IAAI,EAAE,cAAc,CAAC,CACvB,CAAC;IAEF,OAAO;QACL,mBAAmB;KACpB,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Room } from "livekit-client";
|
|
2
|
+
export interface VideoControls {
|
|
3
|
+
isVideoEnabled: boolean;
|
|
4
|
+
isVideoHidden: boolean;
|
|
5
|
+
enableVideo: () => Promise<void>;
|
|
6
|
+
disableVideo: () => Promise<void>;
|
|
7
|
+
hideVideo: () => Promise<void>;
|
|
8
|
+
showVideo: () => Promise<void>;
|
|
9
|
+
toggleVideo: () => Promise<void>;
|
|
10
|
+
setVideoDevice: (deviceId: string) => Promise<void>;
|
|
11
|
+
getVideoDevices: () => Promise<MediaDeviceInfo[]>;
|
|
12
|
+
setVideoQuality: (quality: 'low' | 'medium' | 'high') => Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Hook for managing video controls in LiveKit.
|
|
16
|
+
*
|
|
17
|
+
* Provides methods to enable/disable camera, manage video devices,
|
|
18
|
+
* and control video visibility state.
|
|
19
|
+
*
|
|
20
|
+
* @param {Room | null} room - LiveKit room instance
|
|
21
|
+
* @returns {VideoControls} Object containing video control methods and state
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* function VideoControls() {
|
|
26
|
+
* const videoControls = useVideoControls(room);
|
|
27
|
+
*
|
|
28
|
+
* return (
|
|
29
|
+
* <div>
|
|
30
|
+
* <button onClick={videoControls.toggleVideo}>
|
|
31
|
+
* {videoControls.isVideoEnabled ? 'Disable Camera' : 'Enable Camera'}
|
|
32
|
+
* </button>
|
|
33
|
+
* </div>
|
|
34
|
+
* );
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare const useVideoControls: (room: Room | null) => VideoControls;
|
|
39
|
+
//# sourceMappingURL=useVideoControls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useVideoControls.d.ts","sourceRoot":"","sources":["../../src/hooks/useVideoControls.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAGtC,MAAM,WAAW,aAAa;IAE5B,cAAc,EAAE,OAAO,CAAC;IACxB,aAAa,EAAE,OAAO,CAAC;IAGvB,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,YAAY,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAGjC,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,eAAe,EAAE,MAAM,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;IAGlD,eAAe,EAAE,CAAC,OAAO,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACxE;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,IAAI,GAAG,IAAI,KAAG,aA0MpD,CAAC"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { useCallback, useState, useEffect } from "react";
|
|
2
|
+
import { logger } from "../utils/logger";
|
|
3
|
+
/**
|
|
4
|
+
* Hook for managing video controls in LiveKit.
|
|
5
|
+
*
|
|
6
|
+
* Provides methods to enable/disable camera, manage video devices,
|
|
7
|
+
* and control video visibility state.
|
|
8
|
+
*
|
|
9
|
+
* @param {Room | null} room - LiveKit room instance
|
|
10
|
+
* @returns {VideoControls} Object containing video control methods and state
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* function VideoControls() {
|
|
15
|
+
* const videoControls = useVideoControls(room);
|
|
16
|
+
*
|
|
17
|
+
* return (
|
|
18
|
+
* <div>
|
|
19
|
+
* <button onClick={videoControls.toggleVideo}>
|
|
20
|
+
* {videoControls.isVideoEnabled ? 'Disable Camera' : 'Enable Camera'}
|
|
21
|
+
* </button>
|
|
22
|
+
* </div>
|
|
23
|
+
* );
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export const useVideoControls = (room) => {
|
|
28
|
+
const [isVideoEnabled, setIsVideoEnabled] = useState(false);
|
|
29
|
+
const [isVideoHidden, setIsVideoHidden] = useState(false);
|
|
30
|
+
// Update video state when room changes
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (!room) {
|
|
33
|
+
setIsVideoEnabled(false);
|
|
34
|
+
setIsVideoHidden(false);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const localParticipant = room.localParticipant;
|
|
38
|
+
// Set initial state
|
|
39
|
+
setIsVideoEnabled(localParticipant.isCameraEnabled);
|
|
40
|
+
setIsVideoHidden(false); // LiveKit doesn't have a direct hidden state for video
|
|
41
|
+
// Listen for video state changes
|
|
42
|
+
const handleTrackMuted = (track) => {
|
|
43
|
+
if (track.source === 'camera') {
|
|
44
|
+
setIsVideoHidden(true);
|
|
45
|
+
logger.log("📹 Video hidden");
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const handleTrackUnmuted = (track) => {
|
|
49
|
+
if (track.source === 'camera') {
|
|
50
|
+
setIsVideoHidden(false);
|
|
51
|
+
logger.log("📹 Video shown");
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const handleTrackPublished = (publication) => {
|
|
55
|
+
if (publication.source === 'camera') {
|
|
56
|
+
setIsVideoEnabled(true);
|
|
57
|
+
logger.log("📹 Camera track published - video enabled");
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const handleTrackUnpublished = (publication) => {
|
|
61
|
+
if (publication.source === 'camera') {
|
|
62
|
+
setIsVideoEnabled(false);
|
|
63
|
+
logger.log("📹 Camera track unpublished - video disabled");
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
// Subscribe to events
|
|
67
|
+
localParticipant.on('trackMuted', handleTrackMuted);
|
|
68
|
+
localParticipant.on('trackUnmuted', handleTrackUnmuted);
|
|
69
|
+
localParticipant.on('trackPublished', handleTrackPublished);
|
|
70
|
+
localParticipant.on('trackUnpublished', handleTrackUnpublished);
|
|
71
|
+
return () => {
|
|
72
|
+
localParticipant.off('trackMuted', handleTrackMuted);
|
|
73
|
+
localParticipant.off('trackUnmuted', handleTrackUnmuted);
|
|
74
|
+
localParticipant.off('trackPublished', handleTrackPublished);
|
|
75
|
+
localParticipant.off('trackUnpublished', handleTrackUnpublished);
|
|
76
|
+
};
|
|
77
|
+
}, [room]);
|
|
78
|
+
// Enable video
|
|
79
|
+
const enableVideo = useCallback(async () => {
|
|
80
|
+
if (!room) {
|
|
81
|
+
logger.warn("Cannot enable video: no room connection");
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
await room.localParticipant.setCameraEnabled(true);
|
|
86
|
+
setIsVideoEnabled(true); // Update state immediately
|
|
87
|
+
logger.log("📹 Video enabled successfully");
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
logger.error("Failed to enable video:", error);
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}, [room]);
|
|
94
|
+
// Disable video
|
|
95
|
+
const disableVideo = useCallback(async () => {
|
|
96
|
+
if (!room) {
|
|
97
|
+
logger.warn("Cannot disable video: no room connection");
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
await room.localParticipant.setCameraEnabled(false);
|
|
102
|
+
setIsVideoEnabled(false); // Update state immediately
|
|
103
|
+
logger.log("📹 Video disabled successfully");
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
logger.error("Failed to disable video:", error);
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
}, [room]);
|
|
110
|
+
// Hide video
|
|
111
|
+
const hideVideo = useCallback(async () => {
|
|
112
|
+
if (!room) {
|
|
113
|
+
logger.warn("Cannot hide video: no room connection");
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
// For now, we'll just disable the camera as LiveKit doesn't have a direct hide method
|
|
118
|
+
await room.localParticipant.setCameraEnabled(false);
|
|
119
|
+
logger.log("📹 Video hidden successfully");
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
logger.error("Failed to hide video:", error);
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
}, [room]);
|
|
126
|
+
// Show video
|
|
127
|
+
const showVideo = useCallback(async () => {
|
|
128
|
+
if (!room) {
|
|
129
|
+
logger.warn("Cannot show video: no room connection");
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
await room.localParticipant.setCameraEnabled(true);
|
|
134
|
+
logger.log("📹 Video shown successfully");
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
logger.error("Failed to show video:", error);
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
}, [room]);
|
|
141
|
+
// Toggle video
|
|
142
|
+
const toggleVideo = useCallback(async () => {
|
|
143
|
+
if (isVideoEnabled) {
|
|
144
|
+
await disableVideo();
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
await enableVideo();
|
|
148
|
+
}
|
|
149
|
+
}, [isVideoEnabled, enableVideo, disableVideo]);
|
|
150
|
+
// Set video device
|
|
151
|
+
const setVideoDevice = useCallback(async (deviceId) => {
|
|
152
|
+
if (!room) {
|
|
153
|
+
logger.warn("Cannot set video device: no room connection");
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
await room.localParticipant.setCameraEnabled(true, { deviceId });
|
|
158
|
+
logger.log("📹 Video device changed to:", deviceId);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
logger.error("Failed to set video device:", error);
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
}, [room]);
|
|
165
|
+
// Get available video devices
|
|
166
|
+
const getVideoDevices = useCallback(async () => {
|
|
167
|
+
try {
|
|
168
|
+
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
169
|
+
const videoDevices = devices.filter(device => device.kind === 'videoinput');
|
|
170
|
+
logger.log("📹 Available video devices:", videoDevices);
|
|
171
|
+
return videoDevices;
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
logger.error("Failed to get video devices:", error);
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
}, []);
|
|
178
|
+
// Set video quality
|
|
179
|
+
const setVideoQuality = useCallback(async (quality) => {
|
|
180
|
+
if (!room) {
|
|
181
|
+
logger.warn("Cannot set video quality: no room connection");
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
// TODO: Implement video quality settings when LiveKit provides the API
|
|
186
|
+
logger.log("📹 Video quality set to:", quality);
|
|
187
|
+
logger.log("📹 Video quality settings not implemented yet");
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
logger.error("Failed to set video quality:", error);
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
}, [room]);
|
|
194
|
+
return {
|
|
195
|
+
// Video state
|
|
196
|
+
isVideoEnabled,
|
|
197
|
+
isVideoHidden,
|
|
198
|
+
// Video controls
|
|
199
|
+
enableVideo,
|
|
200
|
+
disableVideo,
|
|
201
|
+
hideVideo,
|
|
202
|
+
showVideo,
|
|
203
|
+
toggleVideo,
|
|
204
|
+
// Video settings
|
|
205
|
+
setVideoDevice,
|
|
206
|
+
getVideoDevices,
|
|
207
|
+
// Video quality
|
|
208
|
+
setVideoQuality,
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
//# sourceMappingURL=useVideoControls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useVideoControls.js","sourceRoot":"","sources":["../../src/hooks/useVideoControls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAsBzC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAiB,EAAiB,EAAE;IACnE,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,Q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AAc;QACd,eAAe;QAEf,gBAAgB;QAChB,eAAe;KAChB,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D,cAAc,SAAS,CAAC;AAGxB,cAAc,cAAc,CAAC;AAG7B,cAAc,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Main unified client export
|
|
2
|
+
export { useConvaiClient } from './hooks/useConvaiClient';
|
|
3
|
+
// Types
|
|
4
|
+
export * from './types';
|
|
5
|
+
// Components (for advanced usage)
|
|
6
|
+
export * from './components';
|
|
7
|
+
// Individual hooks (for advanced usage)
|
|
8
|
+
export * from './hooks';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,QAAQ;AACR,cAAc,SAAS,CAAC;AAExB,kCAAkC;AAClC,cAAc,cAAc,CAAC;AAE7B,wCAAwC;AACxC,cAAc,SAAS,CAAC"}
|