@revrag-ai/embed-react-native 1.0.6 → 1.0.8
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/LICENSE +1 -1
- package/README.md +253 -274
- package/android/CMakeLists.txt +15 -0
- package/android/build.gradle +77 -25
- package/android/cpp-adapter.cpp +8 -0
- package/android/generated/java/com/revragai/embedreactnative/NativeEmbedReactNativeSpec.java +37 -0
- package/android/generated/jni/CMakeLists.txt +49 -0
- package/android/generated/jni/RNEmbedReactNativeSpec-generated.cpp +32 -0
- package/android/generated/jni/RNEmbedReactNativeSpec.h +31 -0
- package/android/generated/jni/react/renderer/components/RNEmbedReactNativeSpec/RNEmbedReactNativeSpecJSI-generated.cpp +28 -0
- package/android/generated/jni/react/renderer/components/RNEmbedReactNativeSpec/RNEmbedReactNativeSpecJSI.h +67 -0
- package/android/gradle.properties +5 -5
- package/cpp/revrag-ai-embed-react-native.cpp +7 -0
- package/cpp/revrag-ai-embed-react-native.h +8 -0
- package/ios/EmbedReactNative.h +9 -0
- package/ios/{Onwid.mm → EmbedReactNative.mm} +4 -4
- package/ios/generated/RNEmbedReactNativeSpec/RNEmbedReactNativeSpec-generated.mm +29 -0
- package/ios/generated/RNEmbedReactNativeSpec/RNEmbedReactNativeSpec.h +50 -0
- package/ios/generated/RNEmbedReactNativeSpecJSI-generated.cpp +28 -0
- package/ios/generated/RNEmbedReactNativeSpecJSI.h +67 -0
- package/lib/commonjs/NativeEmbedReactNative.js +9 -0
- package/{dist/commonjs/onwidApi → lib/commonjs/api}/api.js +86 -15
- package/lib/commonjs/api/types/embed.api.types.js +2 -0
- package/{dist/module/component/audiowave.js → lib/commonjs/components/Embed/EmbedAudioWave.js} +21 -17
- package/{dist/module/component/OnwidButton.js → lib/commonjs/components/Embed/EmbedButton.js} +65 -61
- package/{dist/module/component/voice.js → lib/commonjs/components/Embed/EmbedVoice.js} +18 -14
- package/{dist/commonjs/style/onwidButton.style.js → lib/commonjs/components/styles/EmbedButton.style.js} +14 -9
- package/{dist/module/Event/onwid.js → lib/commonjs/events/embed.event.js} +14 -10
- package/{dist → lib}/commonjs/hooks/initialize.js +22 -22
- package/{dist/commonjs/hooks/initializelivekit.js → lib/commonjs/hooks/initialize.livekit.js} +8 -5
- package/lib/commonjs/hooks/types/voiceAgent.types.js +6 -0
- package/{dist/module/hooks/voiceAgent.js → lib/commonjs/hooks/voiceagent.js} +36 -31
- package/lib/commonjs/index.js +34 -0
- package/{dist/module/index.d.js → lib/commonjs/index.types.js} +7 -7
- package/lib/commonjs/store/store.key.js +46 -0
- package/{dist/module/utils/reanimatedHelpers.js → lib/commonjs/utils/reanimated.helper.js} +23 -17
- package/lib/module/NativeEmbedReactNative.js +5 -0
- package/{dist/module/onwidApi → lib/module/api}/api.js +69 -6
- package/lib/module/api/types/embed.api.types.js +2 -0
- package/{dist/commonjs/component/audiowave.js → lib/module/components/Embed/EmbedAudioWave.js} +2 -3
- package/{dist/commonjs/component/OnwidButton.js → lib/module/components/Embed/EmbedButton.js} +10 -11
- package/{dist/commonjs/component/voice.js → lib/module/components/Embed/EmbedVoice.js} +1 -1
- package/{dist/module/style/onwidButton.style.js → lib/module/components/styles/EmbedButton.style.js} +3 -3
- package/{dist/commonjs/Event/onwid.js → lib/module/events/embed.event.js} +6 -6
- package/{dist → lib}/module/hooks/initialize.js +7 -13
- package/{dist/module/hooks/initializelivekit.js → lib/module/hooks/initialize.livekit.js} +1 -1
- package/{dist/commonjs/hooks/voiceAgent.js → lib/module/hooks/voiceagent.js} +4 -4
- package/lib/module/index.js +7 -0
- package/{dist/commonjs/index.d.js → lib/module/index.types.js} +2 -1
- package/{dist/commonjs/utils/reanimatedHelpers.js → lib/module/utils/reanimated.helper.js} +14 -14
- package/lib/typescript/module/package.json +1 -0
- package/package.json +71 -35
- package/react-native.config.js +8 -14
- package/revrag-ai-embed-react-native.podspec +41 -0
- package/Onwid.podspec +0 -20
- package/dist/commonjs/NativeOnwid.js +0 -5
- package/dist/commonjs/button.json +0 -1
- package/dist/commonjs/index.js +0 -34
- package/dist/commonjs/onwidApi/api.types.js +0 -2
- package/dist/commonjs/utils/utils.js +0 -2
- package/dist/module/NativeOnwid.js +0 -5
- package/dist/module/button.json +0 -1
- package/dist/module/hooks/voiceAgent.types.js +0 -4
- package/dist/module/index.js +0 -34
- package/dist/module/onwidApi/api.types.js +0 -2
- package/dist/module/store.key.js +0 -38
- package/dist/module/utils/utils.js +0 -2
- package/dist/typescript/Event/onwid.d.ts +0 -14
- package/dist/typescript/NativeOnwid.d.ts +0 -7
- package/dist/typescript/component/OnwidButton.d.ts +0 -29
- package/dist/typescript/component/audiowave.d.ts +0 -7
- package/dist/typescript/component/voice.d.ts +0 -16
- package/dist/typescript/hooks/initialize.d.ts +0 -3
- package/dist/typescript/hooks/initialize.types.d.ts +0 -6
- package/dist/typescript/hooks/initializelivekit.d.ts +0 -4
- package/dist/typescript/hooks/voiceAgent.d.ts +0 -3
- package/dist/typescript/hooks/voiceAgent.types.d.ts +0 -17
- package/dist/typescript/index.d.ts +0 -27
- package/dist/typescript/onwidApi/api.d.ts +0 -54
- package/dist/typescript/onwidApi/api.types.d.ts +0 -22
- package/dist/typescript/store.key.d.ts +0 -4
- package/dist/typescript/style/onwidButton.style.d.ts +0 -99
- package/dist/typescript/utils/reanimatedHelpers.d.ts +0 -30
- package/dist/typescript/utils/utils.d.ts +0 -1
- package/ios/Onwid.h +0 -5
- package/scripts/verify-setup.js +0 -90
- /package/{dist/commonjs/hooks → lib/commonjs/hooks/types}/initialize.types.js +0 -0
- /package/{dist/module/hooks → lib/module/hooks/types}/initialize.types.js +0 -0
- /package/{dist/commonjs/hooks → lib/module/hooks/types}/voiceAgent.types.js +0 -0
- /package/{dist/commonjs → lib/module/store}/store.key.js +0 -0
- /package/{dist → lib/typescript}/commonjs/package.json +0 -0
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _reactNative = require("@livekit/react-native");
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
6
10
|
// export interface VoiceProps {
|
|
7
11
|
// url: string;
|
|
8
12
|
// token: string;
|
|
9
13
|
// onDisconnected: (data: string) => void;
|
|
10
14
|
// onConnected: (data: string) => void;
|
|
11
15
|
// }
|
|
12
|
-
|
|
16
|
+
|
|
13
17
|
// Track audio session state globally to prevent multiple starts/stops
|
|
14
18
|
let audioSessionActive = false;
|
|
15
19
|
let audioSessionStarting = false;
|
|
@@ -25,9 +29,9 @@ const Voice = props => {
|
|
|
25
29
|
onConnected,
|
|
26
30
|
roomRef
|
|
27
31
|
} = props;
|
|
28
|
-
const [audioSessionStarted, setAudioSessionStarted] = useState(audioSessionActive);
|
|
29
|
-
const mountedRef = useRef(true);
|
|
30
|
-
const connectedRef = useRef(false);
|
|
32
|
+
const [audioSessionStarted, setAudioSessionStarted] = (0, _react.useState)(audioSessionActive);
|
|
33
|
+
const mountedRef = (0, _react.useRef)(true);
|
|
34
|
+
const connectedRef = (0, _react.useRef)(false);
|
|
31
35
|
|
|
32
36
|
// Start audio session safely - prevent multiple simultaneous starts
|
|
33
37
|
const startAudioSession = async () => {
|
|
@@ -38,7 +42,7 @@ const Voice = props => {
|
|
|
38
42
|
try {
|
|
39
43
|
audioSessionStarting = true;
|
|
40
44
|
console.log('Starting audio session');
|
|
41
|
-
await AudioSession.startAudioSession();
|
|
45
|
+
await _reactNative.AudioSession.startAudioSession();
|
|
42
46
|
audioSessionActive = true;
|
|
43
47
|
if (mountedRef.current) {
|
|
44
48
|
setAudioSessionStarted(true);
|
|
@@ -59,7 +63,7 @@ const Voice = props => {
|
|
|
59
63
|
try {
|
|
60
64
|
audioSessionStopping = true;
|
|
61
65
|
console.log('Stopping audio session');
|
|
62
|
-
await AudioSession.stopAudioSession();
|
|
66
|
+
await _reactNative.AudioSession.stopAudioSession();
|
|
63
67
|
audioSessionActive = false;
|
|
64
68
|
} catch (err) {
|
|
65
69
|
console.error('Failed to stop audio session:', err);
|
|
@@ -69,7 +73,7 @@ const Voice = props => {
|
|
|
69
73
|
};
|
|
70
74
|
|
|
71
75
|
// Setup audio session
|
|
72
|
-
useEffect(() => {
|
|
76
|
+
(0, _react.useEffect)(() => {
|
|
73
77
|
mountedRef.current = true;
|
|
74
78
|
startAudioSession();
|
|
75
79
|
return () => {
|
|
@@ -86,7 +90,7 @@ const Voice = props => {
|
|
|
86
90
|
}, []);
|
|
87
91
|
|
|
88
92
|
// Track connection state changes to avoid unmounting while connected
|
|
89
|
-
useEffect(() => {
|
|
93
|
+
(0, _react.useEffect)(() => {
|
|
90
94
|
if (token) {
|
|
91
95
|
activeConnectionToken = token;
|
|
92
96
|
}
|
|
@@ -105,7 +109,7 @@ const Voice = props => {
|
|
|
105
109
|
|
|
106
110
|
// IMPORTANT: Never return empty fragment when connected!
|
|
107
111
|
// Instead, always render the LiveKitRoom component to maintain the connection
|
|
108
|
-
return /*#__PURE__*/
|
|
112
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.LiveKitRoom, {
|
|
109
113
|
serverUrl: url,
|
|
110
114
|
token: token,
|
|
111
115
|
screen: false,
|
|
@@ -123,5 +127,5 @@ const Voice = props => {
|
|
|
123
127
|
}
|
|
124
128
|
});
|
|
125
129
|
};
|
|
126
|
-
|
|
127
|
-
//# sourceMappingURL=
|
|
130
|
+
var _default = exports.default = Voice;
|
|
131
|
+
//# sourceMappingURL=EmbedVoice.js.map
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.onwidButtonStyles = exports.createEmbedButtonStyles = exports.EXPANDED_WIDTH = exports.BUTTON_WIDTH = exports.BUTTON_HEIGHT = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
4
8
|
const {
|
|
5
9
|
width: SCREEN_WIDTH
|
|
6
|
-
} = Dimensions.get('window');
|
|
10
|
+
} = _reactNative.Dimensions.get('window');
|
|
7
11
|
|
|
8
12
|
// Calculate dynamic dimensions based on screen size
|
|
9
13
|
const calculateDimensions = () => {
|
|
@@ -26,10 +30,10 @@ const calculateDimensions = () => {
|
|
|
26
30
|
};
|
|
27
31
|
};
|
|
28
32
|
const dimensions = calculateDimensions();
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
const BUTTON_WIDTH = exports.BUTTON_WIDTH = dimensions.BUTTON_WIDTH;
|
|
34
|
+
const EXPANDED_WIDTH = exports.EXPANDED_WIDTH = dimensions.EXPANDED_WIDTH;
|
|
35
|
+
const BUTTON_HEIGHT = exports.BUTTON_HEIGHT = dimensions.BUTTON_HEIGHT;
|
|
36
|
+
const createEmbedButtonStyles = customStyles => {
|
|
33
37
|
const {
|
|
34
38
|
buttonWidth = BUTTON_WIDTH,
|
|
35
39
|
buttonHeight = BUTTON_HEIGHT,
|
|
@@ -38,7 +42,7 @@ export const createOnwidButtonStyles = customStyles => {
|
|
|
38
42
|
marginBottom = dimensions.SPACING.LARGE,
|
|
39
43
|
spacing = dimensions.SPACING
|
|
40
44
|
} = customStyles || {};
|
|
41
|
-
return StyleSheet.create({
|
|
45
|
+
return _reactNative.StyleSheet.create({
|
|
42
46
|
container: {
|
|
43
47
|
position: 'absolute',
|
|
44
48
|
bottom: 0,
|
|
@@ -239,5 +243,6 @@ export const createOnwidButtonStyles = customStyles => {
|
|
|
239
243
|
};
|
|
240
244
|
|
|
241
245
|
// Default styles export with dynamic dimensions
|
|
242
|
-
|
|
243
|
-
|
|
246
|
+
exports.createEmbedButtonStyles = createEmbedButtonStyles;
|
|
247
|
+
const onwidButtonStyles = exports.onwidButtonStyles = createEmbedButtonStyles();
|
|
248
|
+
//# sourceMappingURL=EmbedButton.style.js.map
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.EventKeys = void 0;
|
|
7
|
+
var _storeKey = require("../store/store.key.js");
|
|
8
|
+
var _api = require("../api/api.js");
|
|
5
9
|
// Predefined event keys
|
|
6
|
-
|
|
10
|
+
let EventKeys = exports.EventKeys = /*#__PURE__*/function (EventKeys) {
|
|
7
11
|
EventKeys["USER_DATA"] = "user_data";
|
|
8
12
|
EventKeys["SCREEN_STATE"] = "state_data";
|
|
9
13
|
return EventKeys;
|
|
10
14
|
}({});
|
|
11
|
-
class
|
|
15
|
+
class Embed {
|
|
12
16
|
events = {};
|
|
13
17
|
|
|
14
18
|
// Automatically adds a default listener if none exists
|
|
@@ -26,7 +30,7 @@ class OnWid {
|
|
|
26
30
|
}
|
|
27
31
|
const key = eventKey;
|
|
28
32
|
if (key !== EventKeys.USER_DATA) {
|
|
29
|
-
const userIdentity = await getAgentData(EventKeys.USER_DATA);
|
|
33
|
+
const userIdentity = await (0, _storeKey.getAgentData)(EventKeys.USER_DATA);
|
|
30
34
|
if (userIdentity) {
|
|
31
35
|
data.app_user_id = userIdentity.app_user_id;
|
|
32
36
|
} else {
|
|
@@ -39,7 +43,7 @@ class OnWid {
|
|
|
39
43
|
console.log('response,updateUserDatniuioioioa');
|
|
40
44
|
// Trigger API call
|
|
41
45
|
try {
|
|
42
|
-
const apiService = APIService.getInstance();
|
|
46
|
+
const apiService = _api.APIService.getInstance();
|
|
43
47
|
const response = await apiService.updateUserData({
|
|
44
48
|
eventKey: key,
|
|
45
49
|
data
|
|
@@ -48,7 +52,7 @@ class OnWid {
|
|
|
48
52
|
if (!response.success) {
|
|
49
53
|
console.error('Failed to trigger API for event:', eventKey);
|
|
50
54
|
}
|
|
51
|
-
setAgentData(data, key);
|
|
55
|
+
(0, _storeKey.setAgentData)(data, key);
|
|
52
56
|
} catch (error) {
|
|
53
57
|
console.error('Error triggering API:', error);
|
|
54
58
|
}
|
|
@@ -65,6 +69,6 @@ class OnWid {
|
|
|
65
69
|
this.events[eventKey]?.push(callback);
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
//# sourceMappingURL=
|
|
72
|
+
const embed = new Embed();
|
|
73
|
+
var _default = exports.default = embed;
|
|
74
|
+
//# sourceMappingURL=embed.event.js.map
|
|
@@ -1,38 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useInitialize = useInitialize;
|
|
7
|
+
var _storeKey = require("../store/store.key.js");
|
|
8
|
+
var _api = require("../api/api.js");
|
|
9
|
+
var _initializeLivekit = _interopRequireDefault(require("./initialize.livekit.js"));
|
|
10
|
+
var _reactNative = require("react-native");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
3
12
|
/**
|
|
4
13
|
* Custom hook for initializing the OnWid SDK
|
|
5
14
|
*
|
|
6
15
|
* Required Parameters:
|
|
7
16
|
* - apiKey: string - Unique identifier for the user
|
|
8
|
-
* - deviceId: string - Unique identifier for the device
|
|
9
|
-
* - metadata: object - Additional device/user information
|
|
10
17
|
*
|
|
11
18
|
* The initialization process:
|
|
12
19
|
* 1. Validates required input parameters
|
|
13
20
|
* 2. Stores API key securely in keychain
|
|
14
21
|
* 3. Registers the device with provided details
|
|
15
22
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
import registerAgent from './initializelivekit';
|
|
19
|
-
import { PermissionsAndroid, Platform } from 'react-native';
|
|
20
|
-
export function useInitialize({
|
|
23
|
+
|
|
24
|
+
function useInitialize({
|
|
21
25
|
apiKey,
|
|
22
|
-
|
|
23
|
-
metadata
|
|
26
|
+
embedUrl
|
|
24
27
|
}) {
|
|
25
28
|
const checkPermissions = async () => {
|
|
26
29
|
try {
|
|
27
30
|
// Check for required permissions on Android
|
|
28
|
-
if (Platform.OS === 'android') {
|
|
29
|
-
const recordAudioPermission = PermissionsAndroid.PERMISSIONS.RECORD_AUDIO;
|
|
31
|
+
if (_reactNative.Platform.OS === 'android') {
|
|
32
|
+
const recordAudioPermission = _reactNative.PermissionsAndroid.PERMISSIONS.RECORD_AUDIO;
|
|
30
33
|
if (!recordAudioPermission) {
|
|
31
34
|
throw new Error('RECORD_AUDIO permission not available');
|
|
32
35
|
}
|
|
33
36
|
const permissions = [recordAudioPermission];
|
|
34
|
-
const results = await Promise.all(permissions.map(permission => PermissionsAndroid.request(permission)));
|
|
35
|
-
const allGranted = results.every(result => result === PermissionsAndroid.RESULTS.GRANTED);
|
|
37
|
+
const results = await Promise.all(permissions.map(permission => _reactNative.PermissionsAndroid.request(permission)));
|
|
38
|
+
const allGranted = results.every(result => result === _reactNative.PermissionsAndroid.RESULTS.GRANTED);
|
|
36
39
|
if (!allGranted) {
|
|
37
40
|
throw new Error('Required permissions not granted');
|
|
38
41
|
}
|
|
@@ -51,29 +54,26 @@ export function useInitialize({
|
|
|
51
54
|
if (!apiKey || typeof apiKey !== 'string') {
|
|
52
55
|
throw new Error('apiKey is required and must be a string');
|
|
53
56
|
}
|
|
54
|
-
if (!
|
|
55
|
-
throw new Error('
|
|
56
|
-
}
|
|
57
|
-
if (metadata && typeof metadata === 'object' && !metadata.config) {
|
|
58
|
-
throw new Error('metadata must contain a config object');
|
|
57
|
+
if (!embedUrl || typeof embedUrl !== 'string') {
|
|
58
|
+
throw new Error('embedUrl is required and must be a string');
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
const initialize = async () => {
|
|
62
62
|
try {
|
|
63
63
|
await checkPermissions();
|
|
64
|
-
|
|
64
|
+
(0, _initializeLivekit.default)();
|
|
65
65
|
|
|
66
66
|
// Validate required parameters before proceeding
|
|
67
67
|
validateInputs();
|
|
68
68
|
|
|
69
69
|
// Store API key in keychain
|
|
70
|
-
await setAgentData({
|
|
70
|
+
await (0, _storeKey.setAgentData)({
|
|
71
71
|
apiKey,
|
|
72
|
-
|
|
72
|
+
embedUrl
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
// Get the APIService instance and initialize it
|
|
76
|
-
const apiService = APIService.getInstance();
|
|
76
|
+
const apiService = _api.APIService.getInstance();
|
|
77
77
|
await apiService.initialize();
|
|
78
78
|
console.log('registerOnInitialize');
|
|
79
79
|
// Register new device with provided details
|
package/{dist/commonjs/hooks/initializelivekit.js → lib/commonjs/hooks/initialize.livekit.js}
RENAMED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _reactNative = require("@livekit/react-native");
|
|
3
8
|
// This module imports the `registerGlobals` function from the LiveKit React Native library.
|
|
4
9
|
// The `registerGlobals` function is used to register global settings and configurations
|
|
5
10
|
// for the LiveKit service, which is essential for managing real-time audio and video
|
|
@@ -8,10 +13,8 @@
|
|
|
8
13
|
// Finally, the `registerAgent` is exported as the default export of this module, making
|
|
9
14
|
// it available for use in other modules that require the registration of LiveKit globals.
|
|
10
15
|
|
|
11
|
-
import { registerGlobals } from '@livekit/react-native';
|
|
12
|
-
|
|
13
16
|
// The registerAgent constant is an alias for the registerGlobals function,
|
|
14
17
|
// which is used to set up global configurations for the LiveKit service.
|
|
15
|
-
const registerAgent = registerGlobals;
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=
|
|
18
|
+
const registerAgent = _reactNative.registerGlobals;
|
|
19
|
+
var _default = exports.default = registerAgent;
|
|
20
|
+
//# sourceMappingURL=initialize.livekit.js.map
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useVoiceAgent = void 0;
|
|
7
|
+
var _livekitClient = require("livekit-client");
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _embedEvent = require("../events/embed.event.js");
|
|
10
|
+
var _api = require("../api/api.js");
|
|
11
|
+
var _storeKey = require("../store/store.key.js");
|
|
8
12
|
// Create a singleton instance of Room that persists across hook instances
|
|
9
13
|
// This ensures we don't create multiple Room instances that could conflict
|
|
10
14
|
let roomInstance = null;
|
|
@@ -21,7 +25,7 @@ const getRoomInstance = () => {
|
|
|
21
25
|
if (!roomInstance) {
|
|
22
26
|
console.log('Creating new Room instance');
|
|
23
27
|
// Configure the room with the right options at creation time
|
|
24
|
-
roomInstance = new Room({
|
|
28
|
+
roomInstance = new _livekitClient.Room({
|
|
25
29
|
adaptiveStream: true,
|
|
26
30
|
dynacast: true,
|
|
27
31
|
// Using the most stable configuration for React Native
|
|
@@ -52,7 +56,7 @@ const resetRoomState = () => {
|
|
|
52
56
|
console.log('isDisconnecting', isDisconnecting);
|
|
53
57
|
|
|
54
58
|
// Only disconnect if currently connected
|
|
55
|
-
if (roomInstance.state !== ConnectionState.Disconnected && !isDisconnecting) {
|
|
59
|
+
if (roomInstance.state !== _livekitClient.ConnectionState.Disconnected && !isDisconnecting) {
|
|
56
60
|
isDisconnecting = true;
|
|
57
61
|
roomInstance.disconnect().finally(() => {
|
|
58
62
|
isDisconnecting = false;
|
|
@@ -67,17 +71,17 @@ const resetRoomState = () => {
|
|
|
67
71
|
}
|
|
68
72
|
}
|
|
69
73
|
};
|
|
70
|
-
|
|
71
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
72
|
-
const [error, setError] = useState(null);
|
|
73
|
-
const [tokenDetails, setTokenDetails] = useState(null);
|
|
74
|
-
const [isMicMuted, setIsMicMuted] = useState(false);
|
|
75
|
-
const [connectionState, setConnectionState] = useState(() => {
|
|
74
|
+
const useVoiceAgent = () => {
|
|
75
|
+
const [isLoading, setIsLoading] = (0, _react.useState)(false);
|
|
76
|
+
const [error, setError] = (0, _react.useState)(null);
|
|
77
|
+
const [tokenDetails, setTokenDetails] = (0, _react.useState)(null);
|
|
78
|
+
const [isMicMuted, setIsMicMuted] = (0, _react.useState)(false);
|
|
79
|
+
const [connectionState, setConnectionState] = (0, _react.useState)(() => {
|
|
76
80
|
// Initialize with the current room state if it exists
|
|
77
81
|
const room = getRoomInstance();
|
|
78
|
-
return room ? room.state : ConnectionState.Disconnected;
|
|
82
|
+
return room ? room.state : _livekitClient.ConnectionState.Disconnected;
|
|
79
83
|
});
|
|
80
|
-
const [stableConnection, setStableConnection] = useState(false);
|
|
84
|
+
const [stableConnection, setStableConnection] = (0, _react.useState)(false);
|
|
81
85
|
console.log('ConnectionState_connected', connectionState
|
|
82
86
|
// tokenDetails?.token
|
|
83
87
|
);
|
|
@@ -92,7 +96,7 @@ export const useVoiceAgent = () => {
|
|
|
92
96
|
setConnectionState(() => state);
|
|
93
97
|
|
|
94
98
|
// Handle connection state changes
|
|
95
|
-
if (state === ConnectionState.Connected) {
|
|
99
|
+
if (state === _livekitClient.ConnectionState.Connected) {
|
|
96
100
|
// Reset connection attempts when connected successfully
|
|
97
101
|
resetConnectionAttempts();
|
|
98
102
|
|
|
@@ -105,7 +109,7 @@ export const useVoiceAgent = () => {
|
|
|
105
109
|
console.log('Connection marked as stable');
|
|
106
110
|
setStableConnection(true);
|
|
107
111
|
}, STABLE_CONNECTION_TIMEOUT);
|
|
108
|
-
} else if (state === ConnectionState.Disconnected) {
|
|
112
|
+
} else if (state === _livekitClient.ConnectionState.Disconnected) {
|
|
109
113
|
// Mark connection as unstable
|
|
110
114
|
setStableConnection(false);
|
|
111
115
|
|
|
@@ -143,7 +147,7 @@ export const useVoiceAgent = () => {
|
|
|
143
147
|
};
|
|
144
148
|
|
|
145
149
|
// Initialize room and listeners
|
|
146
|
-
useEffect(() => {
|
|
150
|
+
(0, _react.useEffect)(() => {
|
|
147
151
|
const room = getRoomInstance();
|
|
148
152
|
setupRoomListeners();
|
|
149
153
|
|
|
@@ -160,7 +164,7 @@ export const useVoiceAgent = () => {
|
|
|
160
164
|
}, []);
|
|
161
165
|
|
|
162
166
|
// Connect to LiveKit when token is set
|
|
163
|
-
useEffect(() => {
|
|
167
|
+
(0, _react.useEffect)(() => {
|
|
164
168
|
const room = getRoomInstance();
|
|
165
169
|
if (!tokenDetails || isConnecting) return;
|
|
166
170
|
|
|
@@ -182,9 +186,9 @@ export const useVoiceAgent = () => {
|
|
|
182
186
|
console.log(`Connecting to LiveKit room... (attempt ${connectionAttempts})`);
|
|
183
187
|
|
|
184
188
|
// Only attempt to connect if we're disconnected
|
|
185
|
-
if (room.state === ConnectionState.Disconnected) {
|
|
189
|
+
if (room.state === _livekitClient.ConnectionState.Disconnected) {
|
|
186
190
|
// Update state before connection attempt
|
|
187
|
-
setConnectionState(ConnectionState.Connecting);
|
|
191
|
+
setConnectionState(_livekitClient.ConnectionState.Connecting);
|
|
188
192
|
await room.connect(tokenDetails.server_url, tokenDetails.token, {
|
|
189
193
|
autoSubscribe: true // Ensure we subscribe to tracks automatically
|
|
190
194
|
});
|
|
@@ -192,10 +196,10 @@ export const useVoiceAgent = () => {
|
|
|
192
196
|
// Explicitly set to connected if connection was successful
|
|
193
197
|
setConnectionState(room.state);
|
|
194
198
|
console.log('Connected to LiveKit room');
|
|
195
|
-
} else if (room.state === ConnectionState.Connected) {
|
|
199
|
+
} else if (room.state === _livekitClient.ConnectionState.Connected) {
|
|
196
200
|
console.log('Room is already connected');
|
|
197
201
|
// Ensure our state matches
|
|
198
|
-
setConnectionState(ConnectionState.Connected);
|
|
202
|
+
setConnectionState(_livekitClient.ConnectionState.Connected);
|
|
199
203
|
} else {
|
|
200
204
|
console.log('Room is in transition state:', room.state);
|
|
201
205
|
// Sync our state with the room's current state
|
|
@@ -223,7 +227,7 @@ export const useVoiceAgent = () => {
|
|
|
223
227
|
}, [tokenDetails]);
|
|
224
228
|
|
|
225
229
|
// Log connection status periodically for debugging
|
|
226
|
-
useEffect(() => {
|
|
230
|
+
(0, _react.useEffect)(() => {
|
|
227
231
|
const debugInterval = setInterval(() => {
|
|
228
232
|
if (roomInstance) {
|
|
229
233
|
const state = roomInstance.state;
|
|
@@ -248,12 +252,12 @@ export const useVoiceAgent = () => {
|
|
|
248
252
|
// Reset connection attempts when starting fresh
|
|
249
253
|
resetConnectionAttempts();
|
|
250
254
|
setStableConnection(false);
|
|
251
|
-
const userData = await getAgentData(EventKeys.USER_DATA);
|
|
255
|
+
const userData = await (0, _storeKey.getAgentData)(_embedEvent.EventKeys.USER_DATA);
|
|
252
256
|
setIsLoading(true);
|
|
253
257
|
setError(null);
|
|
254
258
|
console.log('userData', userData);
|
|
255
259
|
try {
|
|
256
|
-
const apiService = APIService.getInstance();
|
|
260
|
+
const apiService = _api.APIService.getInstance();
|
|
257
261
|
const response = await apiService.getTokenDetails({
|
|
258
262
|
app_user_id: userData?.app_user_id,
|
|
259
263
|
call_type: 'EMBEDDED'
|
|
@@ -262,7 +266,7 @@ export const useVoiceAgent = () => {
|
|
|
262
266
|
|
|
263
267
|
// Only set token details if we're not already connected
|
|
264
268
|
const room = getRoomInstance();
|
|
265
|
-
if (room.state !== ConnectionState.Connected) {
|
|
269
|
+
if (room.state !== _livekitClient.ConnectionState.Connected) {
|
|
266
270
|
setTokenDetails(response.data);
|
|
267
271
|
} else {
|
|
268
272
|
console.log('Room already connected, skipping token update');
|
|
@@ -290,13 +294,13 @@ export const useVoiceAgent = () => {
|
|
|
290
294
|
resetConnectionAttempts();
|
|
291
295
|
setStableConnection(false);
|
|
292
296
|
const room = getRoomInstance();
|
|
293
|
-
if (room.state !== ConnectionState.Disconnected) {
|
|
297
|
+
if (room.state !== _livekitClient.ConnectionState.Disconnected) {
|
|
294
298
|
// Update state before disconnection
|
|
295
|
-
setConnectionState(ConnectionState.Connecting);
|
|
299
|
+
setConnectionState(_livekitClient.ConnectionState.Connecting);
|
|
296
300
|
await room.disconnect();
|
|
297
301
|
|
|
298
302
|
// Update state after disconnection
|
|
299
|
-
setConnectionState(ConnectionState.Disconnected);
|
|
303
|
+
setConnectionState(_livekitClient.ConnectionState.Disconnected);
|
|
300
304
|
}
|
|
301
305
|
} catch (err) {
|
|
302
306
|
setError(err instanceof Error ? err.message : 'Failed to end call');
|
|
@@ -350,4 +354,5 @@ export const useVoiceAgent = () => {
|
|
|
350
354
|
cleanup
|
|
351
355
|
};
|
|
352
356
|
};
|
|
353
|
-
|
|
357
|
+
exports.useVoiceAgent = useVoiceAgent;
|
|
358
|
+
//# sourceMappingURL=voiceagent.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Embed", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _embedEvent.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "EmbedButton", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _EmbedButton.EmbedButton;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "EmbedEventKeys", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _embedEvent.EventKeys;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "useInitialize", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _initialize.useInitialize;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
var _EmbedButton = require("./components/Embed/EmbedButton.js");
|
|
31
|
+
var _initialize = require("./hooks/initialize.js");
|
|
32
|
+
var _embedEvent = _interopRequireWildcard(require("./events/embed.event.js"));
|
|
33
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.EventKeys = void 0;
|
|
7
|
+
/* eslint-disable */
|
|
3
8
|
/**
|
|
4
9
|
* @file index.d.ts
|
|
5
10
|
* @description TypeScript declarations for the Onwid React Native library.
|
|
6
11
|
*/
|
|
7
|
-
|
|
8
12
|
// Component declarations
|
|
9
|
-
|
|
10
13
|
// Hook type declarations
|
|
11
|
-
|
|
12
14
|
// Hook declarations
|
|
13
|
-
|
|
14
15
|
// API type declarations
|
|
15
|
-
|
|
16
16
|
// Event system declarations
|
|
17
|
-
|
|
17
|
+
let EventKeys = exports.EventKeys = /*#__PURE__*/function (EventKeys) {
|
|
18
18
|
EventKeys["USER_DATA"] = "user_data";
|
|
19
19
|
EventKeys["SCREEN_STATE"] = "state_data";
|
|
20
20
|
return EventKeys;
|
|
21
21
|
}({});
|
|
22
|
-
//# sourceMappingURL=index.
|
|
22
|
+
//# sourceMappingURL=index.types.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.setAgentData = exports.getAgentData = exports.deleteFromDetail = void 0;
|
|
7
|
+
var _asyncStorage = _interopRequireDefault(require("@react-native-async-storage/async-storage"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
const STORAGE_KEY = '@user_data';
|
|
10
|
+
const setAgentData = async (data, key = STORAGE_KEY) => {
|
|
11
|
+
try {
|
|
12
|
+
const jsonString = JSON.stringify(data);
|
|
13
|
+
await _asyncStorage.default.setItem(key, jsonString);
|
|
14
|
+
console.log('Data saved to storage successfully');
|
|
15
|
+
} catch (error) {
|
|
16
|
+
console.error('Storage save error:', error);
|
|
17
|
+
throw error; // Re-throw to allow caller to handle
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
exports.setAgentData = setAgentData;
|
|
21
|
+
const getAgentData = async (key = STORAGE_KEY) => {
|
|
22
|
+
try {
|
|
23
|
+
const jsonString = await _asyncStorage.default.getItem(key);
|
|
24
|
+
if (!jsonString) {
|
|
25
|
+
console.log('No data stored');
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const data = JSON.parse(jsonString);
|
|
29
|
+
return data;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.error('Storage fetch error:', error);
|
|
32
|
+
throw error; // Re-throw to allow caller to handle
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.getAgentData = getAgentData;
|
|
36
|
+
const deleteFromDetail = async key => {
|
|
37
|
+
try {
|
|
38
|
+
await _asyncStorage.default.removeItem(key);
|
|
39
|
+
console.log('Storage data reset successfully');
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error('Storage reset error:', error);
|
|
42
|
+
throw error; // Re-throw to allow caller to handle
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.deleteFromDetail = deleteFromDetail;
|
|
46
|
+
//# sourceMappingURL=store.key.js.map
|