pushwoosh-cordova-plugin 8.3.42 → 8.3.44

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.44
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.44
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.44",
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.44">
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" />
@@ -40,7 +42,7 @@
40
42
 
41
43
  <meta-data android:name="com.pushwoosh.internal.plugin_provider" android:value="com.pushwoosh.plugin.internal.PhonegapPluginProvider" />
42
44
 
43
- <meta-data android:name="com.pushwoosh.CALL_EVENT_LISTENER" android:value="com.pushwoosh.plugin.pushnotifications.PWCordovaCallEventListener" />
45
+ <meta-data android:name="com.pushwoosh.CALL_EVENT_LISTENER" android:value="com.pushwoosh.plugin.pushnotifications.calls.PWCordovaCallEventListener" />
44
46
 
45
47
  <service android:name="com.pushwoosh.plugin.pushnotifications.CustomFirebaseMessagingService" android:exported="false">
46
48
  <intent-filter>
@@ -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.33"/>
99
+ <framework src="com.pushwoosh:pushwoosh-amazon:6.7.33"/>
100
+ <framework src="com.pushwoosh:pushwoosh-firebase:6.7.33"/>
101
+ <framework src="com.pushwoosh:pushwoosh-badge:6.7.33"/>
102
+ <framework src="com.pushwoosh:pushwoosh-inbox:6.7.33"/>
103
+ <framework src="com.pushwoosh:pushwoosh-inbox-ui:6.7.33"/>
104
+ <framework src="com.pushwoosh:pushwoosh-huawei:6.7.33"/>
94
105
  </platform>
95
106
 
96
107
  <!-- ios -->
@@ -132,7 +143,7 @@
132
143
  <source url="https://github.com/CocoaPods/Specs.git"/>
133
144
  </config>
134
145
  <pods use-frameworks="true">
135
- <pod name="PushwooshXCFramework" spec="6.10.2" />
146
+ <pod name="PushwooshXCFramework" spec="6.10.5" />
136
147
  <pod name="PushwooshInboxUIXCFramework" spec="6.1.2" />
137
148
  </pods>
138
149
  </podspec>
@@ -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.33" }
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,18 @@
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 getCallPermissionStatus(JSONArray data, final CallbackContext callbackContext);
10
+ public boolean registerEvent(JSONArray data, final CallbackContext callbackContext);
11
+ public boolean unregisterEvent(JSONArray data, final CallbackContext callbackContext);
12
+ public boolean endCall(JSONArray data, final CallbackContext callbackContext);
13
+ public boolean initializeVoIPParameters(JSONArray data, final CallbackContext callbackContext);
14
+ public boolean mute();
15
+ public boolean unmute();
16
+ public boolean speakerOn();
17
+ public boolean speakerOff();
18
+ }
@@ -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,75 @@
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 getCallPermissionStatus(JSONArray data, CallbackContext callbackContext) {
24
+ PWLog.error(TAG,"Method not implemented");
25
+ return false;
26
+ }
27
+
28
+ @Override
29
+ public boolean registerEvent(JSONArray data, CallbackContext callbackContext) {
30
+ PWLog.error(TAG,"Method not implemented");
31
+ return false;
32
+ }
33
+
34
+ @Override
35
+ public boolean unregisterEvent(JSONArray data, CallbackContext callbackContext) {
36
+ PWLog.error(TAG,"Method not implemented");
37
+ return false;
38
+ }
39
+
40
+ @Override
41
+ public boolean endCall(JSONArray data, CallbackContext callbackContext) {
42
+ PWLog.error(TAG,"Method not implemented");
43
+ return false;
44
+ }
45
+
46
+ @Override
47
+ public boolean initializeVoIPParameters(JSONArray data, CallbackContext callbackContext) {
48
+ PWLog.error(TAG,"Method not implemented");
49
+ return false;
50
+ }
51
+
52
+ @Override
53
+ public boolean mute() {
54
+ PWLog.error(TAG,"Method not implemented");
55
+ return false;
56
+ }
57
+
58
+ @Override
59
+ public boolean unmute() {
60
+ PWLog.error(TAG,"Method not implemented");
61
+ return false;
62
+ }
63
+
64
+ @Override
65
+ public boolean speakerOn() {
66
+ PWLog.error(TAG,"Method not implemented");
67
+ return false;
68
+ }
69
+
70
+ @Override
71
+ public boolean speakerOff() {
72
+ PWLog.error(TAG,"Method not implemented");
73
+ return false;
74
+ }
75
+ }
@@ -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,70 @@ 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
- private boolean registerEvent(JSONArray data, final CallbackContext callbackContext) {
1095
- try {
1080
+ private boolean getCallPermissionStatus(JSONArray data, final CallbackContext callbackContext) {
1081
+ return callsAdapter.getCallPermissionStatus(data, callbackContext);
1082
+ }
1096
1083
 
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) {
1084
+ @CordovaMethod
1085
+ private boolean registerEvent(JSONArray data, final CallbackContext callbackContext) {
1086
+ return callsAdapter.registerEvent(data, callbackContext);
1087
+ }
1104
1088
 
1105
- return false;
1106
- }
1089
+ @CordovaMethod
1090
+ private boolean unregisterEvent(JSONArray data, final CallbackContext callbackContext) {
1091
+ return callsAdapter.unregisterEvent(data, callbackContext);
1107
1092
  }
1108
1093
 
1109
1094
  @CordovaMethod
1110
1095
  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;
1096
+ return callsAdapter.endCall(data,callbackContext);
1118
1097
  }
