Skip to content

Commit f8abb24

Browse files
committed
giving it a go
1 parent 8034d7e commit f8abb24

File tree

6 files changed

+44
-35
lines changed

6 files changed

+44
-35
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.facebook.react.jstasks.HeadlessJsTaskConfig;
2828

2929
import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALLER_NAME;
30-
import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALL_NUMBER;
30+
import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALL_IDENTIFIER;
3131
import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALL_UUID;
3232

3333
import javax.annotation.Nullable;

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import android.telecom.PhoneAccount;
4444
import android.telecom.PhoneAccountHandle;
4545
import android.telecom.TelecomManager;
46+
import android.telecom.VideoProfile;
4647
import android.telephony.TelephonyManager;
4748
import android.util.Log;
4849

@@ -75,7 +76,7 @@ public class RNCallKeepModule extends ReactContextBaseJavaModule {
7576
public static final String CHECKING_PERMS = "CHECKING_PERMS";
7677
public static final String EXTRA_CALLER_NAME = "EXTRA_CALLER_NAME";
7778
public static final String EXTRA_CALL_UUID = "EXTRA_CALL_UUID";
78-
public static final String EXTRA_CALL_NUMBER = "EXTRA_CALL_NUMBER";
79+
public static final String EXTRA_CALL_IDENTIFIER = "EXTRA_CALL_IDENTIFIER";
7980
public static final String ACTION_END_CALL = "ACTION_END_CALL";
8081
public static final String ACTION_ANSWER_CALL = "ACTION_ANSWER_CALL";
8182
public static final String ACTION_MUTE_CALL = "ACTION_MUTE_CALL";
@@ -127,20 +128,24 @@ public void setup(ReadableMap options) {
127128
}
128129

129130
@ReactMethod
130-
public void displayIncomingCall(String uuid, String number, String callerName) {
131+
public void displayIncomingCall(String uuid, String identifier, String callerType, boolean callHasVideo, String callerName) {
131132
if (!isConnectionServiceAvailable() || !hasPhoneAccount()) {
132133
return;
133134
}
134135

135-
Log.d(TAG, "displayIncomingCall number: " + number + ", callerName: " + callerName);
136+
Log.d(TAG, "displayIncomingCall identifier: " + identifier + ", callerName: " + callerName);
136137

137138
Bundle extras = new Bundle();
138-
Uri uri = Uri.fromParts(PhoneAccount.SCHEME_TEL, number, null);
139+
Uri uri = Uri.fromParts((callerType.equals('sip') ? PhoneAccount.SCHEME_SIP : PhoneAccount.SCHEME_TEL), identifier, null);
139140

140141
extras.putParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, uri);
141142
extras.putString(EXTRA_CALLER_NAME, callerName);
142143
extras.putString(EXTRA_CALL_UUID, uuid);
143144

145+
if (callHasVideo) {
146+
extras.putParcelable(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, VideoProfile.STATE_BIDIRECTIONAL);
147+
}
148+
144149
telecomManager.addNewIncomingCall(handle, extras);
145150
}
146151

@@ -159,24 +164,28 @@ public void answerIncomingCall(String uuid) {
159164
}
160165

161166
@ReactMethod
162-
public void startCall(String uuid, String number, String callerName) {
163-
if (!isConnectionServiceAvailable() || !hasPhoneAccount() || !hasPermissions() || number == null) {
167+
public void startCall(String uuid, String identifer, String callerName, String callerType, boolean callHasVideo) {
168+
if (!isConnectionServiceAvailable() || !hasPhoneAccount() || !hasPermissions() || identifer == null) {
164169
return;
165170
}
166171

167-
Log.d(TAG, "startCall number: " + number + ", callerName: " + callerName);
172+
Log.d(TAG, "startCall identifer: " + identifer + ", callerName: " + callerName);
168173

169174
Bundle extras = new Bundle();
170-
Uri uri = Uri.fromParts(PhoneAccount.SCHEME_TEL, number, null);
175+
Uri uri = Uri.fromParts((callerType.equals('sip') ? PhoneAccount.SCHEME_SIP : PhoneAccount.SCHEME_TEL), identifer, null);
171176

172177
Bundle callExtras = new Bundle();
173178
callExtras.putString(EXTRA_CALLER_NAME, callerName);
174179
callExtras.putString(EXTRA_CALL_UUID, uuid);
175-
callExtras.putString(EXTRA_CALL_NUMBER, number);
180+
callExtras.putString(EXTRA_CALL_IDENTIFIER, identifer);
176181

177182
extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, handle);
178183
extras.putParcelable(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, callExtras);
179184

185+
if (callHasVideo) {
186+
extras.putParcelable(TelecomManager.EXTRA_INCOMING_VIDEO_STATE, VideoProfile.STATE_BIDIRECTIONAL);
187+
}
188+
180189
telecomManager.placeCall(uri, extras);
181190
}
182191

@@ -373,7 +382,7 @@ public void setCurrentCallActive(String uuid) {
373382
return;
374383
}
375384

376-
conn.setConnectionCapabilities(conn.getConnectionCapabilities() | Connection.CAPABILITY_HOLD);
385+
conn.setConnectionCapabilities(conn.getConnectionCapabilities());
377386
conn.setActive();
378387
}
379388

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import static io.wazo.callkeep.RNCallKeepModule.ACTION_UNHOLD_CALL;
4747
import static io.wazo.callkeep.RNCallKeepModule.ACTION_UNMUTE_CALL;
4848
import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALLER_NAME;
49-
import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALL_NUMBER;
49+
import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALL_IDENTIFIER;
5050
import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALL_UUID;
5151

5252
@TargetApi(Build.VERSION_CODES.M)
@@ -61,11 +61,11 @@ public class VoiceConnection extends Connection {
6161
this.handle = handle;
6262
this.context = context;
6363

64-
String number = handle.get(EXTRA_CALL_NUMBER);
64+
String identifier = handle.get(EXTRA_CALL_IDENTIFIER);
6565
String name = handle.get(EXTRA_CALLER_NAME);
6666

67-
if (number != null) {
68-
setAddress(Uri.parse(number), TelecomManager.PRESENTATION_ALLOWED);
67+
if (identifier != null) {
68+
setAddress(Uri.parse(identifier), TelecomManager.PRESENTATION_ALLOWED);
6969
}
7070
if (name != null && !name.equals("")) {
7171
setCallerDisplayName(name, TelecomManager.PRESENTATION_ALLOWED);
@@ -96,7 +96,7 @@ public void onAnswer() {
9696
super.onAnswer();
9797
Log.d(TAG, "onAnswer called");
9898

99-
setConnectionCapabilities(getConnectionCapabilities() | Connection.CAPABILITY_HOLD);
99+
setConnectionCapabilities(getConnectionCapabilities());
100100
setAudioModeIsVoip(true);
101101

102102
sendCallRequestToActivity(ACTION_ANSWER_CALL, handle);

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
import static io.wazo.callkeep.RNCallKeepModule.ACTION_UNMUTE_CALL;
6565
import static io.wazo.callkeep.RNCallKeepModule.ACTION_CHECK_REACHABILITY;
6666
import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALLER_NAME;
67-
import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALL_NUMBER;
67+
import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALL_IDENTIFIER;
6868
import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALL_UUID;
6969
import static io.wazo.callkeep.RNCallKeepModule.handle;
7070

@@ -125,7 +125,7 @@ public static void deinitConnection(String connectionId) {
125125
@Override
126126
public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
127127
Bundle extra = request.getExtras();
128-
Uri number = request.getAddress();
128+
Uri identifier = request.getAddress();
129129
String name = extra.getString(EXTRA_CALLER_NAME);
130130
Connection incomingCallConnection = createConnection(request);
131131
incomingCallConnection.setRinging();
@@ -151,27 +151,27 @@ public Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManage
151151
private Connection makeOutgoingCall(ConnectionRequest request, String uuid, Boolean forceWakeUp) {
152152
Bundle extras = request.getExtras();
153153
Connection outgoingCallConnection = null;
154-
String number = request.getAddress().getSchemeSpecificPart();
155-
String extrasNumber = extras.getString(EXTRA_CALL_NUMBER);
154+
String identifier = request.getAddress().getSchemeSpecificPart();
155+
String extrasIdentifier = extras.getString(EXTRA_CALL_IDENTIFIER);
156156
String displayName = extras.getString(EXTRA_CALLER_NAME);
157157
Boolean isForeground = VoiceConnectionService.isRunning(this.getApplicationContext());
158158

159-
Log.d(TAG, "makeOutgoingCall:" + uuid + ", number: " + number + ", displayName:" + displayName);
159+
Log.d(TAG, "makeOutgoingCall:" + uuid + ", identifier: " + identifier + ", displayName:" + displayName);
160160

161161
// Wakeup application if needed
162162
if (!isForeground || forceWakeUp) {
163163
Log.d(TAG, "onCreateOutgoingConnection: Waking up application");
164-
this.wakeUpApplication(uuid, number, displayName);
164+
this.wakeUpApplication(uuid, identifier, displayName);
165165
} else if (!this.canMakeOutgoingCall() && isReachable) {
166166
Log.d(TAG, "onCreateOutgoingConnection: not available");
167167
return Connection.createFailedConnection(new DisconnectCause(DisconnectCause.LOCAL));
168168
}
169169

170170
// TODO: Hold all other calls
171-
if (extrasNumber == null || !extrasNumber.equals(number)) {
171+
if (extrasIdentifier == null || !extrasIdentifier.equals(number)) {
172172
extras.putString(EXTRA_CALL_UUID, uuid);
173173
extras.putString(EXTRA_CALLER_NAME, displayName);
174-
extras.putString(EXTRA_CALL_NUMBER, number);
174+
extras.putString(EXTRA_CALL_IDENTIFIER, identifier);
175175
}
176176

177177
outgoingCallConnection = createConnection(request);
@@ -195,15 +195,15 @@ private Connection makeOutgoingCall(ConnectionRequest request, String uuid, Bool
195195
return outgoingCallConnection;
196196
}
197197

198-
private void wakeUpApplication(String uuid, String number, String displayName) {
198+
private void wakeUpApplication(String uuid, String identifier, String displayName) {
199199
Intent headlessIntent = new Intent(
200200
this.getApplicationContext(),
201201
RNCallKeepBackgroundMessagingService.class
202202
);
203203
headlessIntent.putExtra("callUUID", uuid);
204204
headlessIntent.putExtra("name", displayName);
205-
headlessIntent.putExtra("handle", number);
206-
Log.d(TAG, "wakeUpApplication: " + uuid + ", number : " + number + ", displayName:" + displayName);
205+
headlessIntent.putExtra("handle", identifier);
206+
Log.d(TAG, "wakeUpApplication: " + uuid + ", identifier : " + identifier + ", displayName:" + displayName);
207207

208208
ComponentName name = this.getApplicationContext().startService(headlessIntent);
209209
if (name != null) {
@@ -217,9 +217,9 @@ private void wakeUpAfterReachabilityTimeout(ConnectionRequest request) {
217217
}
218218
Log.d(TAG, "checkReachability timeout, force wakeup");
219219
Bundle extras = request.getExtras();
220-
String number = request.getAddress().getSchemeSpecificPart();
220+
String identifier = request.getAddress().getSchemeSpecificPart();
221221
String displayName = extras.getString(EXTRA_CALLER_NAME);
222-
wakeUpApplication(this.notReachableCallUuid, number, displayName);
222+
wakeUpApplication(this.notReachableCallUuid, identifier, displayName);
223223

224224
VoiceConnectionService.currentConnectionRequest = null;
225225
}
@@ -245,9 +245,9 @@ private Boolean canMakeOutgoingCall() {
245245
private Connection createConnection(ConnectionRequest request) {
246246
Bundle extras = request.getExtras();
247247
HashMap<String, String> extrasMap = this.bundleToMap(extras);
248-
extrasMap.put(EXTRA_CALL_NUMBER, request.getAddress().toString());
248+
extrasMap.put(EXTRA_CALL_IDENTIFIER, request.getAddress().toString());
249249
VoiceConnection connection = new VoiceConnection(this, extrasMap);
250-
connection.setConnectionCapabilities(Connection.CAPABILITY_MUTE | Connection.CAPABILITY_SUPPORT_HOLD);
250+
connection.setConnectionCapabilities(Connection.CAPABILITY_MUTE);
251251
connection.setInitializing();
252252
connection.setExtras(extras);
253253
currentConnections.put(extras.getString(EXTRA_CALL_UUID), connection);

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class RNCallKeep {
5858

5959
displayIncomingCall = (uuid, handle, localizedCallerName = '', handleType = 'number', hasVideo = false) => {
6060
if (!isIOS) {
61-
RNCallKeepModule.displayIncomingCall(uuid, handle, localizedCallerName);
61+
RNCallKeepModule.displayIncomingCall(uuid, handle, handleType, hasVideo, localizedCallerName);
6262
return;
6363
}
6464

@@ -73,7 +73,7 @@ class RNCallKeep {
7373

7474
startCall = (uuid, handle, contactIdentifier, handleType = 'number', hasVideo = false ) => {
7575
if (!isIOS) {
76-
RNCallKeepModule.startCall(uuid, handle, contactIdentifier);
76+
RNCallKeepModule.startCall(uuid, handle, contactIdentifier, handleType, hasVideo);
7777
return;
7878
}
7979

ios/RNCallKeep/RNCallKeep.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ + (void)initCallKitProvider {
240240
NSLog(@"[RNCallKeep][updateDisplay] uuidString = %@ displayName = %@ uri = %@", uuidString, displayName, uri);
241241
#endif
242242
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString];
243-
CXHandle *callHandle = [[CXHandle alloc] initWithType:CXHandleTypePhoneNumber value:uri];
243+
CXHandle *callHandle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:uri];
244244
CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init];
245245
callUpdate.localizedCallerName = displayName;
246246
callUpdate.remoteHandle = callHandle;
@@ -462,7 +462,7 @@ + (CXProviderConfiguration *)getProviderConfiguration:(NSDictionary*)settings
462462
int _handleType = [RNCallKeep getHandleType:settings[@"handleType"]];
463463
providerConfiguration.supportedHandleTypes = [NSSet setWithObjects:[NSNumber numberWithInteger:_handleType], nil];
464464
}else{
465-
providerConfiguration.supportedHandleTypes = [NSSet setWithObjects:[NSNumber numberWithInteger:CXHandleTypePhoneNumber], nil];
465+
providerConfiguration.supportedHandleTypes = [NSSet setWithObjects:[NSNumber numberWithInteger:CXHandleTypeGeneric], nil];
466466
}
467467
if (settings[@"supportsVideo"]) {
468468
providerConfiguration.supportsVideo = [settings[@"supportsVideo"] boolValue];

0 commit comments

Comments
 (0)