Skip to content

Commit 6c81cab

Browse files
committed
Add setForegroundServiceSettings method to avoid calling setup
1 parent 16410d5 commit 6c81cab

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@ Eg: When your used log out (or the connection to your server is broken, etc..),
130130
RNCallKeep.setAvailable(true);
131131
```
132132

133+
### setForegroundServiceSettings
134+
_This feature is available only on Android._
135+
136+
Configures the [Foreground Service](https://developer.android.com/about/versions/11/privacy/foreground-services) used for Android 11 to get microphone access on background.
137+
Similar to set the `foregroundService` key in the `setup()` method.
138+
139+
```js
140+
RNCallKeep.setForegroundServiceSettings({
141+
channelId: 'com.company.my',
142+
channelName: 'Foreground service for my app',
143+
notificationTitle: 'My app is running on background',
144+
});
145+
```
146+
133147
### canMakeMultipleCalls
134148
_This feature is available only on Android._
135149

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,11 @@ public void setAvailable(Boolean active) {
391391
VoiceConnectionService.setAvailable(active);
392392
}
393393

394+
@ReactMethod
395+
public void setForegroundServiceSettings(ReadableMap settings) {
396+
VoiceConnectionService.setSettings(settings);
397+
}
398+
394399
@ReactMethod
395400
public void canMakeMultipleCalls(Boolean allow) {
396401
VoiceConnectionService.setCanMakeMultipleCalls(allow);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ private Connection makeOutgoingCall(ConnectionRequest request, String uuid, Bool
217217

218218
private void startForegroundService() {
219219
if (_settings == null || !_settings.hasKey("foregroundService")) {
220+
Log.d(TAG, "Not creating foregroundService because not configured");
220221
return;
221222
}
222223
ReadableMap foregroundSettings = _settings.getMap("foregroundService");

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ declare module 'react-native-callkeep' {
138138
*/
139139
static setAvailable(active: boolean): void
140140

141+
static setForegroundServiceSettings(settings: Object): void
142+
141143
static canMakeMultipleCalls(allow: boolean): void
142144

143145
static setCurrentCallActive(callUUID: string): void

index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ class RNCallKeep {
190190
RNCallKeepModule.setAvailable(state);
191191
};
192192

193+
setForegroundServiceSettings = (settings) => {
194+
if (isIOS) {
195+
return;
196+
}
197+
198+
RNCallKeepModule.setForegroundServiceSettings({
199+
foregroundService: settings,
200+
});
201+
};
202+
193203
canMakeMultipleCalls = (state) => {
194204
if (isIOS) {
195205
return;

0 commit comments

Comments
 (0)