1119
1098
 
1120
1099
  @CordovaMethod
1121
1100
  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
- }
1101
+ return callsAdapter.initializeVoIPParameters(data, callbackContext);
1132
1102
  }
1133
1103
 
1134
1104
  @CordovaMethod
1135
1105
  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
- }
1106
+ return callsAdapter.mute();
1144
1107
  }
1145
1108
 
1146
1109
  @CordovaMethod
1147
1110
  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
- }
1111
+ return callsAdapter.unmute();
1156
1112
  }
1157
1113
 
1158
1114
  @CordovaMethod
1159
1115
  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
- }
1116
+ return callsAdapter.speakerOn();
1168
1117
  }
1169
1118
 
1170
1119
  @CordovaMethod
1171
1120
  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
- }
1121
+ return callsAdapter.speakerOff();
1180
1122
  }
1181
1123
 
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
- }
1124
+ public static void emitVoipEvent(@NonNull String type, @NonNull JSONObject payload) {
1125
+ ArrayList<CallbackContext> callbackContexts = getCallbackContexts().get(type);
1126
+ if (callbackContexts == null) return;
1257
1127
 
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");
1128
+ for (final CallbackContext callbackContext : callbackContexts) {
1129
+ getCordovaInterface().getThreadPool().execute(() -> {
1130
+ PluginResult result = new PluginResult(PluginResult.Status.OK, payload);
1131
+ result.setKeepCallback(true);
1132
+ callbackContext.sendPluginResult(result);
1133
+ });
1266
1134
  }
1267
- return payload;
1268
1135
  }
1269
1136
 
