Skip to content

Commit 3dc8c21

Browse files
authored
Docs for using configureAudio in README (#86)
1 parent 046bd96 commit 3dc8c21

1 file changed

Lines changed: 43 additions & 3 deletions

File tree

README.md

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This library depends on `@livekit/react-native-webrtc`, which has additional ins
2929
- [iOS Installation Guide](https://github.com/livekit/react-native-webrtc/blob/master/Documentation/iOSInstallation.md)
3030
- [Android Installation Guide](https://github.com/livekit/react-native-webrtc/blob/master/Documentation/AndroidInstallation.md)
3131

32-
----
32+
---
3333

3434
Once the `@livekit/react-native-webrtc` dependency is installed, one last step is needed to finish the installation:
3535

@@ -106,8 +106,12 @@ const [room] = useState(() => new Room());
106106
const { participants } = useRoom(room);
107107

108108
useEffect(() => {
109-
AudioSession.startAudioSession();
110-
room.connect(url, token, {});
109+
let connect = async () => {
110+
await AudioSession.startAudioSession();
111+
await room.connect(url, token, {});
112+
console.log('connected to ', url, ' ', token);
113+
};
114+
connect();
111115
return () => {
112116
room.disconnect();
113117
AudioSession.stopAudioSession();
@@ -126,6 +130,40 @@ const videoView = participants.length > 0 && (
126130
127131
Additional documentation for the LiveKit SDK can be found at https://docs.livekit.io/references/client-sdks/
128132
133+
## Audio sessions
134+
135+
As seen in the above example, we've introduced a new class `AudioSession` that helps
136+
to manage the audio session on native platforms. This class wraps either [AudioManager](https://developer.android.com/reference/android/media/AudioManager) on Android, or [AVAudioSession](https://developer.apple.com/documentation/avfaudio/avaudiosession) on iOS.
137+
138+
You can customize the configuration of the audio session with `configureAudio`.
139+
140+
```js
141+
useEffect(() => {
142+
let connect = async () => {
143+
// configure audio session prior to starting it.
144+
await AudioSession.configureAudio({
145+
android: {
146+
preferredOutputList: ['earpiece'],
147+
// See [AudioManager](https://developer.android.com/reference/android/media/AudioManager)
148+
// for details on audio and focus modes.
149+
audioMode: 'normal',
150+
audioFocusMode: 'gain',
151+
},
152+
ios: {
153+
defaultOutput: 'earpiece',
154+
},
155+
});
156+
await AudioSession.startAudioSession();
157+
await room.connect(url, token, {});
158+
};
159+
connect();
160+
return () => {
161+
room.disconnect();
162+
AudioSession.stopAudioSession();
163+
};
164+
}, [url, token, room]);
165+
```
166+
129167
## Screenshare
130168
131169
Enabling screenshare requires extra installation steps:
@@ -196,7 +234,9 @@ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the
196234
Apache License 2.0
197235
198236
<!--BEGIN_REPO_NAV-->
237+
199238
<br/><table>
239+
200240
<thead><tr><th colspan="2">LiveKit Ecosystem</th></tr></thead>
201241
<tbody>
202242
<tr><td>Client SDKs</td><td><a href="https://github.com/livekit/components-js">Components</a> · <a href="https://github.com/livekit/client-sdk-js">JavaScript</a> · <a href="https://github.com/livekit/client-sdk-rust">Rust</a> · <a href="https://github.com/livekit/client-sdk-swift">iOS/macOS</a> · <a href="https://github.com/livekit/client-sdk-android">Android</a> · <a href="https://github.com/livekit/client-sdk-flutter">Flutter</a> · <a href="https://github.com/livekit/client-sdk-unity-web">Unity (web)</a> · <a href="https://github.com/livekit/client-sdk-python">Python</a> · <b>React Native (beta)</b></td></tr><tr></tr>

0 commit comments

Comments
 (0)