pushwoosh-cordova-plugin 8.3.55 → 8.3.57
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 +2 -2
- package/example_voip/LICENSE +21 -0
- package/example_voip/README.md +156 -0
- package/example_voip/Screenshots/Android.png +0 -0
- package/example_voip/Screenshots/iOS.png +0 -0
- package/example_voip/Screenshots/xcode_appgroups.png +0 -0
- package/example_voip/demovoip/README.md +181 -0
- package/example_voip/demovoip/config.xml +22 -0
- package/example_voip/demovoip/google-services.json +86 -0
- package/example_voip/demovoip/hooks/after_platform_add/010_install_plugin.js +46 -0
- package/example_voip/demovoip/hooks/after_prepare/010_setup_gradle_wrapper.js +34 -0
- package/example_voip/demovoip/hooks/after_prepare/015_fix_agp_version.js +36 -0
- package/example_voip/demovoip/hooks/after_prepare/020_copy_google_services.js +23 -0
- package/example_voip/demovoip/hooks/after_prepare/025_add_voip_pod.js +43 -0
- package/example_voip/demovoip/hooks/after_prepare.js +28 -0
- package/example_voip/demovoip/package-lock.json +1104 -0
- package/example_voip/demovoip/package.json +34 -0
- package/example_voip/demovoip/www/css/index.css +605 -0
- package/example_voip/demovoip/www/img/logo.png +0 -0
- package/example_voip/demovoip/www/index.html +175 -0
- package/example_voip/demovoip/www/js/index.js +419 -0
- package/package.json +1 -1
- package/plugin.xml +12 -9
- package/src/android/add-android-voip.gradle +1 -1
- package/src/android/src/com/pushwoosh/plugin/pushnotifications/CallsAdapter.java +0 -1
- package/src/android/src/com/pushwoosh/plugin/pushnotifications/NoopCallsAdapter.java +0 -5
- package/src/android/src/com/pushwoosh/plugin/pushnotifications/PushNotifications.java +123 -42
- package/src/android/src/com/pushwoosh/plugin/pushnotifications/VoIPEventStorage.java +130 -0
- package/src/android/src/com/pushwoosh/plugin/pushnotifications/calls/PWCordovaCallEventListener.java +61 -34
- package/src/android/src/com/pushwoosh/plugin/pushnotifications/calls/PushwooshCallsAdapter.java +18 -13
- package/src/ios/PushNotification.m +0 -5
- package/types/PushNotification.d.ts +0 -1
- package/www/PushNotification.js +0 -4
|
@@ -7,11 +7,6 @@ import org.json.JSONArray;
|
|
|
7
7
|
|
|
8
8
|
public class NoopCallsAdapter implements CallsAdapter{
|
|
9
9
|
private static final String TAG = "NoopCallsAdapter";
|
|
10
|
-
@Override
|
|
11
|
-
public boolean setVoipAppCode(JSONArray data, CallbackContext callbackContext) {
|
|
12
|
-
PWLog.error(TAG,"Method not implemented");
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
10
|
|
|
16
11
|
@Override
|
|
17
12
|
public boolean requestCallPermission(JSONArray data, CallbackContext callbackContext) {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
package com.pushwoosh.plugin.pushnotifications;
|
|
12
12
|
|
|
13
|
+
import android.content.Context;
|
|
13
14
|
import android.content.Intent;
|
|
14
15
|
import android.os.Bundle;
|
|
15
16
|
import android.os.Handler;
|
|
@@ -33,6 +34,7 @@ import com.pushwoosh.inbox.data.InboxMessage;
|
|
|
33
34
|
import com.pushwoosh.inbox.exception.InboxMessagesException;
|
|
34
35
|
import com.pushwoosh.inbox.ui.presentation.view.activity.InboxActivity;
|
|
35
36
|
import com.pushwoosh.internal.platform.utils.GeneralUtils;
|
|
37
|
+
import com.pushwoosh.internal.platform.AndroidPlatformModule;
|
|
36
38
|
import com.pushwoosh.internal.utils.JsonUtils;
|
|
37
39
|
import com.pushwoosh.internal.utils.PWLog;
|
|
38
40
|
import com.pushwoosh.notification.LocalNotification;
|
|
@@ -75,7 +77,6 @@ public class PushNotifications extends CordovaPlugin {
|
|
|
75
77
|
private static AtomicBoolean sAppReady = new AtomicBoolean();
|
|
76
78
|
private static PushNotifications sInstance;
|
|
77
79
|
|
|
78
|
-
// private CallbackContext callbackContext;
|
|
79
80
|
private static CordovaInterface cordovaInterface;
|
|
80
81
|
private static CallsAdapter callsAdapter;
|
|
81
82
|
|
|
@@ -108,6 +109,25 @@ public class PushNotifications extends CordovaPlugin {
|
|
|
108
109
|
return cordovaInterface;
|
|
109
110
|
}
|
|
110
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Checks if Cordova WebView is ready to receive events.
|
|
114
|
+
* Returns false if CordovaInterface is null, Activity is null/finishing/destroyed.
|
|
115
|
+
*/
|
|
116
|
+
private static boolean isCordovaReady() {
|
|
117
|
+
if (cordovaInterface == null) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
android.app.Activity activity = cordovaInterface.getActivity();
|
|
122
|
+
if (activity == null || activity.isFinishing() || activity.isDestroyed()) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
return true;
|
|
126
|
+
} catch (Exception e) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
111
131
|
public static HashMap<String, ArrayList<CallbackContext>> getCallbackContextMap() {
|
|
112
132
|
return callbackContextMap;
|
|
113
133
|
}
|
|
@@ -125,11 +145,26 @@ public class PushNotifications extends CordovaPlugin {
|
|
|
125
145
|
|
|
126
146
|
@Override
|
|
127
147
|
public void onDestroy() {
|
|
148
|
+
PWLog.noise(TAG, "onDestroy()");
|
|
149
|
+
|
|
128
150
|
super.onDestroy();
|
|
129
|
-
PWLog.noise("OnDestroy");
|
|
130
151
|
sAppReady.set(false);
|
|
131
152
|
}
|
|
132
153
|
|
|
154
|
+
@Override
|
|
155
|
+
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
|
156
|
+
PWLog.noise(TAG, "initialize()");
|
|
157
|
+
|
|
158
|
+
cordovaInterface = cordova;
|
|
159
|
+
callsAdapter = CallsAdapterFactory.create(cordova.getActivity().getApplicationContext());
|
|
160
|
+
callbackContextMap.put("answer", new ArrayList<CallbackContext>());
|
|
161
|
+
callbackContextMap.put("reject", new ArrayList<CallbackContext>());
|
|
162
|
+
callbackContextMap.put("hangup", new ArrayList<CallbackContext>());
|
|
163
|
+
callbackContextMap.put("voipPushPayload", new ArrayList<CallbackContext>());
|
|
164
|
+
callbackContextMap.put("voipDidCancelCall", new ArrayList<CallbackContext>());
|
|
165
|
+
callbackContextMap.put("voipDidFailToCancelCall", new ArrayList<CallbackContext>());
|
|
166
|
+
}
|
|
167
|
+
|
|
133
168
|
private JSONObject getPushFromIntent(Intent intent) {
|
|
134
169
|
if (null == intent) {
|
|
135
170
|
return null;
|
|
@@ -152,6 +187,8 @@ public class PushNotifications extends CordovaPlugin {
|
|
|
152
187
|
|
|
153
188
|
@CordovaMethod
|
|
154
189
|
private boolean onDeviceReady(JSONArray data, CallbackContext callbackContext) {
|
|
190
|
+
PWLog.noise(TAG, "onDeviceReady()");
|
|
191
|
+
|
|
155
192
|
JSONObject params = null;
|
|
156
193
|
try {
|
|
157
194
|
params = data.getJSONObject(0);
|
|
@@ -160,34 +197,37 @@ public class PushNotifications extends CordovaPlugin {
|
|
|
160
197
|
return false;
|
|
161
198
|
}
|
|
162
199
|
|
|
200
|
+
String appid = null;
|
|
163
201
|
try {
|
|
164
|
-
|
|
165
|
-
String appid = null;
|
|
166
202
|
if (params.has("appid")) {
|
|
167
203
|
appid = params.getString("appid");
|
|
168
204
|
} else {
|
|
169
205
|
appid = params.getString("pw_appid");
|
|
170
206
|
}
|
|
207
|
+
} catch (JSONException e) {
|
|
208
|
+
PWLog.error(TAG, "Missing appid parameter. Did you follow the guide correctly?", e);
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
171
211
|
|
|
172
|
-
|
|
173
|
-
Pushwoosh.getInstance().setSenderId(params.getString("projectid"));
|
|
212
|
+
String projectid = params.optString("projectid", "");
|
|
174
213
|
|
|
214
|
+
Pushwoosh.getInstance().setAppId(appid);
|
|
215
|
+
Pushwoosh.getInstance().setSenderId(projectid);
|
|
175
216
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
217
|
+
try {
|
|
218
|
+
processPendingPushNotifications();
|
|
219
|
+
} catch (Exception e) {
|
|
220
|
+
PWLog.error(TAG, "Failed to process pending push notifications", e);
|
|
221
|
+
}
|
|
180
222
|
|
|
181
|
-
|
|
182
|
-
doOnPushOpened(sStartPushData);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
223
|
+
sAppReady.set(true);
|
|
185
224
|
|
|
186
|
-
|
|
225
|
+
try {
|
|
226
|
+
processPersistedVoIPEvents();
|
|
187
227
|
} catch (Exception e) {
|
|
188
|
-
PWLog.error(TAG, "
|
|
189
|
-
return false;
|
|
228
|
+
PWLog.error(TAG, "Failed to process persisted VoIP events", e);
|
|
190
229
|
}
|
|
230
|
+
|
|
191
231
|
return true;
|
|
192
232
|
}
|
|
193
233
|
|
|
@@ -856,18 +896,6 @@ public class PushNotifications extends CordovaPlugin {
|
|
|
856
896
|
return true;
|
|
857
897
|
}
|
|
858
898
|
|
|
859
|
-
@Override
|
|
860
|
-
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
|
861
|
-
cordovaInterface = cordova;
|
|
862
|
-
callsAdapter = CallsAdapterFactory.create(cordova.getActivity().getApplicationContext());
|
|
863
|
-
callbackContextMap.put("answer", new ArrayList<CallbackContext>());
|
|
864
|
-
callbackContextMap.put("reject", new ArrayList<CallbackContext>());
|
|
865
|
-
callbackContextMap.put("hangup", new ArrayList<CallbackContext>());
|
|
866
|
-
callbackContextMap.put("voipPushPayload", new ArrayList<CallbackContext>());
|
|
867
|
-
callbackContextMap.put("voipDidCancelCall", new ArrayList<CallbackContext>());
|
|
868
|
-
callbackContextMap.put("voipDidFailToCancelCall", new ArrayList<CallbackContext>());
|
|
869
|
-
}
|
|
870
|
-
|
|
871
899
|
@Override
|
|
872
900
|
public boolean execute(String action, JSONArray data, CallbackContext callbackId) {
|
|
873
901
|
PWLog.debug(TAG, "Plugin Method Called: " + action);
|
|
@@ -1068,11 +1096,6 @@ public class PushNotifications extends CordovaPlugin {
|
|
|
1068
1096
|
return true;
|
|
1069
1097
|
}
|
|
1070
1098
|
|
|
1071
|
-
@CordovaMethod
|
|
1072
|
-
private boolean setVoipAppCode(JSONArray data, CallbackContext callbackContext) {
|
|
1073
|
-
return callsAdapter.setVoipAppCode(data, callbackContext);
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
1099
|
@CordovaMethod
|
|
1077
1100
|
private boolean requestCallPermission(JSONArray data, final CallbackContext callbackContext) {
|
|
1078
1101
|
return callsAdapter.requestCallPermission(data, callbackContext);
|
|
@@ -1128,17 +1151,75 @@ public class PushNotifications extends CordovaPlugin {
|
|
|
1128
1151
|
return callsAdapter.speakerOff();
|
|
1129
1152
|
}
|
|
1130
1153
|
|
|
1154
|
+
private void processPendingPushNotifications() {
|
|
1155
|
+
PWLog.noise(TAG, "processPendingPushNotifications()");
|
|
1156
|
+
synchronized (sStartPushLock) {
|
|
1157
|
+
if (sReceivedPushData != null) {
|
|
1158
|
+
doOnPushReceived(sReceivedPushData);
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
if (sStartPushData != null) {
|
|
1162
|
+
doOnPushOpened(sStartPushData);
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
private void processPersistedVoIPEvents() {
|
|
1168
|
+
PWLog.noise(TAG, "processPersistedVoIPEvents()");
|
|
1169
|
+
Context context = AndroidPlatformModule.getApplicationContext();
|
|
1170
|
+
if (context == null) {
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
List<VoIPEventStorage.StoredEvent> storedEvents = VoIPEventStorage.loadEvents(context);
|
|
1175
|
+
if (storedEvents.isEmpty()) {
|
|
1176
|
+
return;
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
PWLog.info(TAG, "Processing " + storedEvents.size() + " persisted VoIP events");
|
|
1180
|
+
|
|
1181
|
+
for (VoIPEventStorage.StoredEvent event : storedEvents) {
|
|
1182
|
+
emitVoipEvent(event.type, event.payload);
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
VoIPEventStorage.clearEvents(context);
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
private static void bufferVoipEvent(@NonNull String type, @NonNull JSONObject payload) {
|
|
1189
|
+
Context context = AndroidPlatformModule.getApplicationContext();
|
|
1190
|
+
if (context != null) {
|
|
1191
|
+
VoIPEventStorage.saveEvent(context, type, payload);
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1131
1195
|
public static void emitVoipEvent(@NonNull String type, @NonNull JSONObject payload) {
|
|
1196
|
+
PWLog.noise(TAG, "emitVoipEvent(), event type: " + type);
|
|
1197
|
+
|
|
1198
|
+
if (!isCordovaReady()) {
|
|
1199
|
+
PWLog.info(TAG, "Buffering VoIP event '" + type + "': Cordova not ready");
|
|
1200
|
+
bufferVoipEvent(type, payload);
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1132
1204
|
ArrayList<CallbackContext> callbackContexts = getCallbackContexts().get(type);
|
|
1133
|
-
if (callbackContexts
|
|
1205
|
+
if (callbackContexts != null && !callbackContexts.isEmpty()) {
|
|
1206
|
+
for (final CallbackContext callbackContext : callbackContexts) {
|
|
1207
|
+
getCordovaInterface().getThreadPool().execute(() -> {
|
|
1208
|
+
PluginResult result = new PluginResult(PluginResult.Status.OK, payload);
|
|
1209
|
+
result.setKeepCallback(true);
|
|
1210
|
+
callbackContext.sendPluginResult(result);
|
|
1211
|
+
});
|
|
1212
|
+
}
|
|
1213
|
+
return;
|
|
1214
|
+
}
|
|
1134
1215
|
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
callbackContext.sendPluginResult(result);
|
|
1140
|
-
});
|
|
1216
|
+
if (!sAppReady.get()) {
|
|
1217
|
+
PWLog.info(TAG, "Buffering VoIP event '" + type + "': JS not ready");
|
|
1218
|
+
bufferVoipEvent(type, payload);
|
|
1219
|
+
return;
|
|
1141
1220
|
}
|
|
1221
|
+
|
|
1222
|
+
PWLog.warn(TAG, "No callback contexts registered for event: " + type);
|
|
1142
1223
|
}
|
|
1143
1224
|
|
|
1144
1225
|
private static JSONObject inboxMessageToJson(InboxMessage message) {
|
|
@@ -1165,4 +1246,4 @@ public class PushNotifications extends CordovaPlugin {
|
|
|
1165
1246
|
}
|
|
1166
1247
|
return object;
|
|
1167
1248
|
}
|
|
1168
|
-
}
|
|
1249
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
package com.pushwoosh.plugin.pushnotifications;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.content.SharedPreferences;
|
|
5
|
+
import androidx.annotation.NonNull;
|
|
6
|
+
import com.pushwoosh.internal.utils.PWLog;
|
|
7
|
+
import org.json.JSONArray;
|
|
8
|
+
import org.json.JSONObject;
|
|
9
|
+
import java.util.ArrayList;
|
|
10
|
+
import java.util.List;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* VoIP Event Buffering Storage
|
|
14
|
+
*
|
|
15
|
+
* Provides persistent storage for VoIP events when WebView/JavaScript is not ready.
|
|
16
|
+
*/
|
|
17
|
+
public class VoIPEventStorage {
|
|
18
|
+
private static final String TAG = "VoIPEventStorage";
|
|
19
|
+
private static final String PREFS_NAME = "pushwoosh_voip_events";
|
|
20
|
+
private static final String KEY_BUFFERED_EVENTS = "buffered_events";
|
|
21
|
+
private static final long TTL_MILLIS = 24 * 60 * 60 * 1000; // 24 hours
|
|
22
|
+
private static final Object STORAGE_LOCK = new Object();
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Represents a stored VoIP event with metadata
|
|
26
|
+
*/
|
|
27
|
+
public static class StoredEvent {
|
|
28
|
+
public String type;
|
|
29
|
+
public JSONObject payload;
|
|
30
|
+
public long timestamp;
|
|
31
|
+
|
|
32
|
+
public StoredEvent(String type, JSONObject payload, long timestamp) {
|
|
33
|
+
this.type = type;
|
|
34
|
+
this.payload = payload;
|
|
35
|
+
this.timestamp = timestamp;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public boolean isExpired() {
|
|
39
|
+
return (System.currentTimeMillis() - timestamp) > TTL_MILLIS;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Save VoIP event to persistent storage
|
|
45
|
+
*/
|
|
46
|
+
public static boolean saveEvent(@NonNull Context context, @NonNull String type, @NonNull JSONObject payload) {
|
|
47
|
+
PWLog.noise(TAG, "saveEvent()");
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
synchronized (STORAGE_LOCK) {
|
|
51
|
+
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
|
52
|
+
String existingData = prefs.getString(KEY_BUFFERED_EVENTS, "[]");
|
|
53
|
+
JSONArray events = new JSONArray(existingData);
|
|
54
|
+
|
|
55
|
+
JSONObject event = new JSONObject();
|
|
56
|
+
event.put("type", type);
|
|
57
|
+
event.put("payload", payload);
|
|
58
|
+
event.put("timestamp", System.currentTimeMillis());
|
|
59
|
+
|
|
60
|
+
events.put(event);
|
|
61
|
+
|
|
62
|
+
boolean success = prefs.edit()
|
|
63
|
+
.putString(KEY_BUFFERED_EVENTS, events.toString())
|
|
64
|
+
.commit();
|
|
65
|
+
|
|
66
|
+
return success;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
} catch (Exception e) {
|
|
70
|
+
PWLog.error(TAG, "Failed to save VoIP event", e);
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private static StoredEvent parseStoredEvent(@NonNull JSONObject eventObj) throws Exception {
|
|
76
|
+
String type = eventObj.getString("type");
|
|
77
|
+
JSONObject payload = eventObj.getJSONObject("payload");
|
|
78
|
+
long timestamp = eventObj.getLong("timestamp");
|
|
79
|
+
return new StoredEvent(type, payload, timestamp);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Load all non-expired events from storage.
|
|
84
|
+
*/
|
|
85
|
+
public static List<StoredEvent> loadEvents(@NonNull Context context) {
|
|
86
|
+
PWLog.noise(TAG, "loadEvents()");
|
|
87
|
+
|
|
88
|
+
List<StoredEvent> result = new ArrayList<>();
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
synchronized (STORAGE_LOCK) {
|
|
92
|
+
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
|
93
|
+
String data = prefs.getString(KEY_BUFFERED_EVENTS, "[]");
|
|
94
|
+
JSONArray events = new JSONArray(data);
|
|
95
|
+
|
|
96
|
+
for (int i = 0; i < events.length(); i++) {
|
|
97
|
+
try {
|
|
98
|
+
StoredEvent event = parseStoredEvent(events.getJSONObject(i));
|
|
99
|
+
|
|
100
|
+
if (event.isExpired()) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
result.add(event);
|
|
105
|
+
} catch (Exception e) {
|
|
106
|
+
PWLog.error(TAG, "Failed to parse VoIP event at index " + i + ", skipping", e);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
} catch (Exception e) {
|
|
112
|
+
PWLog.error(TAG, "Failed to load VoIP events", e);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public static void clearEvents(@NonNull Context context) {
|
|
119
|
+
PWLog.noise(TAG, "clearEvents()");
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
synchronized (STORAGE_LOCK) {
|
|
123
|
+
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
|
124
|
+
prefs.edit().remove(KEY_BUFFERED_EVENTS).commit();
|
|
125
|
+
}
|
|
126
|
+
} catch (Exception e) {
|
|
127
|
+
PWLog.error(TAG, "Failed to clear VoIP events", e);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
package/src/android/src/com/pushwoosh/plugin/pushnotifications/calls/PWCordovaCallEventListener.java
CHANGED
|
@@ -13,82 +13,109 @@ import com.pushwoosh.internal.platform.AndroidPlatformModule;
|
|
|
13
13
|
import com.pushwoosh.internal.utils.PWLog;
|
|
14
14
|
|
|
15
15
|
public class PWCordovaCallEventListener implements CallEventListener {
|
|
16
|
+
|
|
17
|
+
private static final String TAG = "PWCordovaCallEventListener";
|
|
16
18
|
private static final Object sCurrentCallLock = new Object();
|
|
17
19
|
private static Bundle currentCallInfo = null;
|
|
18
20
|
|
|
21
|
+
private void setCurrentCallInfo(Bundle bundle) {
|
|
22
|
+
synchronized (sCurrentCallLock) {
|
|
23
|
+
currentCallInfo = bundle;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
19
26
|
|
|
20
|
-
|
|
21
|
-
public void onAnswer(@NonNull PushwooshVoIPMessage pushwooshVoIPMessage, int i) {
|
|
27
|
+
private void clearCurrentCallInfo() {
|
|
22
28
|
synchronized (sCurrentCallLock) {
|
|
23
|
-
currentCallInfo =
|
|
29
|
+
currentCallInfo = null;
|
|
24
30
|
}
|
|
25
|
-
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public static Bundle getCurrentCallInfo() {
|
|
34
|
+
synchronized (sCurrentCallLock) {
|
|
35
|
+
return currentCallInfo;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private void launchMainActivity() {
|
|
40
|
+
PWLog.noise(TAG, "launchMainActivity()");
|
|
26
41
|
try {
|
|
27
42
|
Context context = AndroidPlatformModule.getApplicationContext();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
43
|
+
if (context == null) {
|
|
44
|
+
PWLog.error(TAG, "cant launch activity: context is null");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
|
48
|
+
if (launchIntent == null) {
|
|
49
|
+
PWLog.error(TAG, "cant launch activity: launchIntent is null");
|
|
50
|
+
return;
|
|
34
51
|
}
|
|
52
|
+
|
|
53
|
+
launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
|
54
|
+
context.startActivity(launchIntent);
|
|
35
55
|
} catch (Exception e) {
|
|
36
|
-
PWLog.error(
|
|
56
|
+
PWLog.error(TAG, "Failed to launch activity", e);
|
|
37
57
|
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@Override
|
|
62
|
+
public void onCreateIncomingConnection(@Nullable Bundle bundle) {
|
|
63
|
+
PWLog.noise(TAG, "onCreateIncomingConnection()");
|
|
64
|
+
|
|
65
|
+
setCurrentCallInfo(bundle);
|
|
66
|
+
PushwooshCallsAdapter.onCreateIncomingConnection(bundle);
|
|
67
|
+
}
|
|
38
68
|
|
|
69
|
+
|
|
70
|
+
@Override
|
|
71
|
+
public void onAnswer(@NonNull PushwooshVoIPMessage pushwooshVoIPMessage, int i) {
|
|
72
|
+
PWLog.noise(TAG, "onAnswer()");
|
|
73
|
+
|
|
74
|
+
setCurrentCallInfo(pushwooshVoIPMessage.getRawPayload());
|
|
39
75
|
PushwooshCallsAdapter.onAnswer(pushwooshVoIPMessage);
|
|
76
|
+
launchMainActivity();
|
|
40
77
|
}
|
|
41
78
|
|
|
42
79
|
@Override
|
|
43
80
|
public void onReject(@NonNull PushwooshVoIPMessage pushwooshVoIPMessage) {
|
|
81
|
+
PWLog.noise(TAG, "onReject()");
|
|
82
|
+
|
|
44
83
|
PushwooshCallsAdapter.onReject(pushwooshVoIPMessage);
|
|
45
|
-
|
|
46
|
-
currentCallInfo = null;
|
|
47
|
-
}
|
|
84
|
+
clearCurrentCallInfo();
|
|
48
85
|
}
|
|
49
86
|
|
|
50
87
|
@Override
|
|
51
88
|
public void onDisconnect(@NonNull PushwooshVoIPMessage pushwooshVoIPMessage) {
|
|
52
|
-
|
|
53
|
-
synchronized (sCurrentCallLock) {
|
|
54
|
-
currentCallInfo = null;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
89
|
+
PWLog.noise(TAG, "onDisconnect()");
|
|
57
90
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
synchronized (sCurrentCallLock) {
|
|
61
|
-
currentCallInfo = bundle;
|
|
62
|
-
}
|
|
63
|
-
PushwooshCallsAdapter.onCreateIncomingConnection(bundle);
|
|
91
|
+
PushwooshCallsAdapter.onDisconnect(pushwooshVoIPMessage);
|
|
92
|
+
clearCurrentCallInfo();
|
|
64
93
|
}
|
|
65
94
|
|
|
66
95
|
@Override
|
|
67
96
|
public void onCallAdded(@NonNull PushwooshVoIPMessage pushwooshVoIPMessage) {
|
|
97
|
+
PWLog.noise(TAG, "onCallAdded()");
|
|
68
98
|
//stub
|
|
69
99
|
}
|
|
70
100
|
|
|
71
101
|
@Override
|
|
72
102
|
public void onCallRemoved(@NonNull PushwooshVoIPMessage pushwooshVoIPMessage) {
|
|
103
|
+
PWLog.noise(TAG, "onCallRemoved()");
|
|
73
104
|
//stub
|
|
74
105
|
}
|
|
75
106
|
|
|
76
107
|
@Override
|
|
77
108
|
public void onCallCancelled(@NonNull PushwooshVoIPMessage pushwooshVoIPMessage) {
|
|
109
|
+
PWLog.noise(TAG, "onCallCancelled()");
|
|
110
|
+
|
|
78
111
|
PushwooshCallsAdapter.onCallCancelled(pushwooshVoIPMessage);
|
|
79
|
-
|
|
80
|
-
currentCallInfo = null;
|
|
81
|
-
}
|
|
112
|
+
clearCurrentCallInfo();
|
|
82
113
|
}
|
|
83
114
|
|
|
84
115
|
@Override
|
|
85
116
|
public void onCallCancellationFailed(@Nullable String callId, @Nullable String reason) {
|
|
86
|
-
|
|
87
|
-
}
|
|
117
|
+
PWLog.noise(TAG, "onCallCancellationFailed()");
|
|
88
118
|
|
|
89
|
-
|
|
90
|
-
synchronized (sCurrentCallLock) {
|
|
91
|
-
return currentCallInfo;
|
|
92
|
-
}
|
|
119
|
+
PushwooshCallsAdapter.onCallCancellationFailed(callId, reason);
|
|
93
120
|
}
|
|
94
121
|
}
|
package/src/android/src/com/pushwoosh/plugin/pushnotifications/calls/PushwooshCallsAdapter.java
CHANGED
|
@@ -8,7 +8,6 @@ import android.content.Intent;
|
|
|
8
8
|
import android.media.AudioManager;
|
|
9
9
|
import android.os.Bundle;
|
|
10
10
|
|
|
11
|
-
import com.pushwoosh.Pushwoosh;
|
|
12
11
|
import com.pushwoosh.calls.CallPermissionsCallback;
|
|
13
12
|
import com.pushwoosh.calls.PushwooshCallReceiver;
|
|
14
13
|
import com.pushwoosh.calls.PushwooshCallSettings;
|
|
@@ -28,20 +27,9 @@ import java.util.ArrayList;
|
|
|
28
27
|
public class PushwooshCallsAdapter implements CallsAdapter {
|
|
29
28
|
public static final String TAG = "PushwooshCallsAdapter";
|
|
30
29
|
|
|
31
|
-
@Override
|
|
32
|
-
public boolean setVoipAppCode(JSONArray data, CallbackContext callbackContext) {
|
|
33
|
-
try {
|
|
34
|
-
String appCode = data.getString(0);
|
|
35
|
-
Pushwoosh.getInstance().addAlternativeAppCode(appCode);
|
|
36
|
-
} catch (JSONException e) {
|
|
37
|
-
PWLog.error(TAG, "No parameters passed (missing parameters)", e);
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
30
|
@Override
|
|
44
31
|
public boolean requestCallPermission(JSONArray data, final CallbackContext callbackContext) {
|
|
32
|
+
PWLog.noise(TAG, "requestCallPermission()");
|
|
45
33
|
try {
|
|
46
34
|
PushwooshCallSettings.requestCallPermissions(new CallPermissionsCallback() {
|
|
47
35
|
@Override
|
|
@@ -59,6 +47,7 @@ public class PushwooshCallsAdapter implements CallsAdapter {
|
|
|
59
47
|
|
|
60
48
|
@Override
|
|
61
49
|
public boolean getCallPermissionStatus(JSONArray data, CallbackContext callbackContext) {
|
|
50
|
+
PWLog.noise(TAG, "getCallPermissionStatus()");
|
|
62
51
|
try {
|
|
63
52
|
int status = PushwooshCallSettings.getCallPermissionStatus();
|
|
64
53
|
callbackContext.success(status);
|
|
@@ -71,6 +60,7 @@ public class PushwooshCallsAdapter implements CallsAdapter {
|
|
|
71
60
|
|
|
72
61
|
@Override
|
|
73
62
|
public boolean registerEvent(JSONArray data, CallbackContext callbackContext) {
|
|
63
|
+
PWLog.noise(TAG, "registerEvent()");
|
|
74
64
|
try {
|
|
75
65
|
|
|
76
66
|
String eventType = data.getString(0);
|
|
@@ -86,6 +76,7 @@ public class PushwooshCallsAdapter implements CallsAdapter {
|
|
|
86
76
|
|
|
87
77
|
@Override
|
|
88
78
|
public boolean unregisterEvent(JSONArray data, CallbackContext callbackContext) {
|
|
79
|
+
PWLog.noise(TAG, "unregisterEvent()");
|
|
89
80
|
try {
|
|
90
81
|
String eventType = data.getString(0);
|
|
91
82
|
ArrayList<CallbackContext> callbackContextList = getCallbackContextMap().get(eventType);
|
|
@@ -104,6 +95,7 @@ public class PushwooshCallsAdapter implements CallsAdapter {
|
|
|
104
95
|
|
|
105
96
|
@Override
|
|
106
97
|
public boolean endCall(JSONArray data, CallbackContext callbackContext) {
|
|
98
|
+
PWLog.noise(TAG, "endCall()");
|
|
107
99
|
Context context = AndroidPlatformModule.getApplicationContext();
|
|
108
100
|
Intent endCallIntent = new Intent(context, PushwooshCallReceiver.class);
|
|
109
101
|
endCallIntent.putExtras(PWCordovaCallEventListener.getCurrentCallInfo());
|
|
@@ -115,6 +107,7 @@ public class PushwooshCallsAdapter implements CallsAdapter {
|
|
|
115
107
|
|
|
116
108
|
@Override
|
|
117
109
|
public boolean initializeVoIPParameters(JSONArray data, CallbackContext callbackContext) {
|
|
110
|
+
PWLog.noise(TAG, "initializeVoIPParameters()");
|
|
118
111
|
try {
|
|
119
112
|
String callSound = data.getString(1);
|
|
120
113
|
if (callSound!= null && !callSound.isEmpty()){
|
|
@@ -129,6 +122,7 @@ public class PushwooshCallsAdapter implements CallsAdapter {
|
|
|
129
122
|
|
|
130
123
|
@Override
|
|
131
124
|
public boolean setIncomingCallTimeout(JSONArray data, CallbackContext callbackContext) {
|
|
125
|
+
PWLog.noise(TAG, "setIncomingCallTimeout()");
|
|
132
126
|
try {
|
|
133
127
|
double timeout = data.getDouble(0);
|
|
134
128
|
PushwooshCallSettings.setIncomingCallTimeout(timeout);
|
|
@@ -141,6 +135,7 @@ public class PushwooshCallsAdapter implements CallsAdapter {
|
|
|
141
135
|
|
|
142
136
|
@Override
|
|
143
137
|
public boolean mute() {
|
|
138
|
+
PWLog.noise(TAG, "mute()");
|
|
144
139
|
try {
|
|
145
140
|
AudioManager audioManager = (AudioManager) getCordovaInterface().getActivity().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
|
|
146
141
|
audioManager.setMicrophoneMute(true);
|
|
@@ -153,6 +148,7 @@ public class PushwooshCallsAdapter implements CallsAdapter {
|
|
|
153
148
|
|
|
154
149
|
@Override
|
|
155
150
|
public boolean unmute() {
|
|
151
|
+
PWLog.noise(TAG, "unmute()");
|
|
156
152
|
try {
|
|
157
153
|
AudioManager audioManager = (AudioManager) getCordovaInterface().getActivity().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
|
|
158
154
|
audioManager.setMicrophoneMute(false);
|
|
@@ -165,6 +161,7 @@ public class PushwooshCallsAdapter implements CallsAdapter {
|
|
|
165
161
|
|
|
166
162
|
@Override
|
|
167
163
|
public boolean speakerOn() {
|
|
164
|
+
PWLog.noise(TAG, "speakerOn()");
|
|
168
165
|
try {
|
|
169
166
|
AudioManager audioManager = (AudioManager) getCordovaInterface().getActivity().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
|
|
170
167
|
audioManager.setSpeakerphoneOn(true);
|
|
@@ -177,6 +174,7 @@ public class PushwooshCallsAdapter implements CallsAdapter {
|
|
|
177
174
|
|
|
178
175
|
@Override
|
|
179
176
|
public boolean speakerOff() {
|
|
177
|
+
PWLog.noise(TAG, "speakerOff()");
|
|
180
178
|
try {
|
|
181
179
|
AudioManager audioManager = (AudioManager) getCordovaInterface().getActivity().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
|
|
182
180
|
audioManager.setSpeakerphoneOn(false);
|
|
@@ -188,27 +186,33 @@ public class PushwooshCallsAdapter implements CallsAdapter {
|
|
|
188
186
|
}
|
|
189
187
|
|
|
190
188
|
public static void onAnswer(PushwooshVoIPMessage voIPMessage) {
|
|
189
|
+
PWLog.noise(TAG, "onAnswer()");
|
|
191
190
|
PushNotifications.emitVoipEvent("answer", parseVoIPMessage(voIPMessage));
|
|
192
191
|
}
|
|
193
192
|
|
|
194
193
|
public static void onReject(PushwooshVoIPMessage voIPMessage) {
|
|
194
|
+
PWLog.noise(TAG, "onReject()");
|
|
195
195
|
PushNotifications.emitVoipEvent("reject", parseVoIPMessage(voIPMessage));
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
public static void onDisconnect(PushwooshVoIPMessage voIPMessage) {
|
|
199
|
+
PWLog.noise(TAG, "onDisconnect()");
|
|
199
200
|
PushNotifications.emitVoipEvent("hangup", parseVoIPMessage(voIPMessage));
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
public static void onCreateIncomingConnection(Bundle bundle) {
|
|
204
|
+
PWLog.noise(TAG, "onCreateIncomingConnection()");
|
|
203
205
|
PushwooshVoIPMessage voipMessage = new PushwooshVoIPMessage(bundle);
|
|
204
206
|
PushNotifications.emitVoipEvent("voipPushPayload", parseVoIPMessage(voipMessage));
|
|
205
207
|
}
|
|
206
208
|
|
|
207
209
|
public static void onCallCancelled(PushwooshVoIPMessage voIPMessage) {
|
|
210
|
+
PWLog.noise(TAG, "onCallCancelled()");
|
|
208
211
|
PushNotifications.emitVoipEvent("voipDidCancelCall", parseVoIPMessage(voIPMessage));
|
|
209
212
|
}
|
|
210
213
|
|
|
211
214
|
public static void onCallCancellationFailed(String callId, String reason) {
|
|
215
|
+
PWLog.noise(TAG, "onCallCancellationFailed()");
|
|
212
216
|
org.json.JSONObject payload = new org.json.JSONObject();
|
|
213
217
|
try {
|
|
214
218
|
payload.put("callId", callId != null ? callId : "");
|
|
@@ -218,6 +222,7 @@ public class PushwooshCallsAdapter implements CallsAdapter {
|
|
|
218
222
|
}
|
|
219
223
|
|
|
220
224
|
private static org.json.JSONObject parseVoIPMessage(PushwooshVoIPMessage message) {
|
|
225
|
+
PWLog.noise(TAG, "parseVoIPMessage()");
|
|
221
226
|
org.json.JSONObject payload = new org.json.JSONObject();
|
|
222
227
|
try {
|
|
223
228
|
Bundle rawBundle = message.getRawPayload();
|