1270
1137
  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,196 @@
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 getCallPermissionStatus(JSONArray data, CallbackContext callbackContext) {
55
+ try {
56
+ int status = PushwooshCallSettings.getCallPermissionStatus();
57
+ callbackContext.success(status);
58
+ return true;
59
+ } catch (Exception e) {
60
+ PWLog.error(TAG, "Failed to get call permission status: " + e.getMessage());
61
+ return false;
62
+ }
63
+ }
64
+
65
+ @Override
66
+ public boolean registerEvent(JSONArray data, CallbackContext callbackContext) {
67
+ try {
68
+
69
+ String eventType = data.getString(0);
70
+ ArrayList<CallbackContext> callbackContextList = getCallbackContextMap().get(eventType);
71
+ if (callbackContextList != null) {
72
+ callbackContextList.add(callbackContext);
73
+ }
74
+ return true;
75
+ } catch (Exception e) {
76
+ return false;
77
+ }
78
+ }
79
+
80
+ @Override
81
+ public boolean unregisterEvent(JSONArray data, CallbackContext callbackContext) {
82
+ try {
83
+ String eventType = data.getString(0);
84
+ ArrayList<CallbackContext> callbackContextList = getCallbackContextMap().get(eventType);
85
+ if (callbackContextList != null) {
86
+ callbackContextList.clear();
87
+ callbackContext.success("Successfully unregistered from " + eventType + " event");
88
+ } else {
89
+ callbackContext.error("Event " + eventType + " not found or not supported");
90
+ }
91
+ return true;
92
+ } catch (Exception e) {
93
+ PWLog.error(TAG, "Failed to unregister event: " + e.getMessage());
94
+ return false;
95
+ }
96
+ }
97
+
98
+ @Override
99
+ public boolean endCall(JSONArray data, CallbackContext callbackContext) {
100
+ Context context = AndroidPlatformModule.getApplicationContext();
101
+ Intent endCallIntent = new Intent(context, PushwooshCallReceiver.class);
102
+ endCallIntent.putExtras(PWCordovaCallEventListener.getCurrentCallInfo());
103
+ endCallIntent.setAction("ACTION_END_CALL");
104
+ getCordovaInterface().getActivity().getApplicationContext().sendBroadcast(endCallIntent);
105
+
106
+ return true;
107
+ }
108
+
109
+ @Override
110
+ public boolean initializeVoIPParameters(JSONArray data, CallbackContext callbackContext) {
111
+ try {
112
+ String callSound = data.getString(1);
113
+ if (callSound!= null && !callSound.isEmpty()){
114
+ PushwooshCallSettings.setCallSound(callSound);
115
+ }
116
+ return true;
117
+ } catch (Exception e) {
118
+ PWLog.error("Failed to fetch custom sound name");
119
+ return false;
120
+ }
121
+ }
122
+
123
+ @Override
124
+ public boolean mute() {
125
+ try {
126
+ AudioManager audioManager = (AudioManager) getCordovaInterface().getActivity().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
127
+ audioManager.setMicrophoneMute(true);
128
+ return true;
129
+ } catch (Exception e) {
130
+ PWLog.error("Failed to mute audio channel");
131
+ return false;
132
+ }
133
+ }
134
+
135
+ @Override
136
+ public boolean unmute() {
137
+ try {
138
+ AudioManager audioManager = (AudioManager) getCordovaInterface().getActivity().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
139
+ audioManager.setMicrophoneMute(false);
140
+ return true;
141
+ } catch (Exception e) {
142
+ PWLog.error("Failed to unmute audio channel");
143
+ return false;
144
+ }
145
+ }
146
+
147
+ @Override
148
+ public boolean speakerOn() {
149
+ try {
150
+ AudioManager audioManager = (AudioManager) getCordovaInterface().getActivity().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
151
+ audioManager.setSpeakerphoneOn(true);
152
+ return true;
153
+ } catch (Exception e) {
154
+ PWLog.error("Failed to turn speaker on");
155
+ return false;
156
+ }
157
+ }
158
+
159
+ @Override
160
+ public boolean speakerOff() {
161
+ try {
162
+ AudioManager audioManager = (AudioManager) getCordovaInterface().getActivity().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
163
+ audioManager.setSpeakerphoneOn(false);
164
+ return true;
165
+ } catch (Exception e) {
166
+ PWLog.error("Failed to turn speaker off");
167
+ return false;
168
+ }
169
+ }
170
+
171
+ public static void onAnswer(PushwooshVoIPMessage voIPMessage) {
172
+ PushNotifications.emitVoipEvent("answer", parseVoIPMessage(voIPMessage));
173
+ }
174
+
175
+ public static void onReject(PushwooshVoIPMessage voIPMessage) {
176
+ PushNotifications.emitVoipEvent("reject", parseVoIPMessage(voIPMessage));
177
+ }
178
+
179
+ public static void onDisconnect(PushwooshVoIPMessage voIPMessage) {
180
+ PushNotifications.emitVoipEvent("hangup", parseVoIPMessage(voIPMessage));
181
+ }
182
+
183
+ public static void onCreateIncomingConnection(Bundle bundle) {
184
+ PushNotifications.emitVoipEvent("voipPushPayload", JsonUtils.bundleToJson(bundle));
185
+ }
186
+
187
+ private static org.json.JSONObject parseVoIPMessage(PushwooshVoIPMessage message) {
188
+ org.json.JSONObject payload = new org.json.JSONObject();
189
+ try {
190
+ payload.put("callerName", message.getCallerName())
191
+ .put("rawPayload", message.getRawPayload())
192
+ .put("hasVideo", message.getHasVideo());
193
+ } catch (org.json.JSONException ignored) {}
194
+ return payload;
195
+ }
196
+ }
@@ -13,7 +13,6 @@
13
13
  #import "PushNotification.h"
