Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio route to speaker for Android platform #295

Merged
Merged
Show file tree
Hide file tree
Changes from 9 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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,16 @@ _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: string, routeSpeaker: boolean);
```

### supportConnectionService (async)

Tells if `ConnectionService` is available on the device (returns a boolean).
Expand Down
17 changes: 17 additions & 0 deletions android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(useSpeaker){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be routeSpeaker here.
Can you please also reformat code and add space before ( and after ).
Same for the else below, space before { and after }.

conn.setAudioRoute(CallAudioState.ROUTE_SPEAKER);
}else{
conn.setAudioRoute(CallAudioState.ROUTE_EARPIECE);
}
}

@ReactMethod
public void sendDTMF(String uuid, String key) {
Expand Down
8 changes: 7 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Comment on lines +185 to +190

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated here b0a2fda

please review

toggleAudioRouteSpeaker = (uuid, routeSpeaker) => isIOS ? null : RNCallKeepModule.toggleAudioRouteSpeaker(uuid, routeSpeaker);

checkIfBusy = () =>
isIOS ? RNCallKeepModule.checkIfBusy() : Promise.reject('RNCallKeep.checkIfBusy was called from unsupported OS');

Expand Down