pushwoosh-cordova-plugin 8.3.42 → 8.3.43

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
@@ -14,13 +14,13 @@ Cross-Platform push notifications by Pushwoosh for Cordova / PhoneGap
14
14
  Using npm:
15
15
 
16
16
  ```
17
- cordova plugin add pushwoosh-cordova-plugin@8.3.42
17
+ cordova plugin add pushwoosh-cordova-plugin@8.3.43
18
18
  ```
19
19
 
20
20
  Using git:
21
21
 
22
22
  ```
23
- cordova plugin add https://github.com/Pushwoosh/pushwoosh-phonegap-plugin.git#8.3.42
23
+ cordova plugin add https://github.com/Pushwoosh/pushwoosh-phonegap-plugin.git#8.3.43
24
24
  ```
25
25
 
26
26
  ### Guide
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pushwoosh-cordova-plugin",
3
- "version": "8.3.42",
3
+ "version": "8.3.43",
4
4
  "description": "\n This plugin allows you to send and receive push notifications. Powered by Pushwoosh (www.pushwoosh.com).\n ",
5
5
  "main":"www/PushNotification.js",
6
6
  "typings":"types/index.d.ts",
package/plugin.xml CHANGED
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="pushwoosh-cordova-plugin" version="8.3.42">
2
+ <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="pushwoosh-cordova-plugin" version="8.3.43">
3
3
 
4
4
  <name>Pushwoosh</name>
5
5
 
@@ -20,6 +20,8 @@
20
20
  <preference name="IOS_FOREGROUND_ALERT_TYPE" default="ALERT" />
21
21
  <preference name="ANDROID_FOREGROUND_PUSH" default="true" />
22
22
  <preference name="PW_VOIP_IOS_ENABLED" default="false" />
23
+ <preference name="PW_VOIP_ANDROID_ENABLED" default="false" />
24
+
23
25
 
24
26
  <js-module src="www/PushNotification.js" name="PushNotification">
25
27
  <clobbers target="plugins.pushNotification" />
@@ -55,6 +57,8 @@
55
57
  </feature>
56
58
  </config-file>
57
59
 
60
+ <!-- core source files -->
61
+
58
62
  <source-file src="src/android/src/com/pushwoosh/plugin/pushnotifications/PushNotifications.java"
59
63
  target-dir="src/com/pushwoosh/plugin/pushnotifications" />
60
64
 
@@ -69,7 +73,15 @@
69
73
 
70
74
  <source-file src="src/android/src/com/pushwoosh/plugin/internal/PhonegapPluginProvider.java"
71
75
  target-dir="src/com/pushwoosh/plugin/internal" />
72
- <source-file src="src/android/src/com/pushwoosh/plugin/pushnotifications/PWCordovaCallEventListener.java" target-dir="src/com/pushwoosh/plugin/pushnotifications" />
76
+
77
+ <!-- required call source files -->
78
+ <source-file src="src/android/src/com/pushwoosh/plugin/pushnotifications/CallsAdapter.java" target-dir="src/com/pushwoosh/plugin/pushnotifications" />
79
+ <source-file src="src/android/src/com/pushwoosh/plugin/pushnotifications/NoopCallsAdapter.java" target-dir="src/com/pushwoosh/plugin/pushnotifications" />
80
+ <source-file src="src/android/src/com/pushwoosh/plugin/pushnotifications/CallsAdapterFactory.java" target-dir="src/com/pushwoosh/plugin/pushnotifications" />
81
+
82
+ <!-- gradle script to include pushwoosh-calls-related source files and dependencies -->
83
+ <hook type="after_prepare" src="spec/set-voip-gradle-prop.js" />
84
+ <framework src="src/android/add-android-voip.gradle" custom="true" type="gradleReference" />
73
85
 
74
86
  <framework src="build-extras-pushwoosh.gradle" custom="true" type="gradleReference" />
75
87
 
@@ -83,14 +95,13 @@
83
95
  <framework src="org.jetbrains.kotlin:kotlin-stdlib:1.1.60" />
84
96
  <framework src="com.google.android.material:material:1.12.0"/>
85
97
 
