Skip to content

Commit

Permalink
DTMF and call from contacts support in Android
Browse files Browse the repository at this point in the history
  • Loading branch information
arekfryz committed Aug 9, 2018
1 parent b8ccb0d commit 7b7d23f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-call" version="1.1.6" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<plugin id="cordova-call" version="1.1.8" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>CordovaCall</name>
<js-module name="CordovaCall" src="www/CordovaCall.js">
<clobbers target="cordova.plugins.CordovaCall" />
Expand Down
1 change: 1 addition & 0 deletions src/android/CordovaCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void initialize(CordovaInterface cordova, CordovaWebView webView) {
callbackContextMap.put("hangup",new ArrayList<CallbackContext>());
callbackContextMap.put("sendCall",new ArrayList<CallbackContext>());
callbackContextMap.put("receiveCall",new ArrayList<CallbackContext>());
callbackContextMap.put("dtmf",new ArrayList<CallbackContext>());
}

@Override
Expand Down
47 changes: 45 additions & 2 deletions src/android/MyConnectionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
import android.net.Uri;
import java.util.ArrayList;
import android.util.Log;
import org.json.JSONObject;
import org.json.JSONException;

public class MyConnectionService extends ConnectionService {

private static String TAG = "MyConnectionService";
private static Connection conn;



public static Connection getConnection() {
return conn;
}
Expand Down Expand Up @@ -130,6 +134,23 @@ public void onAbort() {
super.onAbort();
}

@Override
public void onPlayDtmfTone(char c) {
Log.d("REMAC", Character.toString(c));
ArrayList<CallbackContext> callbackContexts = CordovaCall.getCallbackContexts().get("dtmf");
for (final CallbackContext callbackContext : callbackContexts) {
CordovaCall.getCordova().getThreadPool().execute(new Runnable() {
public void run() {
PluginResult result = new PluginResult(PluginResult.Status.OK, Character.toString(c));
result.setKeepCallback(true);
callbackContext.sendPluginResult(result);
}
});
}

super.onPlayDtmfTone(c);
}

@Override
public void onDisconnect() {
DisconnectCause cause = new DisconnectCause(DisconnectCause.LOCAL);
Expand Down Expand Up @@ -163,7 +184,29 @@ public void run() {
}
}
};
connection.setAddress(Uri.parse(request.getExtras().getString("to")), TelecomManager.PRESENTATION_ALLOWED);

JSONObject callResult = new JSONObject();

if(request.getExtras().getString("to") != null){
connection.setAddress(Uri.parse(request.getExtras().getString("to")), TelecomManager.PRESENTATION_ALLOWED);
try {
callResult.put("external", false);
callResult.put("to", request.getExtras().getString("to"));
} catch( JSONException e) {
Log.e("REMAC", "Json parsing error: " + e.getMessage());
}

} else {
Log.d("REMAC",request.toString());
connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
try {
callResult.put("external", true);
callResult.put("to", request.getAddress().toString());
} catch ( JSONException e) {
Log.e("REMAC", "Json parsing error: " + e.getMessage());
}
}

Icon icon = CordovaCall.getIcon();
if(icon != null) {
StatusHints statusHints = new StatusHints((CharSequence)"", icon, new Bundle());
Expand All @@ -176,7 +219,7 @@ public void run() {
for (final CallbackContext callbackContext : callbackContexts) {
CordovaCall.getCordova().getThreadPool().execute(new Runnable() {
public void run() {
PluginResult result = new PluginResult(PluginResult.Status.OK, "sendCall event called successfully");
PluginResult result = new PluginResult(PluginResult.Status.OK, callResult);
result.setKeepCallback(true);
callbackContext.sendPluginResult(result);
}
Expand Down

0 comments on commit 7b7d23f

Please sign in to comment.