Skip to content

Commit 37ff838

Browse files
committed
Update guides with ReactNative versions
1 parent 967046d commit 37ff838

6 files changed

Lines changed: 605 additions & 0 deletions

File tree

client/concepts/events-and-callbacks.mdx

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ You are currently viewing the React version of this page. Use the dropdown to th
1313
You are currently viewing the JavaScript version of this page. Use the dropdown to the right to customize this page for your client framework.
1414
</Callout>
1515
</View>
16+
<View title="React Native" icon="mobile">
17+
<Callout icon="mobile" color="#FFC107">
18+
You are currently viewing the React Native version of this page. Use the dropdown to the right to customize this page for your client framework.
19+
</Callout>
20+
</View>
1621

1722
The Pipecat client emits events throughout the session lifecycle — when the bot connects, when the user speaks, when a transcript arrives, and more.
1823

@@ -69,6 +74,29 @@ Callbacks and event listeners are equivalent — use whichever pattern fits your
6974

7075
</View>
7176

77+
<View title="React Native" icon="mobile">
78+
79+
Use `useEffect` with `.on()` and `.off()` to subscribe and clean up within a component:
80+
81+
```tsx
82+
import { RTVIEvent } from "@pipecat-ai/client-js";
83+
import { useEffect } from "react";
84+
85+
function TranscriptDisplay() {
86+
useEffect(() => {
87+
const handler = (data) => {
88+
if (data.final) setTranscript(data.text);
89+
};
90+
client.on(RTVIEvent.UserTranscript, handler);
91+
return () => client.off(RTVIEvent.UserTranscript, handler);
92+
}, []);
93+
}
94+
```
95+
96+
Always return a cleanup function from `useEffect` to remove the listener when the component unmounts.
97+
98+
</View>
99+
72100
---
73101

