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

Add setAllParticipantsVolume for RN + Android #287

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package io.dolby.sdk.comms.reactnative.services.audio

import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
Expand Down Expand Up @@ -85,6 +84,20 @@ class RNRemoteAudioModule(
.forward(promise, ignoreReturnType = true)
}

/**
* Sets the conference volume for the local participant.
* The method sets the volume of all remote participants to a preferred value between 0 and 1.
* Providing an unsupported volume results in constraining volume to a either 0 or 1.
* This method is supported in SDK 3.11 and later.
*
* @param volume
*/
@ReactMethod
fun setAllParticipantsVolume(volume: Float, promise: ReactPromise) {
Promises.promise(audioService.remote.setOutputVolume(volume))
.forward(promise, ignoreReturnType = true)
}

/**
* Gets [Participant] based on a React Native participant model. Throws
* [IllegalArgumentException] if participant id is invalid.
Expand Down
22 changes: 22 additions & 0 deletions docs/classes/internal.RemoteAudio.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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)
- [setAllParticipantsVolume](internal.RemoteAudio.md#setallparticipantsvolume)

## Constructors

Expand Down Expand Up @@ -86,3 +87,24 @@ This method is supported in SDK 3.11 and later.
#### Returns

`Promise`<`void`\>

___

### setAllParticipantsVolume

▸ **setAllParticipantsVolume**(`volume`): `Promise`<`void`\>

Sets the conference volume for the local participant. The method sets the volume of all remote participants to a preferred value between 0 and 1.
Providing an unsupported volume results in constraining volume to a either 0 or 1.

This method is supported in SDK 3.11 and later.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `volume` | `number` | The preferred volume level between 0 (no audio) and 1 (full volume). |

#### Returns

`Promise`<`void`\>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
setComfortNoiseLevel,
startLocalAudio,
stopLocalAudio,
setAllParticipantsVolume,
} from '@utils/audio.tester';
import { sendCommandMessage } from '@utils/command.tester';
import {
Expand Down Expand Up @@ -70,12 +71,12 @@ import {

import { Conference, VoiceFont } from '@dolbyio/comms-sdk-react-native/models';
import styles from './ConferenceScreen.style';
import {
AudioProcessingOptions,
VideoForwardingStrategy,
AudioCaptureMode,
ComfortNoiseLevel,
NoiseReductionLevel
import {
AudioProcessingOptions,
VideoForwardingStrategy,
AudioCaptureMode,
ComfortNoiseLevel,
NoiseReductionLevel
} from '@dolbyio/comms-sdk-react-native/models';
import { startLocalVideo, stopLocalVideo } from '@utils/video.tester';

Expand Down Expand Up @@ -160,8 +161,8 @@ const ConferenceScreenBottomSheet = () => {
},
];

const voiceFontAction: (voiceFont: VoiceFont) => () => void = (voiceFont) => {
return () => setAudioCaptureMode({ mode: AudioCaptureMode.Standard, noiseReduction: NoiseReductionLevel.Low, voiceFont: voiceFont })
const voiceFontAction: (voiceFont: VoiceFont) => () => void = (voiceFont) => {
return () => setAudioCaptureMode({ mode: AudioCaptureMode.Standard, noiseReduction: NoiseReductionLevel.Low, voiceFont: voiceFont })
};
const voiceFontOptions: Array<{
text: string;
Expand Down Expand Up @@ -345,17 +346,54 @@ const ConferenceScreenBottomSheet = () => {
</Text>
</Space>
<Button
size="small"
color="dark"
text="Start local audio"
onPress={() => startLocalAudio()}
/>
<Button
size="small"
color="dark"
text="Stop local audio"
onPress={() => stopLocalAudio()}
/>
<Space mb="xs">
<Text size="s" color={COLORS.BLACK}>
Set all participants volume
</Text>
</Space>
<Space mb="s" style={styles.actionButtons}>
<Button
size="small"
color="dark"
text="0.0"
onPress={() => setAllParticipantsVolume(0.0)}
/>
<Button
size="small"
color="dark"
text="0.25"
onPress={() => setAllParticipantsVolume(0.25)}
/>
<Button
size="small"
color="dark"
text="Start local audio"
onPress={() => startLocalAudio()}
text="0.5"
onPress={() => setAllParticipantsVolume(0.5)}
/>
<Button
size="small"
color="dark"
text="Stop local audio"
onPress={() => stopLocalAudio()}
text="0.75"
onPress={() => setAllParticipantsVolume(0.75)}
/>
<Button
size="small"
color="dark"
text="1.0"
onPress={() => setAllParticipantsVolume(1.0)}
/>
</Space>
<Space mb="s" style={styles.actionButtons}>
<Button
size="small"
Expand Down Expand Up @@ -399,18 +437,18 @@ const ConferenceScreenBottomSheet = () => {
</Space>
<Space mb="s" style={styles.actionButtons}>
{voiceFontOptions.map((option) => {
return (
<Button
key={option.text}
size="small"
color="dark"
text={option.text}
onPress={option.onClick}
/>
);
})}
return (
<Button
key={option.text}
size="small"
color="dark"
text={option.text}
onPress={option.onClick}
/>
);
})}
</Space>

<Space mb="xs">
<Text size="s" color={COLORS.BLACK}>
Video service
Expand Down
12 changes: 10 additions & 2 deletions example/src/utils/audio.tester.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Alert } from 'react-native';

import CommsAPI from '@dolbyio/comms-sdk-react-native';

import Logger from '@utils/Logger/Logger';
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 @@ -96,3 +95,12 @@ export const setVolume = async (participant: Participant, volume: number) => {
Alert.alert('setVolume error', msg);
}
};

export const setAllParticipantsVolume = async (volume: number) => {
try {
await CommsAPI.audio.getRemote().setAllParticipantsVolume(volume);
Logger.log(`All participants volume: ${volume}`);
} catch (e: any) {
Alert.alert('Error');
}
};
12 changes: 12 additions & 0 deletions src/services/audio/RemoteAudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ export class RemoteAudio {
): Promise<void> {
return this._remoteAudio.setVolume(participant, volume);
}

/**
* Sets the conference volume for the local participant. The method sets the volume of all remote participants to a preferred value between 0 and 1.
* Providing an unsupported volume results in constraining volume to a either 0 or 1.
*
* This method is supported in SDK 3.11 and later.
*
* @param volume The preferred volume level between 0 (no audio) and 1 (full volume).
*/
public async setAllParticipantsVolume(volume: number): Promise<void> {
return this._remoteAudio.setAllParticipantsVolume(volume);
}
}

export default new RemoteAudio();