diff --git a/README.md b/README.md index c7f8482c..264d5077 100644 --- a/README.md +++ b/README.md @@ -398,6 +398,21 @@ _This feature is available only on iOS._ RNCallKeep.checkSpeaker(); ``` +### toggleAudioRouteSpeaker + +Update the audio route of Audio Service on Android with a `routeSpeaker` boolean value (`true` if speaker need on, `false` otherwise). +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 + +_This feature is available only on Android._ + +```js +RNCallKeep.toggleAudioRouteSpeaker(uuid, true); +``` + +- `uuid`: string + - uuid of the current call. +- `routeSpeaker`: boolean + ### supportConnectionService (async) Tells if `ConnectionService` is available on the device (returns a boolean). diff --git a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java index 327d49b4..f04903ab 100644 --- a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java +++ b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java @@ -417,6 +417,23 @@ public void setMutedCall(String uuid, boolean shouldMute) { } conn.onCallAudioStateChanged(newAudioState); } + /** + * toggle audio route for speaker via connection service function + * @param uuid + * @param routeSpeaker + */ + @ReactMethod + public void toggleAudioRouteSpeaker(String uuid, boolean routeSpeaker) { + VoiceConnection conn = (VoiceConnection) VoiceConnectionService.getConnection(uuid); + if (conn == null) { + return; + } + if (routeSpeaker) { + conn.setAudioRoute(CallAudioState.ROUTE_SPEAKER); + } else { + conn.setAudioRoute(CallAudioState.ROUTE_EARPIECE); + } + } @ReactMethod public void sendDTMF(String uuid, String key) { diff --git a/index.d.ts b/index.d.ts index 0ca7adf3..f03566f8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -138,7 +138,13 @@ declare module 'react-native-callkeep' { * @description setMutedCall method is available only on iOS. */ static setMutedCall(uuid: string, muted: boolean): void - + + /** + * @description toggleAudioRouteSpeaker method is available only on Android. + * @param uuid + * @param routeSpeaker + */ + static toggleAudioRouteSpeaker(uuid: string, routeSpeaker: boolean): void static setOnHold(uuid: string, held: boolean): void /** diff --git a/index.js b/index.js index 06278d59..085b1802 100644 --- a/index.js +++ b/index.js @@ -182,7 +182,14 @@ class RNCallKeep { }; sendDTMF = (uuid, key) => RNCallKeepModule.sendDTMF(uuid, key); - + /** + * @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 + * @param {*} uuid + * @param {*} routeSpeaker + * @returns Audio route state of audio service + */ + toggleAudioRouteSpeaker = (uuid, routeSpeaker) => isIOS ? null : RNCallKeepModule.toggleAudioRouteSpeaker(uuid, routeSpeaker); + checkIfBusy = () => isIOS ? RNCallKeepModule.checkIfBusy() : Promise.reject('RNCallKeep.checkIfBusy was called from unsupported OS');