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

Commit

Permalink
Revert "Add setStreamVolume() (#289)" (#292)
Browse files Browse the repository at this point in the history
This reverts most of commit 3bc8bfa.

We are keeping the renamed setVolume to setParticipantVolume.
  • Loading branch information
graduad authored Sep 11, 2023
1 parent 6ebe3e1 commit 4b3bc16
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.voxeet.sdk.models.Participant
import com.voxeet.sdk.models.ParticipantNotification
import com.voxeet.sdk.models.v1.ConferenceParticipantStatus
import com.voxeet.sdk.models.v2.ParticipantType
import com.voxeet.sdk.services.ConferenceService

/**
* Provides methods that map [Participant] and [Participant]-related models to React Native models and vice versa
Expand Down Expand Up @@ -68,26 +67,12 @@ class ParticipantMapper {

fun toRNMediaStream(stream: MediaStream): ReadableMap =
Arguments.createMap().apply {
putString(PARTICIPANT_STREAMS_ID, stream.peerId())
putString(PARTICIPANT_STREAMS_LABEL, stream.label())
putString(PARTICIPANT_STREAMS_ID, stream.label())
putString(PARTICIPANT_STREAMS_TYPE, toRNMediaStreamType(stream.type))
putArray(PARTICIPANT_STREAMS_AUDIO_TRACKS, toRNAudioTracks(stream.audioTracks()))
putArray(PARTICIPANT_STREAMS_VIDEO_TRACKS, toRNVideoTracks(stream.videoTracks()))
}

@Throws(Exception::class)
fun fromRNMediaStream(stream: ReadableMap, conferenceService: ConferenceService): MediaStream {
val peerId = stream.getString(PARTICIPANT_STREAMS_ID) ?: throw IllegalArgumentException("MediaStream should contain id")
val label = stream.getString(PARTICIPANT_STREAMS_LABEL) ?: throw IllegalArgumentException("MediaStream should contain label")
return findMediaStream(peerId, label, conferenceService) ?: throw Exception("Couldn't find the media stream")
}

private fun findMediaStream(peerId: String, label: String, conferenceService: ConferenceService): MediaStream? =
conferenceService
.findParticipantById(peerId)
?.streams()
?.find { it.label() == label }

private fun toRNParticipantType(participantType: ParticipantType) = when (participantType) {
ParticipantType.USER -> "USER"
ParticipantType.LISTENER -> "LISTENER"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.ReadableMap
import com.voxeet.android.media.MediaStream
import com.voxeet.sdk.models.Participant
import com.voxeet.sdk.services.AudioService
import com.voxeet.sdk.services.ConferenceService
Expand Down Expand Up @@ -99,21 +98,6 @@ class RNRemoteAudioModule(
.forward(promise, ignoreReturnType = true)
}

/**
* Sets the volume of a selected media stream in non-Dolby Voice conferences to a preferred value between 0 and 1.
* Providing an unsupported number results in constraining volume to a either 0 or 1.
* Using the method for a selected media stream after calling setOutputVolume or other setVolume methods overwrites
* the media stream's volume. This method is supported in SDK 3.11 and later.
*
* @param mediaStreamRN The selected media stream.
* @param volume The preferred volume level between 0 (no audio) and 1 (full volume).
*/
@ReactMethod
fun setStreamVolume(mediaStreamRN: ReadableMap, volume: Float, promise: ReactPromise) {
Promises.promise(audioService.remote.setVolume(participantMapper.fromRNMediaStream(mediaStreamRN, conferenceService), 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: 0 additions & 24 deletions docs/classes/internal.RemoteAudio.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ This model is supported only in SDK 3.7 and later.
- [start](internal.RemoteAudio.md#start)
- [stop](internal.RemoteAudio.md#stop)
- [setParticipantVolume](internal.RemoteAudio.md#setparticipantvolume)
- [setStreamVolume](internal.RemoteAudio.md#setstreamvolume)
- [setAllParticipantsVolume](internal.RemoteAudio.md#setallparticipantsvolume)

## Constructors
Expand Down Expand Up @@ -91,29 +90,6 @@ This method is supported in SDK 3.11 and later.

___

### setStreamVolume

**setStreamVolume**(`mediaStream`, `volume`): `Promise`<`void`\>

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

This method is supported in SDK 3.11 and later.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `mediaStream` | [`MediaStream`](../modules/internal.md#mediastream) | The selected media stream. |
| `volume` | `number` | The preferred volume level between 0 (no audio) and 1 (full volume). |

#### Returns

`Promise`<`void`\>

___

### setAllParticipantsVolume

**setAllParticipantsVolume**(`volume`): `Promise`<`void`\>
Expand Down
27 changes: 5 additions & 22 deletions example/src/screens/ConferenceScreen/ParticipantAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const ParticipantAvatar = ({ participant, scaleType }: ParticipantAvatarProps) =
SpatialConfigModalTypeModel.setSpatialDirectionType
);
const [volumeModalActive, setVolumeModalActive] = useState(false);
const [isSetStreamVolumeModal, setIsSetStreamVolumeModal] = useState(false);

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

useEffect(() => {
Expand All @@ -66,22 +66,6 @@ const ParticipantAvatar = ({ participant, scaleType }: ParticipantAvatarProps) =
value: 'set participant volume',
onSelect: () => {
if (me!.id !== participant.id) {
setIsSetStreamVolumeModal(false);
setVolumeModalActive(!volumeModalActive);
} else {
Alert.alert(
'Error',
'Action available only from remote participant avatar'
);
}
},
},
{
text: 'Set stream volume',
value: 'set stream volume',
onSelect: () => {
if (me!.id !== participant.id) {
setIsSetStreamVolumeModal(true);
setVolumeModalActive(!volumeModalActive);
} else {
Alert.alert(
Expand Down Expand Up @@ -217,11 +201,10 @@ const ParticipantAvatar = ({ participant, scaleType }: ParticipantAvatarProps) =
open={spatialConfigModalActive}
closeModal={() => setSpatialConfigModalActive(false)}
/>
<SetVolumeModal
isSetStreamVolume={isSetStreamVolumeModal}
open={volumeModalActive}
closeModal={() => setVolumeModalActive(false)}
participant={participant}
<SetVolumeModal
open={volumeModalActive}
closeModal={() => setVolumeModalActive(false)}
participant={participant}
/>
</Space>
);
Expand Down
25 changes: 8 additions & 17 deletions example/src/screens/ConferenceScreen/VolumeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ import { Modal } from 'react-native';
import Text from '@ui/Text';
import Button from '@ui/Button';
import Space from '@ui/Space';
import { setStreamVolume, setParticipantVolume } from '@utils/audio.tester';
import { setParticipantVolume } from '@utils/audio.tester';

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

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

const SetVolumeModal: FunctionComponent<SetVolumeModalProps> = ({
isSetStreamVolume,
open,
closeModal,
participant,
Expand All @@ -24,53 +23,45 @@ const SetVolumeModal: FunctionComponent<SetVolumeModalProps> = ({
closeModal();
};

const setVolume = async (participant: Participant, volume: number) => {
if (isSetStreamVolume) {
await setStreamVolume(participant, volume);
} else {
await setParticipantVolume(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">
{isSetStreamVolume ? "Set stream volume value" : "Set participant volume value"}
Set volume value
</Text>
</Space>
<Space mt="m" fw style={styles.modalButtonSection}>
<Button
text="0.0"
size="small"
color="dark"
onPress={() => setVolume(participant, 0.0)}
onPress={() => setParticipantVolume(participant, 0.0)}
/>
<Button
text="0.25"
size="small"
color="dark"
onPress={() => setVolume(participant, 0.25)}
onPress={() => setParticipantVolume(participant, 0.25)}
/>
<Button
text="0.5"
size="small"
color="dark"
onPress={() => setVolume(participant, 0.50)}
onPress={() => setParticipantVolume(participant, 0.50)}
/>
<Button
text="0.75"
size="small"
color="dark"
onPress={() => setVolume(participant, 0.75)}
onPress={() => setParticipantVolume(participant, 0.75)}
/>
<Button
text="1.0"
size="small"
color="dark"
onPress={() => setVolume(participant, 1.0)}
onPress={() => setParticipantVolume(participant, 1.0)}
/>
</Space>
<Space fw pt="xs" style={styles.modalButtonSection}>
Expand Down
11 changes: 0 additions & 11 deletions example/src/utils/audio.tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,3 @@ export const setAllParticipantsVolume = async (volume: number) => {
Alert.alert('Error');
}
};

export const setStreamVolume = async (participant: Participant, volume: number) => {
try {
const mediaStream = participant!.streams![0];
await CommsAPI.audio.getRemote().setStreamVolume(mediaStream, volume);
Logger.log(`Stream label: ${mediaStream.label}, volume: ${volume}`);
} catch (e) {
const msg = (e as Error).message;
Alert.alert('setVolume error', msg);
}
};
2 changes: 1 addition & 1 deletion src/VideoView/VideoView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default class VideoView extends PureComponent<Props, State> {
// @ts-ignore
ios: UIManager.COMVideoView.Commands.attach,
}),
[participant.id, mediaStream.label]
[participant.id, mediaStream.id]
));
this.setState({
mediaStream,
Expand Down
19 changes: 1 addition & 18 deletions src/services/audio/RemoteAudio.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NativeModules } from 'react-native';

import type { MediaStream, Participant } from '../conference/models';
import type { Participant } from '../conference/models';

const { CommsAPIRemoteAudioModule } = NativeModules;

Expand Down Expand Up @@ -53,23 +53,6 @@ export class RemoteAudio {
return this._remoteAudio.setParticipantVolume(participant, volume);
}

/**
* Sets the volume of a selected media stream in non-Dolby Voice conferences to a preferred value between 0 and 1.
* Providing an unsupported number results in constraining volume to a either 0 or 1.
* Using the method for a selected media stream after calling setOutputVolume or other setVolume methods overwrites the media stream's volume.
*
* This method is supported in SDK 3.11 and later.
*
* @param mediaStream The selected media stream.
* @param volume The preferred volume level between 0 (no audio) and 1 (full volume).
*/
public async setStreamVolume(
mediaStream: MediaStream,
volume: number
): Promise<void> {
return this._remoteAudio.setStreamVolume(mediaStream, 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.
Expand Down

0 comments on commit 4b3bc16

Please sign in to comment.