Skip to content

Commit 2461875

Browse files
authored
feature: include isCallActive in Android, added activeCalls method for getting available calls (Android/iOS) (#135)
1 parent 7169d9c commit 2461875

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ public boolean handleMethodCall(@NonNull MethodCall call, @NonNull Result result
213213
result.success(null);
214214
}
215215
break;
216+
case "isCallActive": {
217+
isCallActive((String)call.argument("uuid"), result);
218+
}
219+
break;
220+
case "activeCalls": {
221+
activeCalls(result);
222+
}
223+
break;
216224
default:
217225
return false;
218226
}
@@ -500,6 +508,25 @@ public void hasPermissions(@NonNull MethodChannel.Result result) {
500508
result.success(this.hasPermissions());
501509
}
502510

511+
public void isCallActive(String uuid, @NonNull MethodChannel.Result result) {
512+
if (!isConnectionServiceAvailable() || !hasPhoneAccount()) {
513+
result.success(false);
514+
return;
515+
}
516+
517+
Connection conn = VoiceConnectionService.getConnection(uuid);
518+
result.success(conn != null);
519+
}
520+
521+
public void activeCalls(@NonNull MethodChannel.Result result) {
522+
if (!isConnectionServiceAvailable() || !hasPhoneAccount()) {
523+
result.success(new ArrayList<>());
524+
return;
525+
}
526+
527+
result.success(VoiceConnectionService.getActiveConnections());
528+
}
529+
503530

504531
public void setAvailable(Boolean active) {
505532
VoiceConnectionService.setAvailable(active);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ public static Connection getConnection(String connectionId) {
7979
return null;
8080
}
8181

82+
public static List<String> getActiveConnections() {
83+
return new ArrayList<>(currentConnections.keySet());
84+
}
85+
8286
public VoiceConnectionService() {
8387
super();
8488
Log.e(TAG, "Constructor");

ios/Classes/CallKeep.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ - (BOOL)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
9494
else if ([@"isCallActive" isEqualToString:method]) {
9595
result(@([self isCallActive:argsMap[@"uuid"]]));
9696
}
97+
else if ([@"activeCalls" isEqualToString:method]) {
98+
result([self activeCalls]);
99+
}
97100
else if ([@"endCall" isEqualToString:method]) {
98101
[self endCall:argsMap[@"uuid"]];
99102
result(nil);
@@ -348,6 +351,24 @@ -(void) endAllCalls
348351
}
349352
}
350353

354+
-(NSArray*)activeCalls
355+
{
356+
#ifdef DEBUG
357+
NSLog(@"[CallKeep][activeCalls]");
358+
#endif
359+
CXCallObserver *callObserver = [[CXCallObserver alloc] init];
360+
361+
NSMutableString *uuids = [NSMutableString string];
362+
363+
for(CXCall *call in callObserver.calls){
364+
NSLog(@"[CallKeep] activeCall %@ ", call.UUID);
365+
NSString *uuid = [call.UUID UUIDString];
366+
[uuids appendString: uuid];
367+
}
368+
369+
return [NSArray arrayWithObject:uuids];
370+
}
371+
351372
-(void) setOnHold:(NSString *)uuidString shouldHold:(BOOL)shouldHold
352373
{
353374
#ifdef DEBUG

lib/src/api.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,20 @@ class FlutterCallkeep extends EventManager {
175175
return false;
176176
}
177177

178+
Future<List<String>> activeCalls() async {
179+
var resp = await _channel
180+
.invokeMethod<List<Object>?>('activeCalls', <String, dynamic>{});
181+
if (resp != null) {
182+
var uuids = <String>[];
183+
resp.forEach((element) {
184+
if (element != null && element is String)
185+
uuids.add(element);
186+
});
187+
return uuids;
188+
}
189+
return [];
190+
}
191+
178192
Future<void> endCall(String uuid) async => await _channel
179193
.invokeMethod<void>('endCall', <String, dynamic>{'uuid': uuid});
180194

0 commit comments

Comments
 (0)