Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Add missing video attributes #570

Merged
merged 5 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
33 changes: 29 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 @@ -983,6 +997,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 @@ -1067,7 +1089,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 @@ -1076,6 +1098,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 @@ -1119,6 +1142,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 All @@ -1144,6 +1168,7 @@ public void onReceive(Context context, Intent intent) {
args.putString("callUUID", attributeMap.get(EXTRA_CALL_UUID));
args.putString("name", attributeMap.get(EXTRA_CALLER_NAME));
sendEventToJS("RNCallKeepOnIncomingConnectionFailed", args);
break;
case ACTION_DID_CHANGE_AUDIO_ROUTE:
args.putString("handle", attributeMap.get(EXTRA_CALL_NUMBER));
args.putString("callUUID", attributeMap.get(EXTRA_CALL_UUID));
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