14
14
  #import "PWLog.h"
15
15
  #import <PushwooshInboxUI/PushwooshInboxUI.h>
16
- #import <PushwooshFramework/PWGDPRManager.h>
17
16
  #import <PushwooshFramework/PWInAppManager.h>
18
17
  #import <PushwooshFramework/PushNotificationManager.h>
19
18
  #import <PushwooshFramework/PWInbox.h>
@@ -37,6 +36,8 @@
37
36
 
38
37
 
39
38
  #define WRITEJS(VAL) [NSString stringWithFormat:@"setTimeout(function() { %@; }, 0);", VAL]
39
+ #define PW_COMMUNICATION_ENABLED_KEY @"PushwooshCommunicationEnabled"
40
+ #define PW_COMMUNICATION_ENABLED_PLIST_KEY @"Pushwoosh_ALLOW_SERVER_COMMUNICATION"
40
41
 
41
42
  NSMutableDictionary *callbackIds;
42
43
  NSDictionary* pendingCallFromRecents;
@@ -120,6 +121,7 @@ API_AVAILABLE(ios(10))
120
121
  - (void)pluginInitialize {
121
122
  [super pluginInitialize];
122
123
  pw_PushNotificationPlugin = self;
124
+
123
125
  #if PW_VOIP_ENABLED
124
126
  callbackIds = [[NSMutableDictionary alloc] initWithCapacity:5];
125
127
  [callbackIds setObject:[NSMutableArray array] forKey:@"initializeVoIPParameters"];
@@ -135,6 +137,8 @@ API_AVAILABLE(ios(10))
135
137
  [callbackIds setObject:[NSMutableArray array] forKey:@"speakerOn"];
136
138
  [callbackIds setObject:[NSMutableArray array] forKey:@"speakerOff"];
137
139
  [callbackIds setObject:[NSMutableArray array] forKey:@"playDTMF"];
140
+ [callbackIds setObject:[NSMutableArray array] forKey:@"voipDidFailToRegisterTokenWithError"];
141
+ [callbackIds setObject:[NSMutableArray array] forKey:@"voipDidRegisterTokenSuccessfully"];
138
142
 
139
143
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveCallFromRecents:) name:@"RecentsCallNotification" object:nil];
140
144
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAudioRouteChange:) name:AVAudioSessionRouteChangeNotification object:nil];
@@ -627,6 +631,10 @@ API_AVAILABLE(ios(10.0)) {
627
631
  //stub, android only
628
632
  }
629
633
 
