pushwoosh-cordova-plugin 8.3.39 → 8.3.40

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.
@@ -10,18 +10,24 @@
10
10
 
11
11
  package com.pushwoosh.plugin.pushnotifications;
12
12
 
13
+ import android.content.Context;
13
14
  import android.content.Intent;
15
+ import android.media.AudioManager;
16
+ import android.nfc.Tag;
14
17
  import android.os.Bundle;
15
18
  import android.os.Handler;
16
19
  import android.os.Looper;
17
20
  import androidx.annotation.NonNull;
21
+ import androidx.annotation.Nullable;
18
22
  import androidx.core.app.NotificationManagerCompat;
19
23
  import android.webkit.JavascriptInterface;
20
24
 
21
- import com.pushwoosh.GDPRManager;
22
25
  import com.pushwoosh.Pushwoosh;
23
26
  import com.pushwoosh.RegisterForPushNotificationsResultData;
24
27
  import com.pushwoosh.badge.PushwooshBadge;
28
+ import com.pushwoosh.calls.PushwooshCallReceiver;
29
+ import com.pushwoosh.calls.PushwooshCallSettings;
30
+ import com.pushwoosh.calls.PushwooshVoIPMessage;
25
31
  import com.pushwoosh.exception.GetTagsException;
26
32
  import com.pushwoosh.exception.PushwooshException;
27
33
  import com.pushwoosh.exception.RegisterForPushNotificationsException;
@@ -33,6 +39,7 @@ import com.pushwoosh.inbox.PushwooshInbox;
33
39
  import com.pushwoosh.inbox.data.InboxMessage;
34
40
  import com.pushwoosh.inbox.exception.InboxMessagesException;
35
41
  import com.pushwoosh.inbox.ui.presentation.view.activity.InboxActivity;
42
+ import com.pushwoosh.internal.platform.AndroidPlatformModule;
36
43
  import com.pushwoosh.internal.platform.utils.GeneralUtils;
37
44
  import com.pushwoosh.internal.utils.JsonUtils;
38
45
  import com.pushwoosh.internal.utils.PWLog;
@@ -46,7 +53,10 @@ import com.pushwoosh.tags.Tags;
46
53
  import com.pushwoosh.tags.TagsBundle;
47
54
 
48
55
  import org.apache.cordova.CallbackContext;
56
+ import org.apache.cordova.CordovaInterface;
49
57
  import org.apache.cordova.CordovaPlugin;
58
+ import org.apache.cordova.CordovaWebView;
59
+ import org.apache.cordova.PluginResult;
50
60
  import org.json.JSONArray;
51
61
  import org.json.JSONException;
52
62
  import org.json.JSONObject;
