cordova-plugin-salus-call 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cordova-plugin-salus-call",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Integração nativa de chamadas VoIP para o aplicativo Salus.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"private": false,
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"engines": {
|
|
31
31
|
"cordovaDependencies": {
|
|
32
|
-
"0.2.
|
|
32
|
+
"0.2.1": {
|
|
33
33
|
"cordova": ">=12.0.0",
|
|
34
34
|
"cordova-android": ">=14.0.0"
|
|
35
35
|
}
|
package/plugin.xml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
|
3
3
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
4
4
|
id="cordova-plugin-salus-call"
|
|
5
|
-
version="0.2.
|
|
5
|
+
version="0.2.1">
|
|
6
6
|
<name>Salus Call</name>
|
|
7
7
|
<description>Ponte nativa para chamadas de interfone do Salus.</description>
|
|
8
8
|
<license>UNLICENSED</license>
|
|
@@ -24,13 +24,8 @@ public class SalusCallActionReceiver extends BroadcastReceiver {
|
|
|
24
24
|
SalusCallPlugin.dispatchEvent(context, event);
|
|
25
25
|
|
|
26
26
|
if (answered) {
|
|
27
|
-
Intent launch =
|
|
28
|
-
|
|
29
|
-
launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
30
|
-
launch.putExtra(SalusCallNotificationManager.EXTRA_CALL, call.toString());
|
|
31
|
-
launch.putExtra("salus_call_action", "answer");
|
|
32
|
-
context.startActivity(launch);
|
|
33
|
-
}
|
|
27
|
+
Intent launch = SalusCallNotificationManager.launchIntent(context, call, "answer");
|
|
28
|
+
context.startActivity(launch);
|
|
34
29
|
}
|
|
35
30
|
} catch (Exception ignored) {}
|
|
36
31
|
}
|
|
@@ -32,7 +32,7 @@ public final class SalusCallNotificationManager {
|
|
|
32
32
|
int notificationId = notificationId(callId);
|
|
33
33
|
|
|
34
34
|
Person caller = new Person.Builder().setName(callerName).setImportant(true).build();
|
|
35
|
-
PendingIntent answer =
|
|
35
|
+
PendingIntent answer = answerIntent(context, call, notificationId + 1);
|
|
36
36
|
PendingIntent reject = actionIntent(context, ACTION_REJECT, call, notificationId + 2);
|
|
37
37
|
PendingIntent open = openAppIntent(context, call, notificationId + 3);
|
|
38
38
|
|
|
@@ -100,13 +100,24 @@ public final class SalusCallNotificationManager {
|
|
|
100
100
|
return PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
private static PendingIntent answerIntent(Context context, JSONObject call, int requestCode) {
|
|
104
|
+
Intent intent = launchIntent(context, call, "answer");
|
|
105
|
+
intent.setAction(ACTION_ANSWER);
|
|
106
|
+
return PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
|
107
|
+
}
|
|
108
|
+
|
|
103
109
|
private static PendingIntent openAppIntent(Context context, JSONObject call, int requestCode) {
|
|
110
|
+
Intent intent = launchIntent(context, call, "open");
|
|
111
|
+
return PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
static Intent launchIntent(Context context, JSONObject call, String action) {
|
|
104
115
|
Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
|
105
116
|
if (intent == null) intent = new Intent();
|
|
106
117
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
107
118
|
intent.putExtra(EXTRA_CALL, call.toString());
|
|
108
|
-
intent.putExtra("salus_call_action",
|
|
109
|
-
return
|
|
119
|
+
intent.putExtra("salus_call_action", action);
|
|
120
|
+
return intent;
|
|
110
121
|
}
|
|
111
122
|
|
|
112
123
|
private static int notificationId(String callId) {
|
|
@@ -20,6 +20,7 @@ public class SalusCallPlugin extends CordovaPlugin {
|
|
|
20
20
|
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
|
21
21
|
super.initialize(cordova, webView);
|
|
22
22
|
activeInstance = this;
|
|
23
|
+
handleLaunchIntent(cordova.getActivity().getIntent());
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
@Override
|
|
@@ -103,6 +104,7 @@ public class SalusCallPlugin extends CordovaPlugin {
|
|
|
103
104
|
|
|
104
105
|
@Override
|
|
105
106
|
public void onNewIntent(Intent intent) {
|
|
107
|
+
handleLaunchIntent(intent);
|
|
106
108
|
emitPendingEvents();
|
|
107
109
|
}
|
|
108
110
|
|
|
@@ -127,4 +129,34 @@ public class SalusCallPlugin extends CordovaPlugin {
|
|
|
127
129
|
event.put("timestamp", System.currentTimeMillis());
|
|
128
130
|
emitEvent(event);
|
|
129
131
|
}
|
|
132
|
+
|
|
133
|
+
private void handleLaunchIntent(Intent intent) {
|
|
134
|
+
if (intent == null) return;
|
|
135
|
+
|
|
136
|
+
String action = intent.getStringExtra("salus_call_action");
|
|
137
|
+
String callJson = intent.getStringExtra(SalusCallNotificationManager.EXTRA_CALL);
|
|
138
|
+
if (action == null || callJson == null || callJson.isEmpty()) return;
|
|
139
|
+
|
|
140
|
+
intent.removeExtra("salus_call_action");
|
|
141
|
+
intent.removeExtra(SalusCallNotificationManager.EXTRA_CALL);
|
|
142
|
+
|
|
143
|
+
try {
|
|
144
|
+
JSONObject call = new JSONObject(callJson);
|
|
145
|
+
String callId = call.optString("callId", "");
|
|
146
|
+
SalusCallNotificationManager.cancel(cordova.getContext(), callId);
|
|
147
|
+
|
|
148
|
+
JSONObject event = new JSONObject();
|
|
149
|
+
if ("answer".equals(action)) {
|
|
150
|
+
event.put("type", "answered");
|
|
151
|
+
event.put("reason", "system_answer");
|
|
152
|
+
} else {
|
|
153
|
+
event.put("type", "opened");
|
|
154
|
+
event.put("reason", "notification_open");
|
|
155
|
+
}
|
|
156
|
+
event.put("callId", callId);
|
|
157
|
+
event.put("call", call);
|
|
158
|
+
event.put("timestamp", System.currentTimeMillis());
|
|
159
|
+
dispatchEvent(cordova.getContext(), event);
|
|
160
|
+
} catch (Exception ignored) {}
|
|
161
|
+
}
|
|
130
162
|
}
|