634
+ - (void)getCallPermissionStatus:(CDVInvokedUrlCommand *)command {
635
+ //stub, android only
636
+ }
637
+
630
638
  - (void)setVoipAppCode:(CDVInvokedUrlCommand *)command {
631
639
  NSString *voipAppCode = command.arguments[0];
632
640
  [PushwooshVoIPImplementation setPushwooshVoIPAppId:voipAppCode];
@@ -693,7 +701,6 @@ API_AVAILABLE(ios(10.0)) {
693
701
  NSNumber *handleTypesNumber = [command.arguments objectAtIndex:2];
694
702
 
695
703
  if ([supportsVideoNumber isKindOfClass:[NSNumber class]] &&
696
- [ringtoneSound isKindOfClass:[NSString class]] && ringtoneSound.length > 0 &&
697
704
  [handleTypesNumber isKindOfClass:[NSNumber class]]) {
698
705
 
699
706
  BOOL supportsVideo = [supportsVideoNumber boolValue];
@@ -706,7 +713,7 @@ API_AVAILABLE(ios(10.0)) {
706
713
 
707
714
  pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"VoIP Parameters Initialized"];
708
715
  } else {
709
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid Parameters"];
716
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid initialization parameters"];
710
717
  }
711
718
 
712
719
  [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
@@ -759,6 +766,21 @@ API_AVAILABLE(ios(10.0)) {
759
766
  }
760
767
  }
761
768
 
769
+ // MARK: - Unregister event func
770
+ - (void)unregisterEvent:(CDVInvokedUrlCommand*)command {
771
+ NSString* eventName = [command.arguments objectAtIndex:0];
772
+
773
+ if(callbackIds[eventName] != nil) {
774
+ [callbackIds[eventName] removeAllObjects];
775
+
776
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[NSString stringWithFormat:@"Successfully unregistered from %@ event", eventName]];
777
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
778
+ } else {
779
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[NSString stringWithFormat:@"Event %@ not found or not supported", eventName]];
780
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
781
+ }
782
+ }
783
+
762
784
  // MARK: - Send Call
763
785
  - (void)sendCall:(CDVInvokedUrlCommand*)command {
764
786
  BOOL hasId = ![[command.arguments objectAtIndex:1] isEqual:[NSNull null]];
@@ -850,6 +872,34 @@ API_AVAILABLE(ios(10.0)) {
850
872
  }
851
873
  }
852
874
 
875
+ // MARK: - voipDidFailToRegisterTokenWithError callback
876
+ - (void)voipDidFailToRegisterTokenWithError:(NSError *)error {
877
+ for (id callbackId in callbackIds[@"voipDidFailToRegisterTokenWithError"]) {
878
+ CDVPluginResult* pluginResult = nil;
879
+ NSDictionary *errorData = @{
880
+ @"error": error.localizedDescription ?: @"Unknown error",
881
+ @"code": @(error.code),
882
+ @"domain": error.domain ?: @"Unknown domain"
883
+ };
884
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorData];
885
+ [pluginResult setKeepCallbackAsBool:YES];
886
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
887
+ }
888
+ }
889
+
890
+ // MARK: - voipDidRegisterTokenSuccessfully callback
891
+ - (void)voipDidRegisterTokenSuccessfully {
892
+ for (id callbackId in callbackIds[@"voipDidRegisterTokenSuccessfully"]) {
893
+ CDVPluginResult* pluginResult = nil;
894
+ NSDictionary *successData = @{
895
+ @"message": @"VoIP token registered successfully"
896
+ };
897
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successData];
898
+ [pluginResult setKeepCallbackAsBool:YES];
899
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
900
+ }
901
+ }
902
+
853
903
  // MARK: - Answer Call
