Skip to content

Commit 5d8b90c

Browse files
authored
Merge pull request #570 from react-native-webrtc/fix_missing_video_attrs
[Android] Add missing video attributes
2 parents 2a4b0c0 + 2ba0c6c commit 5d8b90c

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class Constants {
2222
public static final String EXTRA_CALL_NUMBER_SCHEMA = "EXTRA_CALL_NUMBER_SCHEMA";
2323
public static final String EXTRA_CALL_UUID = "EXTRA_CALL_UUID";
2424
public static final String EXTRA_CALLER_NAME = "EXTRA_CALLER_NAME";
25+
public static final String EXTRA_HAS_VIDEO = "EXTRA_HAS_VIDEO";
2526
// Can't use telecom.EXTRA_DISABLE_ADD_CALL ...
2627
public static final String EXTRA_DISABLE_ADD_CALL = "android.telecom.extra.DISABLE_ADD_CALL";
2728

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

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import static io.wazo.callkeep.Constants.EXTRA_CALLER_NAME;
8383
import static io.wazo.callkeep.Constants.EXTRA_CALL_UUID;
8484
import static io.wazo.callkeep.Constants.EXTRA_CALL_NUMBER;
85+
import static io.wazo.callkeep.Constants.EXTRA_HAS_VIDEO;
8586
import static io.wazo.callkeep.Constants.ACTION_END_CALL;
8687
import static io.wazo.callkeep.Constants.ACTION_ANSWER_CALL;
8788
import static io.wazo.callkeep.Constants.ACTION_MUTE_CALL;
@@ -151,6 +152,7 @@ private RNCallKeepModule(ReactApplicationContext reactContext) {
151152
this.reactContext = reactContext;
152153
delayedEvents = new WritableNativeArray();
153154
this.registerReceiver();
155+
this.fetchStoredSettings(reactContext);
154156
}
155157

156158
private boolean isSelfManaged() {
@@ -177,15 +179,15 @@ public ReactApplicationContext getContext() {
177179

178180
public void reportNewIncomingCall(String uuid, String number, String callerName, boolean hasVideo, String payload) {
179181
Log.d(TAG, "[RNCallKeepModule] reportNewIncomingCall, uuid: " + uuid + ", number: " + number + ", callerName: " + callerName);
180-
// @TODO: handle video
181182

182-
this.displayIncomingCall(uuid, number, callerName);
183+
this.displayIncomingCall(uuid, number, callerName, hasVideo);
183184

184185
// Send event to JS
185186
WritableMap args = Arguments.createMap();
186187
args.putString("handle", number);
187188
args.putString("callUUID", uuid);
188189
args.putString("name", callerName);
190+
args.putString("hasVideo", hasVideo);
189191
if (payload != null) {
190192
args.putString("payload", payload);
191193
}
@@ -308,19 +310,25 @@ public void unregisterEvents() {
308310

309311
@ReactMethod
310312
public void displayIncomingCall(String uuid, String number, String callerName) {
313+
this.displayIncomingCall(uuid, number, callerName, false);
314+
}
315+
316+
@ReactMethod
317+
public void displayIncomingCall(String uuid, String number, String callerName, boolean hasVideo) {
311318
if (!isConnectionServiceAvailable() || !hasPhoneAccount()) {
312319
Log.w(TAG, "[RNCallKeepModule] displayIncomingCall ignored due to no ConnectionService or no phone account");
313320
return;
314321
}
315322

316-
Log.d(TAG, "[RNCallKeepModule] displayIncomingCall, uuid: " + uuid + ", number: " + number + ", callerName: " + callerName);
323+
Log.d(TAG, "[RNCallKeepModule] displayIncomingCall, uuid: " + uuid + ", number: " + number + ", callerName: " + callerName + ", hasVideo: " + hasVideo);
317324

318325
Bundle extras = new Bundle();
319326
Uri uri = Uri.fromParts(PhoneAccount.SCHEME_TEL, number, null);
320327

321328
extras.putParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, uri);
322329
extras.putString(EXTRA_CALLER_NAME, callerName);
323330
extras.putString(EXTRA_CALL_UUID, uuid);
331+
extras.putString(EXTRA_HAS_VIDEO, String.valueOf(hasVideo));
324332

325333
telecomManager.addNewIncomingCall(handle, extras);
326334
}
@@ -344,6 +352,11 @@ public void answerIncomingCall(String uuid) {
344352

345353
@ReactMethod
346354
public void startCall(String uuid, String number, String callerName) {
355+
this.startCall(uuid, number, callerName, false);
356+
}
357+
358+
@ReactMethod
359+
public void startCall(String uuid, String number, String callerName, boolean hasVideo) {
347360
Log.d(TAG, "[RNCallKeepModule] startCall called, uuid: " + uuid + ", number: " + number + ", callerName: " + callerName);
348361

349362
if (!isConnectionServiceAvailable() || !hasPhoneAccount() || !hasPermissions() || number == null) {
@@ -358,6 +371,7 @@ public void startCall(String uuid, String number, String callerName) {
358371
callExtras.putString(EXTRA_CALLER_NAME, callerName);
359372
callExtras.putString(EXTRA_CALL_UUID, uuid);
360373
callExtras.putString(EXTRA_CALL_NUMBER, number);
374+
callExtras.putString(EXTRA_HAS_VIDEO, String.valueOf(hasVideo));
361375

362376
extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, handle);
363377
extras.putParcelable(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, callExtras);
@@ -996,6 +1010,14 @@ private Boolean hasPermissions() {
9961010
}
9971011

9981012
private boolean hasPhoneAccount() {
1013+
if (telecomManager == null) {
1014+
this.initializeTelecomManager();
1015+
}
1016+
1017+
if (isSelfManaged()) {
1018+
return true;
1019+
}
1020+
9991021
return isConnectionServiceAvailable() && telecomManager != null &&
10001022
hasPermissions() && telecomManager.getPhoneAccount(handle) != null &&
10011023
telecomManager.getPhoneAccount(handle).isEnabled();
@@ -1080,7 +1102,7 @@ public void onReceive(Context context, Intent intent) {
10801102
WritableMap args = Arguments.createMap();
10811103
HashMap<String, String> attributeMap = (HashMap<String, String>)intent.getSerializableExtra("attributeMap");
10821104

1083-
Log.d(TAG, "[RNCallKeepModule][onReceive] :" + intent.getAction());
1105+
Log.d(TAG, "[RNCallKeepModule][onReceive] " + intent.getAction());
10841106

10851107
switch (intent.getAction()) {
10861108
case ACTION_END_CALL:
@@ -1089,6 +1111,7 @@ public void onReceive(Context context, Intent intent) {
10891111
break;
10901112
case ACTION_ANSWER_CALL:
10911113
args.putString("callUUID", attributeMap.get(EXTRA_CALL_UUID));
1114+
args.putBoolean("withVideo", Boolean.valueOf(attributeMap.get(EXTRA_HAS_VIDEO)));
10921115
sendEventToJS("RNCallKeepPerformAnswerCallAction", args);
10931116
break;
10941117
case ACTION_HOLD_CALL:
@@ -1132,6 +1155,7 @@ public void onReceive(Context context, Intent intent) {
11321155
args.putString("handle", attributeMap.get(EXTRA_CALL_NUMBER));
11331156
args.putString("callUUID", attributeMap.get(EXTRA_CALL_UUID));
11341157
args.putString("name", attributeMap.get(EXTRA_CALLER_NAME));
1158+
args.putString("hasVideo", attributeMap.get(EXTRA_HAS_VIDEO));
11351159
sendEventToJS("RNCallKeepShowIncomingCallUi", args);
11361160
break;
11371161
case ACTION_WAKE_APP:

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,9 @@ private Boolean canMakeOutgoingCall() {
389389

390390
private Connection createConnection(ConnectionRequest request) {
391391
Bundle extras = request.getExtras();
392+
if (request.getAddress() == null) {
393+
return null;
394+
}
392395
HashMap<String, String> extrasMap = this.bundleToMap(extras);
393396

394397
String callerNumber = request.getAddress().toString();
@@ -460,6 +463,9 @@ public void onConference(Connection connection1, Connection connection2) {
460463

461464
@Override
462465
public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
466+
super.onCreateIncomingConnectionFailed(connectionManagerPhoneAccount, request);
467+
Log.w(TAG, "[VoiceConnectionService] onCreateIncomingConnectionFailed: " + request);
468+
463469
Bundle extras = request.getExtras();
464470
HashMap<String, String> extrasMap = this.bundleToMap(extras);
465471

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class RNCallKeep {
8888
options = null
8989
) => {
9090
if (!isIOS) {
91-
RNCallKeepModule.displayIncomingCall(uuid, handle, localizedCallerName);
91+
RNCallKeepModule.displayIncomingCall(uuid, handle, localizedCallerName, hasVideo);
9292
return;
9393
}
9494

@@ -117,7 +117,7 @@ class RNCallKeep {
117117

118118
startCall = (uuid, handle, contactIdentifier, handleType = 'number', hasVideo = false) => {
119119
if (!isIOS) {
120-
RNCallKeepModule.startCall(uuid, handle, contactIdentifier);
120+
RNCallKeepModule.startCall(uuid, handle, contactIdentifier, hasVideo);
121121
return;
122122
}
123123

0 commit comments

Comments
 (0)