86
- <framework src="com.pushwoosh:pushwoosh:6.7.31"/>
87
- <framework src="com.pushwoosh:pushwoosh-amazon:6.7.31"/>
88
- <framework src="com.pushwoosh:pushwoosh-firebase:6.7.31"/>
89
- <framework src="com.pushwoosh:pushwoosh-badge:6.7.31"/>
90
- <framework src="com.pushwoosh:pushwoosh-inbox:6.7.31"/>
91
- <framework src="com.pushwoosh:pushwoosh-inbox-ui:6.7.31"/>
92
- <framework src="com.pushwoosh:pushwoosh-huawei:6.7.31"/>
93
- <framework src="com.pushwoosh:pushwoosh-calls:6.7.31"/>
98
+ <framework src="com.pushwoosh:pushwoosh:6.7.32"/>
99
+ <framework src="com.pushwoosh:pushwoosh-amazon:6.7.32"/>
100
+ <framework src="com.pushwoosh:pushwoosh-firebase:6.7.32"/>
101
+ <framework src="com.pushwoosh:pushwoosh-badge:6.7.32"/>
102
+ <framework src="com.pushwoosh:pushwoosh-inbox:6.7.32"/>
103
+ <framework src="com.pushwoosh:pushwoosh-inbox-ui:6.7.32"/>
104
+ <framework src="com.pushwoosh:pushwoosh-huawei:6.7.32"/>
94
105
  </platform>
95
106
 