854
904
  - (void)answerCall:(CXProvider *)provider perform:(CXAnswerCallAction *)action voipMessage:(PWVoIPMessage *)voipMessage {
855
905
  [self setupAudioSession];
@@ -1043,22 +1093,49 @@ API_AVAILABLE(ios(10.0)) {
1043
1093
  [[PWInAppManager sharedManager] addJavascriptInterface:bridge withName:name];
1044
1094
  }
1045
1095
 
1046
- - (void)setCommunicationEnabled:(CDVInvokedUrlCommand *)command {
1047
- self.callbackIds[@"setCommunicationEnabled"] = command.callbackId;
1096
+ - (BOOL)getCommunicationEnabledState {
1097
+ NSBundle *bundle = [NSBundle mainBundle];
1098
+ NSObject *plistValue = [bundle objectForInfoDictionaryKey:PW_COMMUNICATION_ENABLED_PLIST_KEY];
1048
1099
 
1049
- NSNumber *enabledObject = [command.arguments firstObject];
1100
+ if (plistValue != nil) {
1101
+ if ([plistValue isKindOfClass:[NSNumber class]]) {
1102
+ return [(NSNumber *)plistValue boolValue];
1103
+ } else if ([plistValue isKindOfClass:[NSString class]]) {
1104
+ NSString *stringValue = [(NSString *)plistValue lowercaseString];
1105
+ return [stringValue isEqualToString:@"true"] || [stringValue isEqualToString:@"yes"] || [stringValue isEqualToString:@"1"];
1106
+ }
1107
+ }
1108
+
1109
+ if ([[NSUserDefaults standardUserDefaults] objectForKey:PW_COMMUNICATION_ENABLED_KEY] != nil) {
1110
+ return [[NSUserDefaults standardUserDefaults] boolForKey:PW_COMMUNICATION_ENABLED_KEY];
1111
+ }
1050
1112
 
1113
+ return YES;
1114
+ }
1115
+
1116
+ - (void)setCommunicationEnabled:(CDVInvokedUrlCommand *)command {
1117
+ NSNumber *enabledObject = [command.arguments firstObject];
1051
1118
  BOOL enabled = [enabledObject boolValue];
1052
1119
 
1053
- [[PWGDPRManager sharedManager] setCommunicationEnabled:enabled completion:^(NSError *error) {
1054
- if (!error) {
1055
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1056
- [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackIds[@"setCommunicationEnabled"]];
1057
- } else {
1058
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error.localizedDescription];
1059
- [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackIds[@"setCommunicationEnabled"]];
1060
- }
1061
- }];
1120
+ [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:PW_COMMUNICATION_ENABLED_KEY];
1121
+
1122
+ CDVPluginResult *pluginResult = nil;
1123
+
1124
+ if (enabled) {
1125
+ [[Pushwoosh sharedInstance] startServerCommunication];
1126
+ } else {
1127
+ [[Pushwoosh sharedInstance] stopServerCommunication];
1128
+ }
1129
+
1130
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1131
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
1132
+ }
1133
+
1134
+ - (void)isCommunicationEnabled:(CDVInvokedUrlCommand *)command {
1135
+ BOOL isEnabled = [self getCommunicationEnabledState];
1136
+
1137
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:(isEnabled ? 1 : 0)];
1138
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
1062
1139
  }
1063
1140
 
