Skip to content

Commit 9e7b1f5

Browse files
authored
Merge pull request #295 from vtn-dev-prithipal/speakerOutputAndroid
Audio route to speaker for Android platform
2 parents 255b5f4 + af87fcf commit 9e7b1f5

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,21 @@ _This feature is available only on iOS._
398398
RNCallKeep.checkSpeaker();
399399
```
400400

401+
### toggleAudioRouteSpeaker
402+
403+
Update the audio route of Audio Service on Android with a `routeSpeaker` boolean value (`true` if speaker need on, `false` otherwise).
404+
When Phone call is active, Android control the audio via connection service. so this function help to toggle the audio to Speaker or wired/ear-piece or vice-versa
405+
406+
_This feature is available only on Android._
407+
408+
```js
409+
RNCallKeep.toggleAudioRouteSpeaker(uuid, true);
410+
```
411+
412+
- `uuid`: string
413+
- uuid of the current call.
414+
- `routeSpeaker`: boolean
415+
401416
### supportConnectionService (async)
402417

403418
Tells if `ConnectionService` is available on the device (returns a boolean).

android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,23 @@ public void setMutedCall(String uuid, boolean shouldMute) {
429429
}
430430
conn.onCallAudioStateChanged(newAudioState);
431431
}
432+
/**
433+
* toggle audio route for speaker via connection service function
434+
* @param uuid
435+
* @param routeSpeaker
436+
*/
437+
@ReactMethod
438+
public void toggleAudioRouteSpeaker(String uuid, boolean routeSpeaker) {
439+
VoiceConnection conn = (VoiceConnection) VoiceConnectionService.getConnection(uuid);
440+
if (conn == null) {
441+
return;
442+
}
443+
if (routeSpeaker) {
444+
conn.setAudioRoute(CallAudioState.ROUTE_SPEAKER);
445+
} else {
446+
conn.setAudioRoute(CallAudioState.ROUTE_EARPIECE);
447+
}
448+
}
432449

433450
@ReactMethod
434451
public void sendDTMF(String uuid, String key) {

index.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,13 @@ declare module 'react-native-callkeep' {
138138
* @description setMutedCall method is available only on iOS.
139139
*/
140140
static setMutedCall(uuid: string, muted: boolean): void
141-
141+
142+
/**
143+
* @description toggleAudioRouteSpeaker method is available only on Android.
144+
* @param uuid
145+
* @param routeSpeaker
146+
*/
147+
static toggleAudioRouteSpeaker(uuid: string, routeSpeaker: boolean): void
142148
static setOnHold(uuid: string, held: boolean): void
143149

144150
/**

index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,14 @@ class RNCallKeep {
182182
};
183183

184184
sendDTMF = (uuid, key) => RNCallKeepModule.sendDTMF(uuid, key);
185-
185+
/**
186+
* @description when Phone call is active, Android control the audio service via connection service. so this function help to toggle the audio to Speaker or wired/ear-piece or vice-versa
187+
* @param {*} uuid
188+
* @param {*} routeSpeaker
189+
* @returns Audio route state of audio service
190+
*/
191+
toggleAudioRouteSpeaker = (uuid, routeSpeaker) => isIOS ? null : RNCallKeepModule.toggleAudioRouteSpeaker(uuid, routeSpeaker);
192+
186193
checkIfBusy = () =>
187194
isIOS ? RNCallKeepModule.checkIfBusy() : Promise.reject('RNCallKeep.checkIfBusy was called from unsupported OS');
188195

0 commit comments

Comments
 (0)