@@ -73,6 +83,10 @@ public class PushNotifications extends CordovaPlugin {
73
83
  private static AtomicBoolean sAppReady = new AtomicBoolean();
74
84
  private static PushNotifications sInstance;
75
85
 
86
+ // private CallbackContext callbackContext;
87
+ private static CordovaInterface cordovaInterface;
88
+ private static HashMap<String, ArrayList<CallbackContext>> callbackContextMap = new HashMap<String, ArrayList<CallbackContext>>();
89
+
76
90
  private final HashMap<String, CallbackContext> callbackIds = new HashMap<String, CallbackContext>();
77
91
 
78
92
  private static final Map<String, Method> exportedMethods;
@@ -96,6 +110,14 @@ public class PushNotifications extends CordovaPlugin {
96
110
  exportedMethods = methods;
97
111
  }
98
112
 
113
+ public static CordovaInterface getCordova() {
114
+ return cordovaInterface;
115
+ }
116
+
117
+ public static HashMap<String, ArrayList<CallbackContext>> getCallbackContexts() {
118
+ return callbackContextMap;
119
+ }
120
+
99
121
  private final Handler handler = new Handler(Looper.getMainLooper());
100
122
 
101
123
  public PushNotifications () {
@@ -717,72 +739,27 @@ public class PushNotifications extends CordovaPlugin {
717
739
  }
718
740
  }
719
741
 
720
- @CordovaMethod
721
- public boolean showGDPRConsentUI(JSONArray data, final CallbackContext callbackContext) {
722
- GDPRManager.getInstance().showGDPRConsentUI();
723
- return true;
724
- }
725
-
726
- @CordovaMethod
727
- public boolean showGDPRDeletionUI(JSONArray data, final CallbackContext callbackContext) {
728
- GDPRManager.getInstance().showGDPRDeletionUI();
729
- return true;
730
- }
731
-
732
- @CordovaMethod
733
- public boolean isDeviceDataRemoved(JSONArray data, final CallbackContext callbackContext) {
734
- boolean removed = GDPRManager.getInstance().isDeviceDataRemoved();
735
- callbackContext.success(removed ? 1 : 0);
736
- return true;
737
- }
738
-
739
742
  @CordovaMethod
740
743
  public boolean isCommunicationEnabled(JSONArray data, final CallbackContext callbackContext) {
741
- boolean enabled = GDPRManager.getInstance().isCommunicationEnabled();
744
+ boolean enabled = Pushwoosh.getInstance().isServerCommunicationAllowed();
742
745
  callbackContext.success(enabled ? 1 : 0);
743
746
  return true;
744
747
 
745
748
  }
746
749
 
747
- @CordovaMethod
748
- public boolean isAvailableGDPR(JSONArray data, final CallbackContext callbackContext) {
749
- boolean isAvailableGDPR = GDPRManager.getInstance().isAvailable();
750
- callbackContext.success(isAvailableGDPR ? 1 : 0);
751
- return true;
752
- }
753
-
754
- @CordovaMethod
755
- public boolean removeAllDeviceData(JSONArray data, final CallbackContext callbackContext) {
756
- GDPRManager.getInstance().removeAllDeviceData(new Callback<Void, PushwooshException>() {
757
- @Override
758
- public void process(@NonNull Result<Void, PushwooshException> result) {
759
- if(result.isSuccess()) {
760
- callbackContext.success();
761
- }else {
762
- callbackContext.error(result.getException().getMessage());
763
- }
764
- }
765
- });
766
- return true;
767
- }
768
-
769
750
  @CordovaMethod
770
751
  public boolean setCommunicationEnabled(JSONArray data, final CallbackContext callbackContext) {
771
752
  try {
772
753
  boolean enable = data.getBoolean(0);
773
- GDPRManager.getInstance().setCommunicationEnabled(enable, new Callback<Void, PushwooshException>() {
774
- @Override
775
- public void process(@NonNull Result<Void, PushwooshException> result) {
776
- if(result.isSuccess()) {
777
- callbackContext.success();
778
- }else {
779
- callbackContext.error(result.getException().getMessage());
780
- }
781
- }
782
- });
754
+ if (enable) {
755
+ Pushwoosh.getInstance().startServerCommunication();
756
+ } else {
757
+ Pushwoosh.getInstance().stopServerCommunication();
758
+ }
759
+ callbackContext.success();
783
760
  return true;
784
761
  } catch (JSONException e) {
785
- e.printStackTrace();
762
+ callbackContext.error(e.getMessage());
786
763
  }
787
764
  return false;
788
765
  }
@@ -881,6 +858,15 @@ public class PushNotifications extends CordovaPlugin {
881
858
  return true;
882
859
  }
883
860
 
861
+ @Override
862
+ public void initialize(CordovaInterface cordova, CordovaWebView webView) {
863
+ cordovaInterface = cordova;
864
+ callbackContextMap.put("answer", new ArrayList<CallbackContext>());
865
+ callbackContextMap.put("reject", new ArrayList<CallbackContext>());
866
+ callbackContextMap.put("hangup", new ArrayList<CallbackContext>());
867
+ callbackContextMap.put("voipPushPayload", new ArrayList<CallbackContext>());
868
+ }
869
+
884
870
  @Override
885
871
  public boolean execute(String action, JSONArray data, CallbackContext callbackId) {
886
872
  PWLog.debug(TAG, "Plugin Method Called: " + action);
@@ -1071,14 +1057,214 @@ public class PushNotifications extends CordovaPlugin {
1071
1057
  }
1072
1058
 
1073
1059
  @CordovaMethod
1074
- private boolean setApiToken(JSONArray data, final CallbackContext callbackContextn) {
1060
+ private boolean setApiToken(JSONArray data, final CallbackContext callbackContext) {
1061
+ try {
1062
+ String appCode = data.getString(0);
1063
+ Pushwoosh.getInstance().addAlternativeAppCode(appCode);
1064
+ } catch (JSONException e) {
1065
+ PWLog.error(TAG, "No parameters passed (missing parameters)", e);
1066
+ }
1067
+ return true;
1068
+ }
1069
+
1070
+ @CordovaMethod
1071
+ private boolean setVoipAppCode(JSONArray data, CallbackContext callbackContext) {
1075
1072
  try {
1076
- String token = data.getString(0);
1077
- Pushwoosh.getInstance().setApiToken(token);
1073
+ String appCode = data.getString(0);
1074
+ Pushwoosh.getInstance().addAlternativeAppCode(appCode);
1078
1075
  } catch (JSONException e) {
1079
1076
  PWLog.error(TAG, "No parameters passed (missing parameters)", e);
1077
+ return false;
1078
+ }
1079
+ return true;
1080
+ }
1081
+
1082
+ @CordovaMethod
1083
+ private boolean requestCallPermission(JSONArray data, final CallbackContext callbackContext) {
1084
+ try {
1085
+ PushwooshCallSettings.requestCallPermissions();
1086
+ } catch (Exception e) {
1087
+ PWLog.error(TAG, "Failed to request call permissions: " + e.getMessage());
1088
+ return false;
1089
+ }
1090
+ return true;
1091
+ }
1092
+
1093
+ @CordovaMethod
1094
+ private boolean registerEvent(JSONArray data, final CallbackContext callbackContext) {
1095
+ try {
1096
+
1097
+ String eventType = data.getString(0);
1098
+ ArrayList<CallbackContext> callbackContextList = callbackContextMap.get(eventType);
1099
+ if (callbackContextList != null) {
1100
+ callbackContextList.add(callbackContext);
1101
+ }
1102
+ return true;
1103
+ } catch (Exception e) {
1104
+
1105
+ return false;
1106
+ }
1107
+ }
1108
+
1109
+ @CordovaMethod
1110
+ private boolean endCall(JSONArray data, final CallbackContext callbackContext) {
1111
+ Context context = AndroidPlatformModule.getApplicationContext();
1112
+ Intent endCallIntent = new Intent(context, PushwooshCallReceiver.class);
1113
+ endCallIntent.putExtras(PWCordovaCallEventListener.getCurrentCallInfo());
1114
+ endCallIntent.setAction("ACTION_END_CALL");
1115
+ getCordova().getActivity().getApplicationContext().sendBroadcast(endCallIntent);
1116
+
1117
+ return true;
1118
+ }
1119
+
1120
+ @CordovaMethod
1121
+ private boolean initializeVoIPParameters(JSONArray data, final CallbackContext callbackContext) {
1122
+ try {
1123
+ String callSound = data.getString(1);
1124
+ if (callSound!= null && !callSound.isEmpty()){
1125
+ PushwooshCallSettings.setCallSound(callSound);
1126
+ }
1127
+ return true;
1128
+ } catch (Exception e) {
1129
+ PWLog.error("Failed to fetch custom sound name");
1130
+ return false;
1131
+ }
1132
+ }
1133
+
1134
+ @CordovaMethod
1135
+ private boolean mute() {
1136
+ try {
1137
+ AudioManager audioManager = (AudioManager) this.cordova.getActivity().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
1138
+ audioManager.setMicrophoneMute(true);
1139
+ return true;
1140
+ } catch (Exception e) {
1141
+ PWLog.error("Failed to mute audio channel");
1142
+ return false;
1080
1143
  }
1144
+ }
1145
+
1146
+ @CordovaMethod
1147
+ private boolean unmute() {
1148
+ try {
1149
+ AudioManager audioManager = (AudioManager) this.cordova.getActivity().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
1150
+ audioManager.setMicrophoneMute(false);
1151
+ return true;
1152
+ } catch (Exception e) {
1153
+ PWLog.error("Failed to unmute audio channel");
1154
+ return false;
1155
+ }
1156
+ }
1157
+
1158
+ @CordovaMethod
1159
+ private boolean speakerOn() {
1160
+ try {
1161
+ AudioManager audioManager = (AudioManager) this.cordova.getActivity().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
1162
+ audioManager.setSpeakerphoneOn(true);
1081
1163
  return true;
1164
+ } catch (Exception e) {
1165
+ PWLog.error("Failed to turn speaker on");
1166
+ return false;
1167
+ }
1168
+ }
1169
+
1170
+ @CordovaMethod
1171
+ private boolean speakerOff() {
1172
+ try {
1173
+ AudioManager audioManager = (AudioManager) this.cordova.getActivity().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
1174
+ audioManager.setSpeakerphoneOn(false);
1175
+ return true;
1176
+ } catch (Exception e) {
1177
+ PWLog.error("Failed to turn speaker off");
1178
+ return false;
1179
+ }
1180
+ }
1181
+
1182
+ public static void onAnswer(PushwooshVoIPMessage voIPMessage) {
1183
+ Context context = AndroidPlatformModule.getApplicationContext();
1184
+ if (context == null) {
1185
+ return;
1186
+ }
1187
+ Intent launchIntent = context.getPackageManager()
1188
+ .getLaunchIntentForPackage(context.getPackageName());
1189
+ if (launchIntent == null) {
1190
+ return;
1191
+ }
1192
+ launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
1193
+ context.startActivity(launchIntent);
1194
+ ArrayList<CallbackContext> callbackContexts = getCallbackContexts().get("answer");
1195
+ if (callbackContexts != null) {
1196
+ for (final CallbackContext callbackContext : callbackContexts) {
1197
+ getCordova().getThreadPool().execute(new Runnable() {
1198
+ public void run() {;
1199
+ PluginResult result = new PluginResult(
1200
+ PluginResult.Status.OK, parseVoIPMessage(voIPMessage));
1201
+ result.setKeepCallback(true);
1202
+ callbackContext.sendPluginResult(result);
1203
+ }
1204
+ });
1205
+ }
1206
+ }
1207
+ }
1208
+
1209
+ public static void onReject(PushwooshVoIPMessage voIPMessage) {
1210
+ ArrayList<CallbackContext> callbackContexts = getCallbackContexts().get("reject");
1211
+ if (callbackContexts != null) {
1212
+ for (final CallbackContext callbackContext : callbackContexts) {
1213
+ getCordova().getThreadPool().execute(new Runnable() {
1214
+ public void run() {
1215
+ PluginResult result = new PluginResult(
1216
+ PluginResult.Status.OK, parseVoIPMessage(voIPMessage));
1217
+ result.setKeepCallback(true);
1218
+ callbackContext.sendPluginResult(result);
1219
+ }
1220
+ });
1221
+ }
1222
+ }
1223
+ }
1224
+
1225
+ public static void onDisconnect(PushwooshVoIPMessage voIPMessage) {
1226
+ ArrayList<CallbackContext> callbackContexts = getCallbackContexts().get("hangup");
1227
+ if (callbackContexts != null) {
1228
+ for (final CallbackContext callbackContext : callbackContexts) {
1229
+ getCordova().getThreadPool().execute(new Runnable() {
1230
+ public void run() {
1231
+ PluginResult result = new PluginResult(
1232
+ PluginResult.Status.OK, parseVoIPMessage(voIPMessage));
1233
+ result.setKeepCallback(true);
1234
+ callbackContext.sendPluginResult(result);
1235
+ }
1236
+ });
1237
+ }
1238
+ }
1239
+ }
1240
+
1241
+ public static void onCreateIncomingConnection(@Nullable Bundle bundle) {
1242
+ ArrayList<CallbackContext> callbackContexts = getCallbackContexts().get("voipPushPayload");
1243
+ if (callbackContexts != null) {
1244
+ for (final CallbackContext callbackContext : callbackContexts) {
1245
+ getCordova().getThreadPool().execute(new Runnable() {
1246
+ public void run() {
1247
+ JSONObject payload = JsonUtils.bundleToJson(bundle);
1248
+ PluginResult result = new PluginResult(
1249
+ PluginResult.Status.OK, payload);
1250
+ result.setKeepCallback(true);
1251
+ callbackContext.sendPluginResult(result);
1252
+ }
1253
+ });
1254
+ }
1255
+ }
1256
+ }
1257
+
1258
+ private static JSONObject parseVoIPMessage(PushwooshVoIPMessage message) {
1259
+ JSONObject payload = new JSONObject();
1260
+ try {
1261
+ payload.put("callerName", message.getCallerName())
1262
+ .put("rawPayload", message.getRawPayload())
1263
+ .put("hasVideo", message.getHasVideo());
1264
+ } catch (JSONException e) {
1265
+ PWLog.error("Failed to parse call notification payload");
1266
+ }
1267
+ return payload;
1082
1268
  }
1083
1269
 
1084
1270
  private static JSONObject inboxMessageToJson(InboxMessage message) {
@@ -1105,5 +1291,4 @@ public class PushNotifications extends CordovaPlugin {
1105
1291
  }
1106
1292
  return object;
1107
1293
  }
1108
-
1109
- }
1294
+ }