Skip to content

Commit 20dcb9b

Browse files
author
Brandon Huang
committed
Add endAllCalls method to Android
1 parent 884d6a0 commit 20dcb9b

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import java.util.Arrays;
6262
import java.util.HashMap;
6363
import java.util.List;
64+
import java.util.Map;
6465
import java.util.ResourceBundle;
6566

6667
import static android.support.v4.app.ActivityCompat.requestPermissions;
@@ -192,6 +193,22 @@ public void endCall(String uuid) {
192193
Log.d(TAG, "endCall executed");
193194
}
194195

196+
@ReactMethod
197+
public void endAllCalls() {
198+
Log.d(TAG, "endAllCalls called");
199+
if (!isConnectionServiceAvailable() || !hasPhoneAccount()) {
200+
return;
201+
}
202+
203+
Map<String, VoiceConnection> currentConnections = VoiceConnectionService.currentConnections;
204+
for (Map.Entry<String, VoiceConnection> connectionEntry : currentConnections.entrySet()) {
205+
Connection connectionToEnd = connectionEntry.getValue();
206+
connectionToEnd.onDisconnect();
207+
}
208+
209+
Log.d(TAG, "endAllCalls executed");
210+
}
211+
195212
@ReactMethod
196213
public void checkPhoneAccountPermission(ReadableArray optionalPermissions, Promise promise) {
197214
Activity currentActivity = this.getCurrentActivity();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
public class VoiceConnectionService extends ConnectionService {
6464
private static Boolean isAvailable = false;
6565
private static String TAG = "RNCK:VoiceConnectionService";
66-
private static Map<String, VoiceConnection> currentConnections = new HashMap<>();
66+
public static Map<String, VoiceConnection> currentConnections = new HashMap<>();
6767

6868
public static Connection getConnection(String connectionId) {
6969
if (currentConnections.containsKey(connectionId)) {

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class RNCallKeep {
9494
};
9595

9696
endAllCalls = () => {
97-
isIOS ? RNCallKeepModule.endAllCalls() : RNCallKeepModule.endCall();
97+
RNCallKeepModule.endAllCalls();
9898
};
9999

100100
supportConnectionService = () => supportConnectionService;

0 commit comments

Comments
 (0)