Skip to content

Commit b2b878f

Browse files
committed
handle participant volume better, expose forceSpeakerphoneOn
1 parent 896b8af commit b2b878f

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

packages/client/src/devices/SpeakerManager.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,17 @@ export class SpeakerManager {
113113
* @param volume a number between 0 and 1. Set it to `undefined` to use the default volume.
114114
*/
115115
setParticipantVolume(sessionId: string, volume: number | undefined) {
116-
if (isReactNative()) {
117-
throw new Error(
118-
'This feature is not supported in React Native. Please visit https://getstream.io/video/docs/reactnative/core/camera-and-microphone/#speaker-management for more details',
119-
);
120-
}
121116
if (volume && (volume < 0 || volume > 1)) {
122117
throw new Error('Volume must be between 0 and 1, or undefined');
123118
}
124-
this.call.state.updateParticipant(sessionId, { audioVolume: volume });
119+
this.call.state.updateParticipant(sessionId, (p) => {
120+
if (isReactNative() && p.audioStream) {
121+
for (const track of p.audioStream.getAudioTracks()) {
122+
// @ts-expect-error track._setVolume is present in react-native-webrtc
123+
track?._setVolume(volume);
124+
}
125+
}
126+
return { audioVolume: volume };
127+
});
125128
}
126129
}

packages/react-native-sdk/src/modules/call-manager/CallManager.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ class SpeakerManager {
6363
NativeManager.unmuteAudioOutput();
6464
}
6565
};
66+
67+
/**
68+
* Forces speakerphone on/off.
69+
*/
70+
setForceSpeakerphoneOn = (force: boolean) => {
71+
NativeManager.setForceSpeakerphoneOn(force);
72+
};
6673
}
6774

6875
export class CallManager {

packages/react-native-sdk/src/modules/call-manager/native-module.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ export interface CallManager extends NativeModule {
6161
*/
6262
unmuteAudioOutput: () => void;
6363

64+
/**
65+
* Forces speakerphone on/off.
66+
*/
67+
setForceSpeakerphoneOn: (boolean) => void;
68+
6469
/**
6570
* Log the current audio state natively.
6671
* Meant for debugging purposes.

0 commit comments

Comments
 (0)