74102
## Event reference
@@ -157,6 +185,24 @@ client.on(RTVIEvent.UserTranscript, (data) => {
157185

158186
</View>
159187

188+
<View title="React Native" icon="mobile">
189+
190+
```tsx
191+
useEffect(() => {
192+
const handler = (data) => {
193+
if (data.final) {
194+
addMessage(data.text); // committed
195+
} else {
196+
updatePartial(data.text); // still in progress
197+
}
198+
};
199+
client.on(RTVIEvent.UserTranscript, handler);
200+
return () => client.off(RTVIEvent.UserTranscript, handler);
201+
}, []);
202+
```
203+
204+
</View>
205+
160206
`BotOutput` is the recommended way to display the bot's response text. It provides the best possible representation of what the bot is saying — supporting interruptions and unspoken responses. By default, Pipecat aggregates output by sentences and words (assuming your TTS supports streaming), but custom aggregation strategies are supported too - like breaking out code snippets or other structured content:
161207

162208
<View title="React" icon="react">
@@ -186,6 +232,22 @@ client.on(RTVIEvent.BotOutput, (data) => {
186232

187233
</View>
188234

235+
<View title="React Native" icon="mobile">
236+
237+
```tsx
238+
useEffect(() => {
239+
const handler = (data) => {
240+
if (data.aggregated_by === "sentence") {
241+
appendSentence(data.text);
242+
}
243+
};
244+
client.on(RTVIEvent.BotOutput, handler);
245+
return () => client.off(RTVIEvent.BotOutput, handler);
246+
}, []);
247+
```
248+
249+
</View>
250+
189251
### Errors
190252

191253
| Event | Callback | When it fires |
@@ -226,6 +288,24 @@ client.on(RTVIEvent.Error, ({ data }) => {
226288

227289
</View>
228290

291+
<View title="React Native" icon="mobile">
292+
293+
```tsx
294+
useEffect(() => {
295+
const handler = ({ data }) => {
296+
if (data.fatal) {
297+
showReconnectPrompt(data.message);
298+
} else {
299+
showToast(data.message);
300+
}
301+
};
302+
client.on(RTVIEvent.Error, handler);
303+
return () => client.off(RTVIEvent.Error, handler);
304+
}, []);
305+
```
306+
307+
</View>
308+
229309
### Devices and tracks
230310

231311
| Event | Callback | When it fires |
@@ -285,3 +365,13 @@ For custom server\<-\>client messaging, see [Custom Messaging](/client/guides/cu
285365
</CardGroup>
286366

287367
</View>
368+
369+
<View title="React Native" icon="mobile">
370+
371+
<CardGroup cols={1}>
372+
<Card title="JavaScript SDK Callbacks" icon="js" href="/api-reference/client/js/callbacks">
373+
Complete callback signatures, data types, and transport compatibility
374+
</Card>
375+
</CardGroup>
376+
377+
</View>

client/concepts/media-management.mdx

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ You are currently viewing the React version of this page. Use the dropdown to th
1313
You are currently viewing the JavaScript version of this page. Use the dropdown to the right to customize this page for your client framework.
1414
</Callout>
1515
</View>
16+
<View title="React Native" icon="mobile">
17+
<Callout icon="mobile" color="#FFC107">
18+
You are currently viewing the React Native version of this page. Use the dropdown to the right to customize this page for your client framework.
19+
</Callout>
20+
</View>
1621

1722
The Pipecat client handles media at two levels: **local devices** (the user's mic, camera, and speakers) and **media tracks** (the live audio/video streams flowing between client and bot). This page covers how to work with both.
1823

@@ -57,6 +62,23 @@ client.on(RTVIEvent.TrackStarted, (track, participant) => {
5762

5863
</View>
5964

65+
<View title="React Native" icon="mobile">
66+
67+
Audio output is handled automatically by the platform via `DailyMediaManager` — no additional setup required. The bot's audio plays through the device speaker as soon as the session connects.
68+
69+
```tsx
70+
import { PipecatClient } from "@pipecat-ai/client-js";
71+
import { RNSmallWebRTCTransport } from "@pipecat-ai/react-native-small-webrtc-transport";
72+
import { DailyMediaManager } from "@pipecat-ai/react-native-daily-media-manager";
73+
74+
const client = new PipecatClient({
75+
transport: new RNSmallWebRTCTransport({ mediaManager: new DailyMediaManager() }),
76+
enableMic: true,
77+
});
78+
```
79+
80+
</View>
81+
6082
---
6183

6284
## Microphone
@@ -107,6 +129,29 @@ const muted = !client.isMicEnabled;
107129

108130
</View>
109131

132+
<View title="React Native" icon="mobile">
133+
134+
Call [`enableMic()`](/api-reference/client/js/client-methods#enablemic-enable-boolean) to mute and unmute. Track state with `useState`:
135+
136+
```tsx
137+
import { useState } from "react";
138+
import { Button } from "react-native";
139+
140+
function MicButton() {
141+
const [isMicEnabled, setIsMicEnabled] = useState(true);
142+
143+
const toggle = () => {
144+
const next = !isMicEnabled;
145+
client.enableMic(next);
146+
setIsMicEnabled(next);
147+
};
148+
149+
return <Button title={isMicEnabled ? "Mute" : "Unmute"} onPress={toggle} />;
150+
}
151+
```
152+
153+
</View>
154+
110155
### Switching microphones
111156

112157
<View title="React" icon="react">
@@ -150,6 +195,17 @@ client.on(RTVIEvent.AvailableMicsUpdated, (mics) => {
150195

151196
</View>
152197

198+
<View title="React Native" icon="mobile">
199+
200+
Enumerate available devices with [`getAllMics()`](/api-reference/client/js/client-methods#getallmics), then switch by `deviceId` using [`updateMic()`](/api-reference/client/js/client-methods#updatemic):
201+
202+
```tsx
203+
const mics = await client.getAllMics();
204+
client.updateMic(mics[1].deviceId);
205+
```
206+
207+
</View>
208+
153209
---
154210

155211
## Camera
@@ -212,6 +268,19 @@ Switch cameras with [`getAllCams()`](/api-reference/client/js/client-methods#get
212268

213269
</View>
214270

271+
<View title="React Native" icon="mobile">
272+
273+
Toggle the camera with [`enableCam()`](/api-reference/client/js/client-methods#enablecam-enable-boolean):
274+
275+
```tsx
276+
client.enableCam(true);
277+
const isOn = client.isCamEnabled;
278+
```
279+
280+
Switch cameras with [`getAllCams()`](/api-reference/client/js/client-methods#getallcams) / [`updateCam()`](/api-reference/client/js/client-methods#updatecam). To render video, use the `DailyMediaManager`'s video rendering capabilities per the React Native Daily SDK docs.
281+
282+
</View>
283+
215284
---
216285

217286
## Speakers
@@ -237,6 +306,12 @@ client.updateSpeaker(speakers[0].deviceId);
237306

238307
</View>
239308

309+
<View title="React Native" icon="mobile">
310+
311+
Audio routing (speaker vs. earpiece) is managed by the platform and `DailyMediaManager`. Use the React Native audio session APIs (e.g., `react-native-audio-session`) to control routing if needed.
312+
313+
</View>
314+
240315
---
241316

242317
## Device initialization before connecting
@@ -293,6 +368,29 @@ client.on(RTVIEvent.TrackStarted, (track, participant) => {
293368

294369
</View>
295370

371+
<View title="React Native" icon="mobile">
372+
373+
Use [`tracks()`](/api-reference/client/js/client-methods#tracks) to access tracks synchronously once the session is ready:
374+
375+
```tsx
376+
const { local, bot } = client.tracks();
377+
// local.audio, local.video, bot.audio, bot.video
378+
```
379+
380+
Or listen for `TrackStarted` to be notified as tracks become available:
381+
382+
```tsx
383+
useEffect(() => {
384+
const handler = (track, participant) => {
385+
// process track as needed
386+
};
387+
client.on(RTVIEvent.TrackStarted, handler);
388+
return () => client.off(RTVIEvent.TrackStarted, handler);
389+
}, []);
390+
```
391+
392+
</View>
393+
296394
---
297395

298396
## Audio visualization
@@ -334,6 +432,34 @@ client.on(RTVIEvent.LocalAudioLevel, (level) => {
334432

335433
</View>
336434

435+
<View title="React Native" icon="mobile">
436+
437+
Listen for `LocalAudioLevel` and `RemoteAudioLevel` events and drive your own visualization with `Animated` or any drawing library:
438+
439+
```tsx
440+
import { RTVIEvent } from "@pipecat-ai/client-js";
441+
import { useState, useEffect } from "react";
442+
import { View } from "react-native";
443+
444+
function AudioViz() {
445+
const [level, setLevel] = useState(0);
446+
447+
useEffect(() => {
448+
const handler = (l) => setLevel(l);
449+
client.on(RTVIEvent.LocalAudioLevel, handler);
450+
return () => client.off(RTVIEvent.LocalAudioLevel, handler);
451+
}, []);
452+
453+
return (
454+
<View style={{ width: 200, height: 8, backgroundColor: "#eee" }}>
455+
<View style={{ width: 200 * level, height: 8, backgroundColor: "#3b82f6" }} />
456+
</View>
457+
);
458+
}
459+
```
460+
461+
</View>
462+
337463
---
338464

339465
## API reference
@@ -363,3 +489,13 @@ client.on(RTVIEvent.LocalAudioLevel, (level) => {
363489
</CardGroup>
364490

365491
</View>
492+
493+
<View title="React Native" icon="mobile">
494+
495+
<CardGroup cols={1}>
496+
<Card title="Client Methods — Devices" icon="js" href="/api-reference/client/js/client-methods#devices">
497+
`initDevices`, `getAllMics`, `updateMic`, `enableMic`, `tracks`, and more
498+
</Card>
499+
</CardGroup>
500+
501+
</View>

0 commit comments

Comments
 (0)