1064
1141
  - (void)setEmail:(CDVInvokedUrlCommand *)command {
@@ -1119,11 +1196,6 @@ API_AVAILABLE(ios(10.0)) {
1119
1196
  [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
1120
1197
  }
1121
1198
 
1122
- - (void)isCommunicationEnabled:(CDVInvokedUrlCommand *)command {
1123
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:[[PWGDPRManager sharedManager] isCommunicationEnabled]];
1124
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
1125
- }
1126
-
1127
1199
  - (void)enableHuaweiPushNotifications:(CDVInvokedUrlCommand *)command {
1128
1200
  // Stub
1129
1201
 
@@ -96,5 +96,6 @@ export interface PushNotification {
96
96
  mute(success?: () => void, error?: (err: Error | string) => void): void;
97
97
  unmute(success?: () => void, error?: (err: Error | string) => void): void;
98
98
  requestCallPermission(): void;
99
+ getCallPermissionStatus(success?: (status: number) => void, error?: (err: Error | string) => void): void;
99
100
  endCall(success?: () => void, error?: (err: Error | string) => void): void;
100
101
  }
@@ -504,6 +504,8 @@ PushNotification.prototype.notificationCallback = function(notification) {
504
504
  * - "incomingCallSuccess": Triggered when an incoming call is successfully displayed.
505
505
  * - "incomingCallFailure": Triggered when displaying the incoming call fails.
506
506
  * - "playDTMF": Triggered when a DTMF tone is played.
507
+ * - "voipDidFailToRegisterTokenWithError": Triggered when VoIP token registration fails (iOS only).
508
+ * - "voipDidRegisterTokenSuccessfully": Triggered when VoIP token registration succeeds (iOS only).
507
509
  *
508
510
  * @param {Function} success - Callback function to be invoked when the event occurs.
509
511
  * @param {Function} fail - Callback function to be invoked if the registration fails.
@@ -512,6 +514,34 @@ PushNotification.prototype.registerEvent = function(eventName, success, fail) {
512
514
  exec(success, fail, "PushNotification", "registerEvent", [eventName]);
513
515
  };
514
516
 
517
+ /**
518
+ * Unregisters a callback for a specific VoIP-related event.
519
+ *
520
+ * This method allows you to unsubscribe from a previously registered VoIP event.
521
+ * After unregistering, the event callback will no longer be invoked when the event occurs.
522
+ *
523
+ * @param {string} eventName - The name of the event to unregister from.
524
+ * This should match the event name used in registerEvent().
525
+ * Supported event names include:
526
+ * - "answer": Triggered when the call is answered.
527
+ * - "hangup": Triggered when the call is hung up.
528
+ * - "reject": Triggered when the call is rejected.
529
+ * - "muted": Triggered when the call is muted or unmuted.
530
+ * - "held": Triggered when the call is put on or off hold.
531
+ * - "voipPushPayload": Triggered when a VoIP push notification is received.
532
+ * - "incomingCallSuccess": Triggered when an incoming call is successfully displayed.
533
+ * - "incomingCallFailure": Triggered when displaying the incoming call fails.
534
+ * - "playDTMF": Triggered when a DTMF tone is played.
535
+ * - "voipDidFailToRegisterTokenWithError": Triggered when VoIP token registration fails (iOS only).
536
+ * - "voipDidRegisterTokenSuccessfully": Triggered when VoIP token registration succeeds (iOS only).
537
+ *
538
+ * @param {Function} success - Callback function to be invoked when the event is successfully unregistered.
539
+ * @param {Function} fail - Callback function to be invoked if the unregistration fails.
540
+ */
541
+ PushNotification.prototype.unregisterEvent = function(eventName, success, fail) {
542
+ exec(success, fail, "PushNotification", "unregisterEvent", [eventName]);
543
+ };
544
+
515
545
  /**
516
546
  * Initializes VoIP call parameters for the native calling system.
517
547
  *
@@ -612,6 +642,19 @@ PushNotification.prototype.requestCallPermission = function() {
612
642
  exec(null, null, "PushNotification", "requestCallPermission", []);
613
643
  }
614
644
 
645
+ /**
646
+ * Get call permission status
647
+ * Returns a Promise or calls success callback with status:
648
+ * 0 - Permission not requested yet
649
+ * 1 - Permission granted by user
650
+ * 2 - Permission denied by user
651
+ * @param {Function} success - Callback invoked with permission status
652
+ * @param {Function} error - Callback invoked if the operation fails
653
+ */
654
+ PushNotification.prototype.getCallPermissionStatus = function(success, error) {
655
+ exec(success, error, "PushNotification", "getCallPermissionStatus", []);
656
+ }
657
+
615
658
  /**
616
659
  * Notifies Pushwoosh that the call has ended
617
660
  * @param {Function} success - Callback invoked when the call ends.