# React Typescript

{% embed url="<https://www.npmjs.com/package/@convai/experience-embed>" %}

## Installation Instructions

To install `@convai/experience-embed` using your preferred package manager, use one of the following commands:

#### npm

```bash
npm install @convai/experience-embed
```

#### yarn

```bash
yarn add @convai/experience-embed
```

#### pnpm

```bash
pnpm add @convai
```

## Quick Start (React Ts)

### 1. Import the Component

```tsx
import { PixelStreamComponent } from '@convai/experience-embed';
```

***

### 2. Set Up a Ref to Access Methods

<pre class="language-tsx"><code class="lang-tsx"><strong>import { useRef } from 'react';
</strong>import { PixelStreamComponentHandles } from '@convai/experience-embed';

const pixelStreamRef = useRef&#x3C;PixelStreamComponentHandles>(null);
</code></pre>

### 3. Use the Component in JSX

```tsx
<PixelStreamComponent
  ref={pixelStreamRef}
  expId="your-experience-id"
  InitialScreen={<div>Loading your experience...</div>}
/>
```

{% hint style="info" %}
`expId` is your unique experience ID from Convai's dashboard.
{% endhint %}

### 4. Interact Using Available Methods

**Enable/Disable Camera**

```tsx
await pixelStreamRef.current?.enableCamera();
await pixelStreamRef.current?.disableCamera();
```

**Enable/Disable Character Audio**

```tsx
await pixelStreamRef.current?.enableCharacterAudio();
await pixelStreamRef.current?.disableCharacterAudio();
```

**Initialise the Experience**

```tsx
await pixelStreamRef.current?.initializeExperience();
```

### 5. Customise the Loading Screen (Optional)

```tsx
const CustomLoadingScreen = () => (
  <div style={{
    width: '100%',
    height: '100%',
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
    background: '#000',
    color: '#fff',
  }}>
    <h2>Loading your experience...</h2>
  </div>
);
```

Usage:

```tsx
<PixelStreamComponent
  ref={pixelStreamRef}
  expId="your-experience-id"
  InitialScreen={<CustomLoadingScreen />}
/>
```

## Full Example

```tsx
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;
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.convai.com/api-docs/plugins-and-integrations/convai-pixel-streaming-embed/react-typescript.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
