Skip to content

Commit

Permalink
docs(react-native): more tutorial fixes (#1009)
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnarkhede authored Aug 29, 2023
1 parent 261b823 commit 8e27a8e
Showing 1 changed file with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,9 @@ const styles = StyleSheet.create({

Hit save and you should see on your emulator or device the following UI.

<!-- TODO: Update the following screenshot with video -->
<div>
<img src={homeScreenImg} alt="Preview of the Home Screen" width="50%" />
<img src={audioRoomEmptyImg} alt="Preview of empty audio room" width="50%" />
<div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'center' }}>
<img src={homeScreenImg} alt="Preview of the Home Screen" width="350" />
<img src={audioRoomEmptyImg} alt="Preview of empty audio room" width="350" />
</div>

Also lets store the credentials somewhere in a separate file. Create a file `config.js` in root directory of application next to `App.tsx`.
Expand Down Expand Up @@ -1191,7 +1190,8 @@ unsubscribe();
</TabItem>
</Tabs>

Now lets first implement the logic for requesting permission to speak when user presses on the microphone button.
Now, let's begin by first developing the logic to initiate a permission request for speaking when the user taps on the microphone button.


```tsx title="src/ToggleMicButton.tsx"
import {
Expand Down Expand Up @@ -1221,22 +1221,16 @@ export const ToggleMicButton = () => {
// highlight-end

const onPress = async () => {
// removed-line
call?.microphone.toggle();
// added-block-start
// highlight-start
if (!hasPermission) {
setIsAwaitingAudioApproval(true);
return call?.requestPermissions({
permissions: [OwnCapability.SEND_AUDIO],
});
}
// highlight-end

if (status === 'disabled') {
call?.microphone.enable();
} else {
call?.microphone.disable();
}
// added-block-end
call?.microphone.toggle();
};

return (
Expand All @@ -1255,7 +1249,34 @@ export const ToggleMicButton = () => {
};
```

And now we will wait for user to be notified when host or speakers grant or reject the permission request.
:::info
By default, the audio source is set to the device's speaker.
However, if you wish for the app to seamlessly switch between the earphone and speaker,
you can make use of the `useIncallManager` hook provided by the SDK. This hook internally utilizes
[react-native-incall-manager](https://github.com/react-native-webrtc/react-native-incall-manager#usage) library for this purpose.

```tsx title="src/ToggleMicButton.tsx"

import {
...
// highlight-next-line
useIncallManager,
} from '@stream-io/video-react-native-sdk';

export const ToggleMicButton = () => {
// start incall manager
// Please read more about `media` and `auto` options in the documentation of react-native-incall-manager
// https://github.com/react-native-webrtc/react-native-incall-manager#usage
// highlight-next-line
useIncallManager({media: 'video', auto: true});
...
}
```
:::

Let's proceed to add an event listener for the event `call.permissions_updated`.
This will keep the current user informed about any changes in permissions, whether they are granted or rejected by hosts or speakers.
It's worth noting that the current user in the app will already possess permission to speak, as the default permission configuration allows the call creator to transmit audio.

```tsx title="src/ToggleMicButton.tsx" {3,9,13-34}
import {
Expand Down

0 comments on commit 8e27a8e

Please sign in to comment.