Skip to content

Commit

Permalink
Merge pull request #570 from react-native-webrtc/fix_missing_video_attrs
Browse files Browse the repository at this point in the history
[Android] Add missing video attributes
  • Loading branch information
manuquentin authored May 25, 2022
2 parents 2a4b0c0 + 2ba0c6c commit 5d8b90c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions android/src/main/java/io/wazo/callkeep/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Constants {
public static final String EXTRA_CALL_NUMBER_SCHEMA = "EXTRA_CALL_NUMBER_SCHEMA";
public static final String EXTRA_CALL_UUID = "EXTRA_CALL_UUID";
public static final String EXTRA_CALLER_NAME = "EXTRA_CALLER_NAME";
public static final String EXTRA_HAS_VIDEO = "EXTRA_HAS_VIDEO";
// Can't use telecom.EXTRA_DISABLE_ADD_CALL ...
public static final String EXTRA_DISABLE_ADD_CALL = "android.telecom.extra.DISABLE_ADD_CALL";

Expand Down
32 changes: 28 additions & 4 deletions android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import static io.wazo.callkeep.Constants.EXTRA_CALLER_NAME;
import static io.wazo.callkeep.Constants.EXTRA_CALL_UUID;
import static io.wazo.callkeep.Constants.EXTRA_CALL_NUMBER;
import static io.wazo.callkeep.Constants.EXTRA_HAS_VIDEO;
import static io.wazo.callkeep.Constants.ACTION_END_CALL;
import static io.wazo.callkeep.Constants.ACTION_ANSWER_CALL;
import static io.wazo.callkeep.Constants.ACTION_MUTE_CALL;
Expand Down Expand Up @@ -151,6 +152,7 @@ private RNCallKeepModule(ReactApplicationContext reactContext) {
this.reactContext = reactContext;
delayedEvents = new WritableNativeArray();
this.registerReceiver();
this.fetchStoredSettings(reactContext);
}

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

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

this.displayIncomingCall(uuid, number, callerName);
this.displayIncomingCall(uuid, number, callerName, hasVideo);

// Send event to JS
WritableMap args = Arguments.createMap();
args.putString("handle", number);
args.putString("callUUID", uuid);
args.putString("name", callerName);
args.putString("hasVideo", hasVideo);
if (payload != null) {
args.putString("payload", payload);
}
Expand Down Expand Up @@ -308,19 +310,25 @@ public void unregisterEvents() {

@ReactMethod
public void displayIncomingCall(String uuid, String number, String callerName) {
this.displayIncomingCall(uuid, number, callerName, false);
}

@ReactMethod
public void displayIncomingCall(String uuid, String number, String callerName, boolean hasVideo) {
if (!isConnectionServiceAvailable() || !hasPhoneAccount()) {
Log.w(TAG, "[RNCallKeepModule] displayIncomingCall ignored due to no ConnectionService or no phone account");
return;
}

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

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

extras.putParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, uri);
extras.putString(EXTRA_CALLER_NAME, callerName);
extras.putString(EXTRA_CALL_UUID, uuid);
extras.putString(EXTRA_HAS_VIDEO, String.valueOf(hasVideo));

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

@ReactMethod
public void startCall(String uuid, String number, String callerName) {
this.startCall(uuid, number, callerName, false);
}

@ReactMethod
public void startCall(String uuid, String number, String callerName, boolean hasVideo) {
Log.d(TAG, "[RNCallKeepModule] startCall called, uuid: " + uuid + ", number: " + number + ", callerName: " + callerName);

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

extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, handle);
extras.putParcelable(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, callExtras);
Expand Down Expand Up @@ -996,6 +1010,14 @@ private Boolean hasPermissions() {
}

private boolean hasPhoneAccount() {
if (telecomManager == null) {
this.initializeTelecomManager();
}

if (isSelfManaged()) {
return true;
}

return isConnectionServiceAvailable() && telecomManager != null &&
hasPermissions() && telecomManager.getPhoneAccount(handle) != null &&
telecomManager.getPhoneAccount(handle).isEnabled();
Expand Down Expand Up @@ -1080,7 +1102,7 @@ public void onReceive(Context context, Intent intent) {
WritableMap args = Arguments.createMap();
HashMap<String, String> attributeMap = (HashMap<String, String>)intent.getSerializableExtra("attributeMap");

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

switch (intent.getAction()) {
case ACTION_END_CALL:
Expand All @@ -1089,6 +1111,7 @@ public void onReceive(Context context, Intent intent) {
break;
case ACTION_ANSWER_CALL:
args.putString("callUUID", attributeMap.get(EXTRA_CALL_UUID));
args.putBoolean("withVideo", Boolean.valueOf(attributeMap.get(EXTRA_HAS_VIDEO)));
sendEventToJS("RNCallKeepPerformAnswerCallAction", args);
break;
case ACTION_HOLD_CALL:
Expand Down Expand Up @@ -1132,6 +1155,7 @@ public void onReceive(Context context, Intent intent) {
args.putString("handle", attributeMap.get(EXTRA_CALL_NUMBER));
args.putString("callUUID", attributeMap.get(EXTRA_CALL_UUID));
args.putString("name", attributeMap.get(EXTRA_CALLER_NAME));
args.putString("hasVideo", attributeMap.get(EXTRA_HAS_VIDEO));
sendEventToJS("RNCallKeepShowIncomingCallUi", args);
break;
case ACTION_WAKE_APP:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@ private Boolean canMakeOutgoingCall() {

private Connection createConnection(ConnectionRequest request) {
Bundle extras = request.getExtras();
if (request.getAddress() == null) {
return null;
}
HashMap<String, String> extrasMap = this.bundleToMap(extras);

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

@Override
public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
super.onCreateIncomingConnectionFailed(connectionManagerPhoneAccount, request);
Log.w(TAG, "[VoiceConnectionService] onCreateIncomingConnectionFailed: " + request);

Bundle extras = request.getExtras();
HashMap<String, String> extrasMap = this.bundleToMap(extras);

Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class RNCallKeep {
options = null
) => {
if (!isIOS) {
RNCallKeepModule.displayIncomingCall(uuid, handle, localizedCallerName);
RNCallKeepModule.displayIncomingCall(uuid, handle, localizedCallerName, hasVideo);
return;
}

Expand Down Expand Up @@ -117,7 +117,7 @@ class RNCallKeep {

startCall = (uuid, handle, contactIdentifier, handleType = 'number', hasVideo = false) => {
if (!isIOS) {
RNCallKeepModule.startCall(uuid, handle, contactIdentifier);
RNCallKeepModule.startCall(uuid, handle, contactIdentifier, hasVideo);
return;
}

Expand Down

0 comments on commit 5d8b90c

Please sign in to comment.