diff --git a/android/src/main/java/io/dolby/sdk/comms/reactnative/services/audio/RNRemoteAudioModule.kt b/android/src/main/java/io/dolby/sdk/comms/reactnative/services/audio/RNRemoteAudioModule.kt index 36674187..4023fbd9 100644 --- a/android/src/main/java/io/dolby/sdk/comms/reactnative/services/audio/RNRemoteAudioModule.kt +++ b/android/src/main/java/io/dolby/sdk/comms/reactnative/services/audio/RNRemoteAudioModule.kt @@ -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. diff --git a/docs/classes/internal.RemoteAudio.md b/docs/classes/internal.RemoteAudio.md index f647acfc..18866423 100644 --- a/docs/classes/internal.RemoteAudio.md +++ b/docs/classes/internal.RemoteAudio.md @@ -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 @@ -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`\> diff --git a/example/src/screens/ConferenceScreen/ConferenceScreen.style.ts b/example/src/screens/ConferenceScreen/ConferenceScreen.style.ts index 9dc897d0..c6ed855a 100644 --- a/example/src/screens/ConferenceScreen/ConferenceScreen.style.ts +++ b/example/src/screens/ConferenceScreen/ConferenceScreen.style.ts @@ -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, }, diff --git a/example/src/screens/ConferenceScreen/ParticipantAvatar.tsx b/example/src/screens/ConferenceScreen/ParticipantAvatar.tsx index 38437a47..abc6649c 100644 --- a/example/src/screens/ConferenceScreen/ParticipantAvatar.tsx +++ b/example/src/screens/ConferenceScreen/ParticipantAvatar.tsx @@ -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; @@ -37,6 +38,7 @@ const ParticipantAvatar = ({ participant, scaleType }: ParticipantAvatarProps) = useState( SpatialConfigModalTypeModel.setSpatialDirectionType ); + const [volumeModalActive, setVolumeModalActive] = useState(false); const [wasSpatialized, setWasSpatialized] = useState(false); @@ -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', @@ -185,6 +201,11 @@ const ParticipantAvatar = ({ participant, scaleType }: ParticipantAvatarProps) = open={spatialConfigModalActive} closeModal={() => setSpatialConfigModalActive(false)} /> + setVolumeModalActive(false)} + participant={participant} + /> ); }; diff --git a/example/src/screens/ConferenceScreen/VolumeModal.tsx b/example/src/screens/ConferenceScreen/VolumeModal.tsx new file mode 100644 index 00000000..e0069b91 --- /dev/null +++ b/example/src/screens/ConferenceScreen/VolumeModal.tsx @@ -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 = ({ + open, + closeModal, + participant, +}) => { + const closeModalWithoutSubmit = () => { + closeModal(); + }; + + const setParticipantVolume = async (participant: Participant, volume: number) => { + await setVolume(participant, volume); + }; + + return ( + + + + + + Set volume value + + + +