@unith-ai/react-native
v0.1.8
Published
React Native WebView wrapper for Unith AI digital humans
Maintainers
Readme
@unith-ai/react-native
React Native WebView wrapper for the Unith AI digital human SDK. This package embeds the existing web SDK inside a WebView and bridges events/commands via postMessage.
Installation
npm install @unith-ai/react-native react-native-webviewUsage (component)
import { UnithConversationView } from "@unith-ai/react-native";
export default function Screen() {
return (
<UnithConversationView
style={{ height: 420 }}
options={{
orgId: "YOUR_ORG_ID",
headId: "YOUR_HEAD_ID",
apiKey: "YOUR_API_KEY",
language: "en-US",
username: "React Native User",
}}
onStatusChange={status => console.log("Status:", status)}
onConnect={data => console.log("Connected:", data)}
onDisconnect={data => console.log("Disconnected:", data)}
onMessage={msg => console.log("Message:", msg)}
onSuggestions={suggestions => console.log("Suggestions:", suggestions)}
onSpeakingStart={() => console.log("Speaking started")}
onSpeakingEnd={() => console.log("Speaking ended")}
onError={error => console.log("Error:", error)}
/>
);
}Usage (hook + custom WebView)
import { WebView } from "react-native-webview";
import { useConversation } from "@unith-ai/react-native";
export default function Screen() {
const convo = useConversation(
{
orgId: "YOUR_ORG_ID",
headId: "YOUR_HEAD_ID",
apiKey: "YOUR_API_KEY",
language: "en-US",
username: "React Native User",
},
{
onStatusChange: status => console.log("Status:", status),
onConnect: data => console.log("Connected:", data),
onDisconnect: data => console.log("Disconnected:", data),
onMessage: msg => console.log("Message:", msg),
onSuggestions: suggestions => console.log("Suggestions:", suggestions),
onSpeakingStart: () => console.log("Speaking started"),
onSpeakingEnd: () => console.log("Speaking ended"),
onError: error => console.log("Error:", error),
onSpeechRecognitionToken: token => console.log("Token:", token),
}
);
return <WebView ref={convo.webViewRef} {...convo.webViewProps} />;
}Examples
For a complete working example, check out the React Native example.
Available Events
onStatusChange- Fired when the conversation status changesonConnect- Fired when connection is establishedonDisconnect- Fired when disconnectedonMessage- Fired when a message is receivedonSuggestions- Fired when suggestions are availableonSpeakingStart- Fired when the digital human starts speakingonSpeakingEnd- Fired when the digital human stops speakingonTimeoutWarning- Fired as a warning before session timeoutonTimeout- Fired when the session times outonKeepSession- Fired to keep the session aliveonMuteStatusChange- Fired when mute status changesonError- Fired when an error occursonStoppingStart- Fired to signal we're in the process of stopping a response.onStoppingEnd- Fired to signal a response has been completely stopped.onSpeechRecognitionToken- Fired when the speech recognition token is generated.
Available Methods
The useConversation hook returns an object with the following methods:
startSession()- Start a new conversation sessionendSession()- End the current sessionsendMessage(text)- Send a text messagetoggleMute()- Toggle output mute statuskeepSession()- Keep the session alivestopResponse()- Stop an ongoing response
Configuration Options
orgId- Organization ID (required)headId- Digital human head ID (required)apiKey- API key for authentication (required)language- Language code (e.g., "en-US", default: undefined)username- Username for the session (default: undefined)