96
107
  <!-- ios -->
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ module.exports = function (ctx) {
6
+ if (!ctx.opts.platforms.includes('android')) return;
7
+
8
+ const projectRoot = ctx.opts.projectRoot;
9
+ // Cordova tracks plugin vars in plugins/fetch.json — reliable source
10
+ const fetchPath = path.join(projectRoot, 'plugins', 'fetch.json');
11
+ if (!fs.existsSync(fetchPath)) return;
12
+
13
+ const fetch = JSON.parse(fs.readFileSync(fetchPath, 'utf8'));
14
+ const entry = fetch['pushwoosh-cordova-plugin'];
15
+ const vars = (entry && entry.variables) || {};
16
+ const val = String(vars.PW_VOIP_ANDROID_ENABLED || 'false').toLowerCase();
17
+
18
+ // Write to platforms/android/gradle.properties
19
+ const gradleProps = path.join(projectRoot, 'platforms', 'android', 'gradle.properties');
20
+ if (!fs.existsSync(path.dirname(gradleProps))) return; // android platform not added yet
21
+
22
+ let contents = fs.existsSync(gradleProps) ? fs.readFileSync(gradleProps, 'utf8') : '';
23
+ const line = `PW_VOIP_ANDROID_ENABLED=${val}\n`;
24
+ const re = /^PW_VOIP_ANDROID_ENABLED=.*$/m;
25
+
26
+ if (re.test(contents)) {
27
+ contents = contents.replace(re, line.trim());
28
+ } else {
29
+ if (contents.length && !contents.endsWith('\n')) contents += '\n';
30
+ contents += line;
31
+ }
32
+
33
+ fs.writeFileSync(gradleProps, contents, 'utf8');
34
+ console.log(`[pushwoosh-cordova-plugin] Wrote PW_VOIP_ANDROID_ENABLED=${val} to gradle.properties`);
35
+ };
@@ -0,0 +1,35 @@
1
+ // Read from: -P, env, or (last-resort) literal placeholder
2
+ def _rawVoip = (project.findProperty('PW_VOIP_ANDROID_ENABLED')
3
+ ?: System.getenv('PW_VOIP_ANDROID_ENABLED')
4
+ ?: '$PW_VOIP_ANDROID_ENABLED') // stays literal if not set
5
+
6
+ def voipEnabled = _rawVoip.toString().trim().toLowerCase() in ['1','true','yes','y']
7
+
8
+ def pluginId = 'pushwoosh-cordova-plugin'
9
+ def pluginDirCandidates = [
10
+ file("${rootDir}/../plugins/${pluginId}"),
11
+ file("${rootDir}/../../plugins/${pluginId}")
12
+ ]
13
+ def pluginDir = pluginDirCandidates.find { it.exists() }
14
+ def callsSrc = pluginDir ? new File(pluginDir, 'src/android/src/com/pushwoosh/plugin/pushnotifications/calls') : null
15
+
16
+ def applyVoip = {
17
+ if (voipEnabled) {
18
+ println "[${pluginId}] PW_VOIP_ANDROID_ENABLED=true — enabling VoIP (dependency + sources)"
19
+ dependencies { implementation "com.pushwoosh:pushwoosh-calls:6.7.32" }
20
+ if (callsSrc?.exists()) {
21
+ android.sourceSets.main.java.srcDirs += callsSrc
22
+ println "[${pluginId}] Added optional sources: ${callsSrc}"
23
+ } else {
24
+ println "[${pluginId}] WARN optional sources not found at ${callsSrc}"
25
+ }
26
+ } else {
27
+ println "[${pluginId}] PW_VOIP_ANDROID_ENABLED=false — VoIP disabled"
28
+ }
29
+ }
30
+
31
+ if (project.hasProperty('cdvPluginPostBuildExtras')) {
32
+ cdvPluginPostBuildExtras << applyVoip
33
+ } else {
34
+ afterEvaluate { applyVoip() }
35
+ }
@@ -0,0 +1,16 @@
1
+ package com.pushwoosh.plugin.pushnotifications;
2
+
3
+ import org.apache.cordova.CallbackContext;
4
+ import org.json.JSONArray;
5
+
6
+ public interface CallsAdapter {
7
+ public boolean setVoipAppCode(JSONArray data, CallbackContext callbackContext);
8
+ public boolean requestCallPermission(JSONArray data, final CallbackContext callbackContext);
9
+ public boolean registerEvent(JSONArray data, final CallbackContext callbackContext);
10
+ public boolean endCall(JSONArray data, final CallbackContext callbackContext);
11
+ public boolean initializeVoIPParameters(JSONArray data, final CallbackContext callbackContext);
12
+ public boolean mute();
13
+ public boolean unmute();
14
+ public boolean speakerOn();
15
+ public boolean speakerOff();
16
+ }
@@ -0,0 +1,16 @@
1
+ package com.pushwoosh.plugin.pushnotifications;
2
+
3
+ import android.content.Context;
4
+
5
+ public final class CallsAdapterFactory {
6
+ private static final String REAL_IMPL = "com.pushwoosh.plugin.pushnotifications.calls.PushwooshCallsAdapter";
7
+
8
+ public static CallsAdapter create(Context ctx) {
9
+ try {
10
+ Class<?> c = Class.forName(REAL_IMPL);
11
+ return (CallsAdapter) c.getDeclaredConstructor().newInstance();
12
+ } catch (Throwable ignored) {
13
+ return new NoopCallsAdapter();
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,63 @@
1
+ package com.pushwoosh.plugin.pushnotifications;
2
+
3
+ import com.pushwoosh.internal.utils.PWLog;
4
+
5
+ import org.apache.cordova.CallbackContext;
6
+ import org.json.JSONArray;
7
+
8
+ public class NoopCallsAdapter implements CallsAdapter{
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
+
16
+ @Override
17
+ public boolean requestCallPermission(JSONArray data, CallbackContext callbackContext) {
18
+ PWLog.error(TAG,"Method not implemented");
19
+ return false;
20
+ }
21
+
22
+ @Override
23
+ public boolean registerEvent(JSONArray data, CallbackContext callbackContext) {
24
+ PWLog.error(TAG,"Method not implemented");
25
+ return false;
26
+ }
27
+
28
+ @Override
29
+ public boolean endCall(JSONArray data, CallbackContext callbackContext) {
30
+ PWLog.error(TAG,"Method not implemented");
31
+ return false;
32
+ }
33
+
34
+ @Override
35
+ public boolean initializeVoIPParameters(JSONArray data, CallbackContext callbackContext) {
36
+ PWLog.error(TAG,"Method not implemented");
37
+ return false;
38
+ }
39
+
40
+ @Override
41
+ public boolean mute() {
42
+ PWLog.error(TAG,"Method not implemented");
43
+ return false;
44
+ }
45
+
46
+ @Override
47
+ public boolean unmute() {
48
+ PWLog.error(TAG,"Method not implemented");
49
+ return false;
50
+ }
51
+
52
+ @Override
53
+ public boolean speakerOn() {
54
+ PWLog.error(TAG,"Method not implemented");
55
+ return false;
56
+ }
57
+
58
+ @Override
59
+ public boolean speakerOff() {
60
+ PWLog.error(TAG,"Method not implemented");
61
+ return false;
62
+ }
63
+ }
@@ -10,36 +10,28 @@
10
10
 
11
11
  package com.pushwoosh.plugin.pushnotifications;
12
12
 
13
- import android.content.Context;
14
13
  import android.content.Intent;
15
- import android.media.AudioManager;
16
- import android.nfc.Tag;
17
14
  import android.os.Bundle;
18
15
  import android.os.Handler;
19
16
  import android.os.Looper;
20
17
  import androidx.annotation.NonNull;
21
- import androidx.annotation.Nullable;
22
18
  import androidx.core.app.NotificationManagerCompat;
23
19
  import android.webkit.JavascriptInterface;
24
20
 
25
21
  import com.pushwoosh.Pushwoosh;
26
22
  import com.pushwoosh.RegisterForPushNotificationsResultData;
27
23
  import com.pushwoosh.badge.PushwooshBadge;
28
- import com.pushwoosh.calls.PushwooshCallReceiver;
29
- import com.pushwoosh.calls.PushwooshCallSettings;
30
- import com.pushwoosh.calls.PushwooshVoIPMessage;
31
24
  import com.pushwoosh.exception.GetTagsException;
32
25
  import com.pushwoosh.exception.PushwooshException;
33
26
  import com.pushwoosh.exception.RegisterForPushNotificationsException;
34
27
  import com.pushwoosh.exception.UnregisterForPushNotificationException;
35
28
  import com.pushwoosh.function.Callback;
36
29
  import com.pushwoosh.function.Result;
37
- import com.pushwoosh.inapp.PushwooshInApp;
30
+ import com.pushwoosh.inapp.InAppManager;
38
31
  import com.pushwoosh.inbox.PushwooshInbox;
39
32
  import com.pushwoosh.inbox.data.InboxMessage;
40
33
  import com.pushwoosh.inbox.exception.InboxMessagesException;
41
34
  import com.pushwoosh.inbox.ui.presentation.view.activity.InboxActivity;
42
- import com.pushwoosh.internal.platform.AndroidPlatformModule;
43
35
  import com.pushwoosh.internal.platform.utils.GeneralUtils;
44
36
  import com.pushwoosh.internal.utils.JsonUtils;
45
37
  import com.pushwoosh.internal.utils.PWLog;
@@ -83,8 +75,10 @@ public class PushNotifications extends CordovaPlugin {
83
75
  private static AtomicBoolean sAppReady = new AtomicBoolean();
84
76
  private static PushNotifications sInstance;
85
77
 
86
- // private CallbackContext callbackContext;
78
+ // private CallbackContext callbackContext;
87
79
  private static CordovaInterface cordovaInterface;
80
+ private static CallsAdapter callsAdapter;
81
+
88
82
  private static HashMap<String, ArrayList<CallbackContext>> callbackContextMap = new HashMap<String, ArrayList<CallbackContext>>();
89
83
 
90
84
  private final HashMap<String, CallbackContext> callbackIds = new HashMap<String, CallbackContext>();
@@ -110,10 +104,14 @@ public class PushNotifications extends CordovaPlugin {
110
104
  exportedMethods = methods;
111
105
  }
112
106
 
113
- public static CordovaInterface getCordova() {
107
+ public static CordovaInterface getCordovaInterface() {
114
108
  return cordovaInterface;
115
109
  }
116
110
 
111
+ public static HashMap<String, ArrayList<CallbackContext>> getCallbackContextMap() {
112
+ return callbackContextMap;
113
+ }
114
+
117
115
  public static HashMap<String, ArrayList<CallbackContext>> getCallbackContexts() {
118
116
  return callbackContextMap;
119
117
  }
@@ -544,7 +542,7 @@ public class PushNotifications extends CordovaPlugin {
544
542
  private boolean setUserId(JSONArray data, final CallbackContext callbackContext) {
545
543
  try {
546
544
  String userId = data.getString(0);
547
- PushwooshInApp.getInstance().setUserId(userId);
545
+ Pushwoosh.getInstance().setUserId(userId);
548
546
  } catch (JSONException e) {
549
547
  PWLog.error(TAG, "No parameters passed (missing parameters)", e);
550
548
  }
@@ -556,7 +554,7 @@ public class PushNotifications extends CordovaPlugin {
556
554
  try {
557
555
  String event = data.getString(0);
558
556
  JSONObject attributes = data.getJSONObject(1);
559
- PushwooshInApp.getInstance().postEvent(event, Tags.fromJson(attributes));
557
+ InAppManager.getInstance().postEvent(event, Tags.fromJson(attributes));
560
558
  } catch (JSONException e) {
561
559
  PWLog.error(TAG, "No parameters passed (missing parameters)", e);
562
560
  }
@@ -813,7 +811,7 @@ public class PushNotifications extends CordovaPlugin {
813
811
  for (int i = 0; i < emailsArray.length(); i++) {
814
812
  emails.add(emailsArray.getString(i));
815
813
  }
816
-
814
+
817
815
  Pushwoosh.getInstance().setUser(userId, emails, result -> {
818
816
  if (result.isSuccess()) {
819
817
  callbackContext.success();
@@ -861,6 +859,7 @@ public class PushNotifications extends CordovaPlugin {
861
859
  @Override
862
860
  public void initialize(CordovaInterface cordova, CordovaWebView webView) {
863
861
  cordovaInterface = cordova;
862
+ callsAdapter = CallsAdapterFactory.create(cordova.getActivity().getApplicationContext());
864
863
  callbackContextMap.put("answer", new ArrayList<CallbackContext>());
865
864
  callbackContextMap.put("reject", new ArrayList<CallbackContext>());
866
865
  callbackContextMap.put("hangup", new ArrayList<CallbackContext>());
@@ -1047,7 +1046,7 @@ public class PushNotifications extends CordovaPlugin {
1047
1046
  private boolean addJavaScriptInterface(JSONArray data, final CallbackContext callbackContext) {
1048
1047
  try {
1049
1048
  String name = data.getString(0);
1050
- PushwooshInApp.getInstance().addJavascriptInterface(new JavascriptInterfaceCordova(), name);
1049
+ InAppManager.getInstance().addJavascriptInterface(new JavascriptInterfaceCordova(), name);
1051
1050
  } catch (JSONException e) {
1052
1051
  PWLog.error(TAG, "No parameters has been passed to addJavaScriptInterface function. Did you follow the guide correctly?", e);
1053
1052
  return false;
@@ -1069,202 +1068,60 @@ public class PushNotifications extends CordovaPlugin {
1069
1068
 
1070
1069
  @CordovaMethod
1071
1070
  private boolean setVoipAppCode(JSONArray data, CallbackContext callbackContext) {
1072
- try {
1073
- String appCode = data.getString(0);
1074
- Pushwoosh.getInstance().addAlternativeAppCode(appCode);
1075
- } catch (JSONException e) {
1076
- PWLog.error(TAG, "No parameters passed (missing parameters)", e);
1077
- return false;
1078
- }
1079
- return true;
1071
+ return callsAdapter.setVoipAppCode(data, callbackContext);
1080
1072
  }
1081
1073
 
1082
1074
  @CordovaMethod
1083
1075
  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
- }
1076
+ return callsAdapter.requestCallPermission(data, callbackContext);
1077
+ }
1092
1078
 
1093
1079
  @CordovaMethod
1094
1080
  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
- }
1081
+ return callsAdapter.registerEvent(data, callbackContext);
1107
1082
  }
1108
1083
 
1109
1084
  @CordovaMethod
1110
1085
  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;
1086
+ return callsAdapter.endCall(data,callbackContext);
1118
1087
  }
1119
1088
 
1120
1089
  @CordovaMethod
1121
1090
  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
- }
1091
+ return callsAdapter.initializeVoIPParameters(data, callbackContext);
1132
1092
  }
1133
1093
 
1134
1094
  @CordovaMethod
1135
1095
  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;
1143
- }
1096
+ return callsAdapter.mute();
1144
1097
  }
1145
1098
 
1146
1099
  @CordovaMethod
1147
1100
  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
- }
1101
+ return callsAdapter.unmute();
1156
1102
  }
1157
1103
 
1158
1104
  @CordovaMethod
1159
1105
  private boolean speakerOn() {
1160
- try {
1161
- AudioManager audioManager = (AudioManager) this.cordova.getActivity().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
1162
- audioManager.setSpeakerphoneOn(true);
1163
- return true;
1164
- } catch (Exception e) {
1165
- PWLog.error("Failed to turn speaker on");
1166
- return false;
1167
- }
1106
+ return callsAdapter.speakerOn();
1168
1107
  }
1169
1108
 
1170
1109
  @CordovaMethod
1171
1110
  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
- }
1111
+ return callsAdapter.speakerOff();
1180
1112
  }
1181
1113
 
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
- }
1114
+ public static void emitVoipEvent(@NonNull String type, @NonNull JSONObject payload) {
1115
+ ArrayList<CallbackContext> callbackContexts = getCallbackContexts().get(type);
1116
+ if (callbackContexts == null) return;
1224
1117
 
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");
1118
+ for (final CallbackContext callbackContext : callbackContexts) {
1119
+ getCordovaInterface().getThreadPool().execute(() -> {
1120
+ PluginResult result = new PluginResult(PluginResult.Status.OK, payload);
1121
+ result.setKeepCallback(true);
1122
+ callbackContext.sendPluginResult(result);
1123
+ });
1266
1124
  }
1267
- return payload;
1268
1125
  }
1269
1126
 
1270
1127
  private static JSONObject inboxMessageToJson(InboxMessage message) {
@@ -1,4 +1,4 @@
1
- package com.pushwoosh.plugin.pushnotifications;
1
+ package com.pushwoosh.plugin.pushnotifications.calls;
2
2
 
3
3
  import android.os.Bundle;
4
4
 
@@ -7,6 +7,7 @@ import androidx.annotation.Nullable;
7
7
 
8
8
  import com.pushwoosh.calls.PushwooshVoIPMessage;
9
9
  import com.pushwoosh.calls.listener.CallEventListener;
10
+ import com.pushwoosh.plugin.pushnotifications.PushNotifications;
10
11
 
11
12
  public class PWCordovaCallEventListener implements CallEventListener {
12
13
  private static final Object sCurrentCallLock = new Object();
@@ -18,12 +19,12 @@ public class PWCordovaCallEventListener implements CallEventListener {
18
19
  synchronized (sCurrentCallLock) {
19
20
  currentCallInfo = pushwooshVoIPMessage.getRawPayload();
20
21
  }
21
- PushNotifications.onAnswer(pushwooshVoIPMessage);
22
+ PushwooshCallsAdapter.onAnswer(pushwooshVoIPMessage);
22
23
  }
23
24
 
24
25
  @Override
25
26
  public void onReject(@NonNull PushwooshVoIPMessage pushwooshVoIPMessage) {
26
- PushNotifications.onReject(pushwooshVoIPMessage);
27
+ PushwooshCallsAdapter.onReject(pushwooshVoIPMessage);
27
28
  synchronized (sCurrentCallLock) {
28
29
  currentCallInfo = null;
29
30
  }
@@ -31,7 +32,7 @@ public class PWCordovaCallEventListener implements CallEventListener {
31
32
 
32
33
  @Override
33
34
  public void onDisconnect(@NonNull PushwooshVoIPMessage pushwooshVoIPMessage) {
34
- PushNotifications.onDisconnect(pushwooshVoIPMessage);
35
+ PushwooshCallsAdapter.onDisconnect(pushwooshVoIPMessage);
35
36
  synchronized (sCurrentCallLock) {
36
37
  currentCallInfo = null;
37
38
  }
@@ -42,7 +43,7 @@ public class PWCordovaCallEventListener implements CallEventListener {
42
43
  synchronized (sCurrentCallLock) {
43
44
  currentCallInfo = bundle;
44
45
  }
45
- PushNotifications.onCreateIncomingConnection(bundle);
46
+ PushwooshCallsAdapter.onCreateIncomingConnection(bundle);
46
47
  }
47
48
 
48
49
  @Override
@@ -0,0 +1,167 @@
1
+ package com.pushwoosh.plugin.pushnotifications.calls;
2
+
3
+ import static com.pushwoosh.plugin.pushnotifications.PushNotifications.getCallbackContextMap;
4
+ import static com.pushwoosh.plugin.pushnotifications.PushNotifications.getCordovaInterface;
5
+
6
+ import android.content.Context;
7
+ import android.content.Intent;
8
+ import android.media.AudioManager;
9
+ import android.os.Bundle;
10
+
11
+ import com.pushwoosh.Pushwoosh;
12
+ import com.pushwoosh.calls.PushwooshCallReceiver;
13
+ import com.pushwoosh.calls.PushwooshCallSettings;
14
+ import com.pushwoosh.calls.PushwooshVoIPMessage;
15
+ import com.pushwoosh.internal.platform.AndroidPlatformModule;
16
+ import com.pushwoosh.internal.utils.JsonUtils;
17
+ import com.pushwoosh.internal.utils.PWLog;
18
+ import com.pushwoosh.plugin.pushnotifications.CallsAdapter;
19
+ import com.pushwoosh.plugin.pushnotifications.PushNotifications;
20
+
21
+ import org.apache.cordova.CallbackContext;
22
+ import org.json.JSONArray;
23
+ import org.json.JSONException;
24
+
25
+ import java.util.ArrayList;
26
+
27
+ public class PushwooshCallsAdapter implements CallsAdapter {
28
+ public static final String TAG = "PushwooshCallsAdapter";
29
+
30
+ @Override
31
+ public boolean setVoipAppCode(JSONArray data, CallbackContext callbackContext) {
32
+ try {
33
+ String appCode = data.getString(0);
34
+ Pushwoosh.getInstance().addAlternativeAppCode(appCode);
35
+ } catch (JSONException e) {
36
+ PWLog.error(TAG, "No parameters passed (missing parameters)", e);
37
+ return false;
38
+ }
39
+ return true;
40
+ }
41
+
42
+ @Override
43
+ public boolean requestCallPermission(JSONArray data, CallbackContext callbackContext) {
44
+ try {
45
+ PushwooshCallSettings.requestCallPermissions();
46
+ } catch (Exception e) {
47
+ PWLog.error(TAG, "Failed to request call permissions: " + e.getMessage());
48
+ return false;
49
+ }
50
+ return true;
51
+ }
52
+
53
+ @Override
54
+ public boolean registerEvent(JSONArray data, CallbackContext callbackContext) {
55
+ try {
56
+
57
+ String eventType = data.getString(0);
58
+ ArrayList<CallbackContext> callbackContextList = getCallbackContextMap().get(eventType);
59
+ if (callbackContextList != null) {
60
+ callbackContextList.add(callbackContext);
61
+ }
62
+ return true;
63
+ } catch (Exception e) {
64
+
65
+ return false;
66
+ }
67
+ }
68
+
69
+ @Override
70
+ public boolean endCall(JSONArray data, CallbackContext callbackContext) {
71
+ Context context = AndroidPlatformModule.getApplicationContext();
72
+ Intent endCallIntent = new Intent(context, PushwooshCallReceiver.class);
73
+ endCallIntent.putExtras(PWCordovaCallEventListener.getCurrentCallInfo());
74
+ endCallIntent.setAction("ACTION_END_CALL");
75
+ getCordovaInterface().getActivity().getApplicationContext().sendBroadcast(endCallIntent);
76
+
77
+ return true;
78
+ }
79
+
80
+ @Override
81
+ public boolean initializeVoIPParameters(JSONArray data, CallbackContext callbackContext) {
82
+ try {
83
+ String callSound = data.getString(1);
84
+ if (callSound!= null && !callSound.isEmpty()){
85
+ PushwooshCallSettings.setCallSound(callSound);
86
+ }
87
+ return true;
88
+ } catch (Exception e) {
89
+ PWLog.error("Failed to fetch custom sound name");
90
+ return false;
91
+ }
92
+ }
93
+
94
+ @Override
95
+ public boolean mute() {
96
+ try {
97
+ AudioManager audioManager = (AudioManager) getCordovaInterface().getActivity().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
98
+ audioManager.setMicrophoneMute(true);
99
+ return true;
100
+ } catch (Exception e) {
101
+ PWLog.error("Failed to mute audio channel");
102
+ return false;
103
+ }
104
+ }
105
+
106
+ @Override
107
+ public boolean unmute() {
108
+ try {
109
+ AudioManager audioManager = (AudioManager) getCordovaInterface().getActivity().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
110
+ audioManager.setMicrophoneMute(false);
111
+ return true;
112
+ } catch (Exception e) {
113
+ PWLog.error("Failed to unmute audio channel");
114
+ return false;
115
+ }
116
+ }
117
+
118
+ @Override
119
+ public boolean speakerOn() {
120
+ try {
121
+ AudioManager audioManager = (AudioManager) getCordovaInterface().getActivity().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
122
+ audioManager.setSpeakerphoneOn(true);
123
+ return true;
124
+ } catch (Exception e) {
125
+ PWLog.error("Failed to turn speaker on");
126
+ return false;
127
+ }
128
+ }
129
+
130
+ @Override
131
+ public boolean speakerOff() {
132
+ try {
133
+ AudioManager audioManager = (AudioManager) getCordovaInterface().getActivity().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
134
+ audioManager.setSpeakerphoneOn(false);
135
+ return true;
136
+ } catch (Exception e) {
137
+ PWLog.error("Failed to turn speaker off");
138
+ return false;
139
+ }
140
+ }
141
+
142
+ public static void onAnswer(PushwooshVoIPMessage voIPMessage) {
143
+ PushNotifications.emitVoipEvent("answer", parseVoIPMessage(voIPMessage));
144
+ }
145
+
146
+ public static void onReject(PushwooshVoIPMessage voIPMessage) {
147
+ PushNotifications.emitVoipEvent("reject", parseVoIPMessage(voIPMessage));
148
+ }
149
+
150
+ public static void onDisconnect(PushwooshVoIPMessage voIPMessage) {
151
+ PushNotifications.emitVoipEvent("hangup", parseVoIPMessage(voIPMessage));
152
+ }
153
+
154
+ public static void onCreateIncomingConnection(Bundle bundle) {
155
+ PushNotifications.emitVoipEvent("voipPushPayload", JsonUtils.bundleToJson(bundle));
156
+ }
157
+
158
+ private static org.json.JSONObject parseVoIPMessage(PushwooshVoIPMessage message) {
159
+ org.json.JSONObject payload = new org.json.JSONObject();
160
+ try {
161
+ payload.put("callerName", message.getCallerName())
162
+ .put("rawPayload", message.getRawPayload())
163
+ .put("hasVideo", message.getHasVideo());
164
+ } catch (org.json.JSONException ignored) {}
165
+ return payload;
166
+ }
167
+ }
@@ -693,7 +693,6 @@ API_AVAILABLE(ios(10.0)) {
693
693
  NSNumber *handleTypesNumber = [command.arguments objectAtIndex:2];
694
694
 
695
695
  if ([supportsVideoNumber isKindOfClass:[NSNumber class]] &&
696
- [ringtoneSound isKindOfClass:[NSString class]] && ringtoneSound.length > 0 &&
697
696
  [handleTypesNumber isKindOfClass:[NSNumber class]]) {
698
697
 
699
698
  BOOL supportsVideo = [supportsVideoNumber boolValue];
@@ -706,7 +705,7 @@ API_AVAILABLE(ios(10.0)) {
706
705
 
707
706
  pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"VoIP Parameters Initialized"];
708
707
  } else {
709
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid Parameters"];
708
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid initialization parameters"];
710
709
  }
711
710
 
712
711
  [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];