React Typescript
Set up and integrate Convai's Pixel Streaming component in your React TypeScript app using @convai/experience-embed.
Last updated
Was this helpful?
Was this helpful?
npm install @convai/experience-embedyarn add @convai/experience-embedpnpm add @convaiimport { PixelStreamComponent } from '@convai/experience-embed';import { useRef } from 'react';
import { PixelStreamComponentHandles } from '@convai/experience-embed';
const pixelStreamRef = useRef<PixelStreamComponentHandles>(null);<PixelStreamComponent
ref={pixelStreamRef}
expId="your-experience-id"
InitialScreen={<div>Loading your experience...</div>}
/>await pixelStreamRef.current?.enableCamera();
await pixelStreamRef.current?.disableCamera();await pixelStreamRef.current?.enableCharacterAudio();
await pixelStreamRef.current?.disableCharacterAudio();await pixelStreamRef.current?.initializeExperience();const CustomLoadingScreen = () => (
<div style={{
width: '100%',
height: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
background: '#000',
color: '#fff',
}}>
<h2>Loading your experience...</h2>
</div>
);<PixelStreamComponent
ref={pixelStreamRef}
expId="your-experience-id"
InitialScreen={<CustomLoadingScreen />}
/>import React, { useRef } from 'react';
import {
PixelStreamComponent,
PixelStreamComponentHandles,
} from '@convai/experience-embed';
function App() {
const pixelStreamRef = useRef<PixelStreamComponentHandles>(null);
const handleEnableCamera = async () => {
await pixelStreamRef.current?.enableCamera();
};
const handleDisableCamera = async () => {
await pixelStreamRef.current?.disableCamera();
};
return (
<div>
<PixelStreamComponent
ref={pixelStreamRef}
expId="your-experience-id"
InitialScreen={<div>Loading your experience...</div>}
/>
<button onClick={handleEnableCamera}>Enable Camera</button>
<button onClick={handleDisableCamera}>Disable Camera</button>
</div>
);
}
export default App;