Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
Add setVolume(p: Participant) for android + RN (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpozy authored Sep 6, 2023
1 parent 2eba225 commit b332623
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ class RNRemoteAudioModule(
.forward(promise)
}

/**
* Sets the volume of a selected participant in non-Dolby Voice conferences to a preferred value between 0 and 1.
* Providing an unsupported number results in constraining the volume to either 0 or 1. Using the method for a selected participant
* after calling setOutputVolume overwrites the participant's volume. This method is supported in SDK 3.11 and later.
*
* @param participantRN The selected remote participant.
* @param volume The preferred volume level between 0 (no audio) and 1 (full volume).
*/
@ReactMethod
fun setVolume(participantRN: ReadableMap, volume: Float, promise: ReactPromise) {
Promises.promise(audioService.remote.setVolume(toParticipant(participantRN), volume))
.forward(promise, ignoreReturnType = true)
}

/**
* Gets [Participant] based on a React Native participant model. Throws
* [IllegalArgumentException] if participant id is invalid.
Expand Down
24 changes: 24 additions & 0 deletions docs/classes/internal.RemoteAudio.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This model is supported only in SDK 3.7 and later.

- [start](internal.RemoteAudio.md#start)
- [stop](internal.RemoteAudio.md#stop)
- [setVolume](internal.RemoteAudio.md#setvolume)

## Constructors

Expand Down Expand Up @@ -62,3 +63,26 @@ The stop method requires up to a few seconds to become effective.
#### Returns

`Promise`<`void`\>

___

### setVolume

**setVolume**(`participant`, `volume`): `Promise`<`void`\>

Sets the volume of a selected participant in non-Dolby Voice conferences to a preferred value between 0 and 1.
Providing an unsupported number results in constraining the volume to either 0 or 1.
Using the method for a selected participant after calling setOutputVolume overwrites the participant's volume.

This method is supported in SDK 3.11 and later.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `participant` | [`Participant`](../interfaces/internal.Participant.md) | The selected remote participant. |
| `volume` | `number` | The preferred volume level between 0 (no audio) and 1 (full volume). |

#### Returns

`Promise`<`void`\>
12 changes: 11 additions & 1 deletion example/src/screens/ConferenceScreen/ConferenceScreen.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,17 @@ export default StyleSheet.create({
elevation: SHADOWS.m.elevation,
flexDirection: 'column',
},

volumeModalContainer: {
backgroundColor: 'lightgray',
borderRadius: SPACE_XXS,
width: '80%',
height: '30%',
shadowOffset: SHADOWS.m.shadowOffset,
shadowOpacity: SHADOWS.m.shadowOpacity,
shadowRadius: SHADOWS.m.shadowRadius,
elevation: SHADOWS.m.elevation,
flexDirection: 'column',
},
modalTitleSection: {
flex: 1,
},
Expand Down
21 changes: 21 additions & 0 deletions example/src/screens/ConferenceScreen/ParticipantAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { SpatialConfigModalTypeModel } from './SpatialConfigModal';
import UpdatePermissionsModal from './UpdatePermissionsModal';
import { startRemoteVideo, stopRemoteVideo } from '@utils/video.tester';
import Video from './Video';
import SetVolumeModal from './VolumeModal';

type ParticipantAvatarProps = {
participant: Participant;
Expand All @@ -37,6 +38,7 @@ const ParticipantAvatar = ({ participant, scaleType }: ParticipantAvatarProps) =
useState<SpatialConfigModalTypeModel>(
SpatialConfigModalTypeModel.setSpatialDirectionType
);
const [volumeModalActive, setVolumeModalActive] = useState(false);

const [wasSpatialized, setWasSpatialized] = useState<boolean>(false);

Expand All @@ -59,6 +61,20 @@ const ParticipantAvatar = ({ participant, scaleType }: ParticipantAvatarProps) =
await kick(participant);
},
},
{
text: 'Set participant volume',
value: 'set participant volume',
onSelect: () => {
if (me!.id !== participant.id) {
setVolumeModalActive(!volumeModalActive);
} else {
Alert.alert(
'Error',
'Action available only from remote participant avatar'
);
}
},
},
{
text: 'Mute',
value: 'mute',
Expand Down Expand Up @@ -185,6 +201,11 @@ const ParticipantAvatar = ({ participant, scaleType }: ParticipantAvatarProps) =
open={spatialConfigModalActive}
closeModal={() => setSpatialConfigModalActive(false)}
/>
<SetVolumeModal
open={volumeModalActive}
closeModal={() => setVolumeModalActive(false)}
participant={participant}
/>
</Space>
);
};
Expand Down
85 changes: 85 additions & 0 deletions example/src/screens/ConferenceScreen/VolumeModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React, { FunctionComponent } from 'react';
import { Modal } from 'react-native';
import Text from '@ui/Text';
import Button from '@ui/Button';
import Space from '@ui/Space';
import { setVolume } from '@utils/audio.tester';

import styles from './ConferenceScreen.style';
import type { Participant } from '@dolbyio/comms-sdk-react-native/models';

type SetVolumeModalProps = {
open: boolean;
closeModal: () => void;
participant: Participant;
};

const SetVolumeModal: FunctionComponent<SetVolumeModalProps> = ({
open,
closeModal,
participant,
}) => {
const closeModalWithoutSubmit = () => {
closeModal();
};

const setParticipantVolume = async (participant: Participant, volume: number) => {
await setVolume(participant, volume);
};

return (
<Modal visible={open} animationType="fade" transparent>
<Space fw fh style={styles.modalBackground}>
<Space style={styles.volumeModalContainer}>
<Space mt="s">
<Text size="l" align="center" color="black">
Set volume value
</Text>
</Space>
<Space mt="m" fw style={styles.modalButtonSection}>
<Button
text="0.0"
size="small"
color="dark"
onPress={() => setParticipantVolume(participant, 0.0)}
/>
<Button
text="0.25"
size="small"
color="dark"
onPress={() => setParticipantVolume(participant, 0.25)}
/>
<Button
text="0.5"
size="small"
color="dark"
onPress={() => setParticipantVolume(participant, 0.50)}
/>
<Button
text="0.75"
size="small"
color="dark"
onPress={() => setParticipantVolume(participant, 0.75)}
/>
<Button
text="1.0"
size="small"
color="dark"
onPress={() => setParticipantVolume(participant, 1.0)}
/>
</Space>
<Space fw pt="xs" style={styles.modalButtonSection}>
<Button
text="Close"
size="small"
color="dark"
onPress={closeModalWithoutSubmit}
/>
</Space>
</Space>
</Space>
</Modal>
);
};

export default SetVolumeModal;
11 changes: 11 additions & 0 deletions example/src/utils/audio.tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
Participant,
} from '../../../src/services/conference/models';
import type { AudioCaptureModeOptions, ComfortNoiseLevel } from 'src/services/audio/models';
import Logger from '@utils/Logger/Logger';

export const startLocalAudio = async () => {
try {
Expand Down Expand Up @@ -85,3 +86,13 @@ export const setAudioCaptureMode = async (audioCaptureModeOptions: AudioCaptureM
Alert.alert('setAudioCaptureMode error', msg);
}
};

export const setVolume = async (participant: Participant, volume: number) => {
try {
await CommsAPI.audio.getRemote().setVolume(participant, volume);
Logger.log(`Participant: ${participant.info.name}, volume: ${volume}`);
} catch (e) {
const msg = (e as Error).message;
Alert.alert('setVolume error', msg);
}
};
17 changes: 17 additions & 0 deletions src/services/audio/RemoteAudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ export class RemoteAudio {
public async stop(participant: Participant): Promise<void> {
return this._remoteAudio.stop(participant);
}

/**
* Sets the volume of a selected participant in non-Dolby Voice conferences to a preferred value between 0 and 1.
* Providing an unsupported number results in constraining the volume to either 0 or 1.
* Using the method for a selected participant after calling setOutputVolume overwrites the participant's volume.
*
* This method is supported in SDK 3.11 and later.
*
* @param participant The selected remote participant.
* @param volume The preferred volume level between 0 (no audio) and 1 (full volume).
*/
public async setVolume(
participant: Participant,
volume: number
): Promise<void> {
return this._remoteAudio.setVolume(participant, volume);
}
}

export default new RemoteAudio();

0 comments on commit b332623

Please sign in to comment.