@adobe/react-native-aepmessaging 1.0.0-beta.1 → 1.0.0-beta.3

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.
Files changed (52) hide show
  1. package/.babelrc +2 -2
  2. package/LICENSE +1 -1
  3. package/RCTAEPMessaging.podspec +1 -1
  4. package/README.md +280 -16
  5. package/android/build.gradle +5 -3
  6. package/android/libs/messaging.aar +0 -0
  7. package/android/libs/optimize.aar +0 -0
  8. package/android/src/main/java/com/adobe/marketing/mobile/reactnative/messaging/RCTAEPMessagingModule.java +239 -15
  9. package/android/src/main/java/com/adobe/marketing/mobile/reactnative/messaging/RCTAEPMessagingPackage.java +1 -1
  10. package/ios/src/RCTAEPMessaging.h +7 -4
  11. package/ios/src/RCTAEPMessaging.m +172 -4
  12. package/js/Messaging.d.ts +32 -0
  13. package/js/Messaging.js +69 -17
  14. package/js/Messaging.js.map +1 -0
  15. package/js/index.d.ts +5 -15
  16. package/js/index.js +12 -13
  17. package/js/index.js.map +1 -0
  18. package/js/models/Message.d.ts +43 -0
  19. package/js/models/Message.js +80 -0
  20. package/js/models/Message.js.map +1 -0
  21. package/js/models/MessagingDelegate.d.ts +25 -0
  22. package/js/models/MessagingDelegate.js +14 -0
  23. package/js/models/MessagingDelegate.js.map +1 -0
  24. package/js/models/MessagingEdgeEventType.d.ts +9 -0
  25. package/js/models/MessagingEdgeEventType.js +25 -0
  26. package/js/models/MessagingEdgeEventType.js.map +1 -0
  27. package/package.json +7 -8
  28. package/ts/Messaging.ts +99 -0
  29. package/ts/index.ts +18 -0
  30. package/ts/models/Message.ts +82 -0
  31. package/ts/models/MessagingDelegate.ts +41 -0
  32. package/ts/models/MessagingEdgeEventType.ts +22 -0
  33. package/tsconfig.json +10 -0
  34. package/.flowconfig +0 -70
  35. package/flow-typed/npm/babel-cli_vx.x.x.js +0 -108
  36. package/flow-typed/npm/babel-eslint_vx.x.x.js +0 -123
  37. package/flow-typed/npm/babel-plugin-module-resolver_vx.x.x.js +0 -81
  38. package/flow-typed/npm/babel-preset-flow_vx.x.x.js +0 -32
  39. package/flow-typed/npm/babel-preset-react-native_vx.x.x.js +0 -80
  40. package/flow-typed/npm/eslint-config-airbnb_vx.x.x.js +0 -73
  41. package/flow-typed/npm/eslint-config-prettier_vx.x.x.js +0 -66
  42. package/flow-typed/npm/eslint-import-resolver-babel-module_vx.x.x.js +0 -32
  43. package/flow-typed/npm/eslint-plugin-flowtype_vx.x.x.js +0 -424
  44. package/flow-typed/npm/eslint-plugin-import_vx.x.x.js +0 -410
  45. package/flow-typed/npm/eslint-plugin-jsx-a11y_vx.x.x.js +0 -1194
  46. package/flow-typed/npm/eslint-plugin-react-native_vx.x.x.js +0 -94
  47. package/flow-typed/npm/eslint-plugin-react_vx.x.x.js +0 -696
  48. package/flow-typed/npm/eslint_vx.x.x.js +0 -2398
  49. package/flow-typed/npm/flow-bin_v0.x.x.js +0 -6
  50. package/flow-typed/npm/flow-typed_vx.x.x.js +0 -193
  51. package/flow-typed/npm/react-native_vx.x.x.js +0 -4288
  52. package/flow-typed/npm-custom/react-native.js +0 -3
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2021 Adobe. All rights reserved.
2
+ Copyright 2022 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -10,28 +10,252 @@
10
10
  */
11
11
  package com.adobe.marketing.mobile.reactnative.messaging;
12
12
 
13
+ import com.adobe.marketing.mobile.AdobeCallback;
14
+ import com.adobe.marketing.mobile.LoggingMode;
15
+
16
+ import static com.adobe.marketing.mobile.LoggingMode.DEBUG;
17
+ import static com.adobe.marketing.mobile.LoggingMode.VERBOSE;
18
+
19
+ import android.util.Log;
20
+
21
+ import com.adobe.marketing.mobile.Message;
13
22
  import com.adobe.marketing.mobile.Messaging;
23
+ import com.adobe.marketing.mobile.MessagingEdgeEventType;
24
+ import com.adobe.marketing.mobile.MobileCore;
25
+ import com.adobe.marketing.mobile.services.ServiceProvider;
26
+ import com.adobe.marketing.mobile.services.ui.FullscreenMessage;
27
+ import com.adobe.marketing.mobile.services.ui.FullscreenMessageDelegate;
28
+ import com.facebook.react.bridge.Arguments;
14
29
  import com.facebook.react.bridge.Promise;
15
30
  import com.facebook.react.bridge.ReactApplicationContext;
16
31
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
17
32
  import com.facebook.react.bridge.ReactMethod;
33
+ import com.facebook.react.bridge.WritableMap;
34
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
35
+
36
+ import java.util.HashMap;
37
+ import java.util.Map;
38
+ import java.util.concurrent.CountDownLatch;
39
+
40
+ public final class RCTAEPMessagingModule extends ReactContextBaseJavaModule implements FullscreenMessageDelegate {
41
+
42
+ private static final String TAG = "RCTAEPMessagingModule";
43
+ private final Map<String, Message> messageCache;
44
+ private final ReactApplicationContext reactContext;
45
+ private boolean shouldSaveMessage;
46
+ private boolean shouldShowMessage;
47
+ private CountDownLatch latch = new CountDownLatch(1);
48
+
49
+ public RCTAEPMessagingModule(ReactApplicationContext reactContext) {
50
+ super(reactContext);
51
+ this.reactContext = reactContext;
52
+ this.messageCache = new HashMap<>();
53
+ this.shouldShowMessage = false;
54
+ this.shouldSaveMessage = false;
55
+ }
56
+
57
+ @Override
58
+ public String getName() {
59
+ return "AEPMessaging";
60
+ }
61
+
62
+ // Required for rn built in EventEmitter Calls.
63
+ @ReactMethod
64
+ public void addListener(String eventName) {}
65
+
66
+ @ReactMethod
67
+ public void removeListeners(Integer count) {}
68
+
69
+ @ReactMethod
70
+ public void extensionVersion(final Promise promise) {
71
+ MobileCore.log(VERBOSE, TAG, "extensionVersion is called");
72
+ promise.resolve(Messaging.extensionVersion());
73
+ }
74
+
75
+ @ReactMethod
76
+ public void refreshInAppMessages() {
77
+ MobileCore.log(VERBOSE, TAG, "refreshInAppMessages is called");
78
+ Messaging.refreshInAppMessages();
79
+ }
80
+
81
+ @ReactMethod
82
+ public void setMessagingDelegate() {
83
+ MobileCore.log(VERBOSE, TAG, "setMessagingDelegate is called");
84
+ ServiceProvider.getInstance().setMessageDelegate(this);
85
+ }
86
+
87
+ @ReactMethod
88
+ public void show(final String messageId) {
89
+ if (messageId != null && messageCache.get(messageId) != null) {
90
+ MobileCore.log(VERBOSE, TAG, String.format("show is called with message id: %s", messageId));
91
+ messageCache.get(messageId).show();
92
+ }
93
+ }
94
+
95
+ @ReactMethod
96
+ public void dismiss(final String messageId, final boolean suppressAutoTrack) {
97
+ if (messageId != null && messageCache.get(messageId) != null) {
98
+ MobileCore.log(VERBOSE, TAG, String.format("dismiss is called with message id: %s and suppressAutoTrack: %b", messageId, suppressAutoTrack));
99
+ messageCache.get(messageId).dismiss(suppressAutoTrack);
100
+ }
101
+ }
102
+
103
+ @ReactMethod
104
+ public void track(final String messageId, final String interaction, final int eventType) {
105
+ if (messageId != null && messageCache.get(messageId) != null) {
106
+ MobileCore.log(VERBOSE, TAG, String.format("track is called with message id: %s, interaction: %s and eventType: %d", messageId, interaction, eventType));
107
+ MessagingEdgeEventType edgeEventType = null;
108
+ switch (eventType) {
109
+ case 0:
110
+ edgeEventType = MessagingEdgeEventType.IN_APP_DISMISS;
111
+ break;
112
+ case 1:
113
+ edgeEventType = MessagingEdgeEventType.IN_APP_INTERACT;
114
+ break;
115
+ case 2:
116
+ edgeEventType = MessagingEdgeEventType.IN_APP_TRIGGER;
117
+ break;
118
+ case 3:
119
+ edgeEventType = MessagingEdgeEventType.IN_APP_DISPLAY;
120
+ break;
121
+ case 4:
122
+ edgeEventType = MessagingEdgeEventType.PUSH_APPLICATION_OPENED;
123
+ break;
124
+ case 5:
125
+ edgeEventType = MessagingEdgeEventType.PUSH_CUSTOM_ACTION;
126
+ break;
127
+ default:
128
+ break;
129
+ }
130
+ if (edgeEventType != null) {
131
+ messageCache.get(messageId).track(interaction, edgeEventType);
132
+ } else {
133
+ MobileCore.log(DEBUG, TAG, String.format("Unable to track interaction (%s) because edgeEventType (%d) is invalid ", interaction, eventType));
134
+ }
135
+ }
136
+ }
137
+
138
+ @ReactMethod
139
+ public void handleJavascriptMessage(final String messageId, final String messageName, final Promise promise) {
140
+ if (messageId != null && messageCache.get(messageId) != null) {
141
+ MobileCore.log(VERBOSE, TAG, String.format("handleJavascriptMessage is called with message id: %s and messageName: %s", messageId, messageName));
142
+ messageCache.get(messageId).handleJavascriptMessage(messageName, new AdobeCallback<String>() {
143
+ @Override
144
+ public void call(final String s) {
145
+ if (s != null) {
146
+ promise.resolve(s);
147
+ } else {
148
+ promise.reject("error", "error in handling javascriptMessage " + messageName);
149
+ }
150
+ }
151
+ });
152
+ }
153
+ }
154
+
155
+ @ReactMethod
156
+ public void clear(final String messageId) {
157
+ if (messageId != null) {
158
+ MobileCore.log(VERBOSE, TAG, String.format("clear is called with message id: %s", messageId));
159
+ messageCache.remove(messageId);
160
+ }
161
+ }
162
+
163
+ @ReactMethod
164
+ public void setAutoTrack(final String messageId, final boolean autoTrack) {
165
+ if (messageId != null && messageCache.get(messageId) != null) {
166
+ MobileCore.log(VERBOSE, TAG, String.format("setAutoTrack is called with message id: %s and autoTrack: %b", messageId, autoTrack));
167
+ messageCache.get(messageId).autoTrack = autoTrack;
168
+ }
169
+ }
170
+
171
+ @ReactMethod(isBlockingSynchronousMethod = true)
172
+ public void shouldShowMessage(final boolean shouldShowMessage, final boolean shouldSaveMessage) {
173
+ MobileCore.log(VERBOSE, TAG, String.format("shouldShowMessage is called with message id: %b and shouldSaveMessage: %b", shouldShowMessage, shouldSaveMessage));
174
+ this.shouldShowMessage = shouldShowMessage;
175
+ this.shouldSaveMessage = shouldSaveMessage;
176
+ latch.countDown();
177
+ }
178
+
179
+ //Messaging Delegate functions
180
+ @Override
181
+ public void onShow(final FullscreenMessage fullscreenMessage) {
182
+ MobileCore.log(VERBOSE, TAG, "onShow is called");
183
+ final Message message = (Message) fullscreenMessage.getParent();
184
+ if (message != null) {
185
+ Map<String, String> data = new HashMap<>();
186
+ data.put("id", message.id);
187
+ data.put("autoTrack", String.valueOf(message.autoTrack));
188
+ emitEvent("onShow", data);
189
+ }
190
+ }
18
191
 
19
- public class RCTAEPMessagingModule extends ReactContextBaseJavaModule {
192
+ @Override
193
+ public void onDismiss(final FullscreenMessage fullscreenMessage) {
194
+ MobileCore.log(VERBOSE, TAG, "onDismiss is called");
195
+ final Message message = (Message) fullscreenMessage.getParent();
196
+ if (message != null) {
197
+ Map<String, String> data = new HashMap<>();
198
+ data.put("id", message.id);
199
+ data.put("autoTrack", String.valueOf(message.autoTrack));
200
+ emitEvent("onDismiss", data);
201
+ }
202
+ }
20
203
 
21
- private final ReactApplicationContext reactContext;
204
+ @Override
205
+ public boolean shouldShowMessage(final FullscreenMessage fullscreenMessage) {
206
+ MobileCore.log(VERBOSE, TAG, "shouldShowMessage is called");
207
+ final Message message = (Message) fullscreenMessage.getParent();
208
+ if (message != null) {
209
+ Map<String, String> data = new HashMap<>();
210
+ data.put("id", message.id);
211
+ data.put("autoTrack", String.valueOf(message.autoTrack));
212
+ emitEvent("shouldShowMessage", data);
213
+ //Latch stops the thread until the shouldShowMessage value is received from the JS side on thread dedicated to run JS code. The function called from JS that resumes the thread is "shouldShowMessage".
214
+ MobileCore.log(VERBOSE, TAG, "shouldShowMessage: Thread is locked.");
215
+ try {
216
+ latch.await();
217
+ } catch (final InterruptedException e) {
218
+ MobileCore.log(LoggingMode.ERROR, TAG, String.format("CountDownLatch await Interrupted: (%s)", e.getLocalizedMessage()));
219
+ }
220
+ MobileCore.log(VERBOSE, TAG, "shouldShowMessage: Thread is resumed.");
221
+ if (shouldSaveMessage) {
222
+ messageCache.put(message.id, message);
223
+ }
224
+ }
225
+ return shouldShowMessage;
226
+ }
22
227
 
23
- public RCTAEPMessagingModule(ReactApplicationContext reactContext) {
24
- super(reactContext);
25
- this.reactContext = reactContext;
26
- }
228
+ @Override
229
+ public boolean overrideUrlLoad(FullscreenMessage fullscreenMessage, String s) {
230
+ MobileCore.log(VERBOSE, TAG, String.format("overrideUrlLoad is called with url: (%s)", s));
231
+ final Message message = (Message) fullscreenMessage.getParent();
232
+ if (message != null) {
233
+ Map<String, String> data = new HashMap<>();
234
+ data.put("id", message.id);
235
+ data.put("autoTrack", String.valueOf(message.autoTrack));
236
+ data.put("url", s);
237
+ emitEvent("shouldShowMessage", data);
238
+ emitEvent("urlLoaded", data);
239
+ }
240
+ return true;
241
+ }
27
242
 
28
- @Override
29
- public String getName() {
30
- return "AEPMessaging";
31
- }
243
+ @Override
244
+ public void onShowFailure() {
245
+ MobileCore.log(VERBOSE, TAG, "onShowFailure is called.");
246
+ }
32
247
 
33
- @ReactMethod
34
- public void extensionVersion(final Promise promise) {
35
- promise.resolve(Messaging.extensionVersion());
36
- }
248
+ /**
249
+ * Emits an event along with data to be handled by the Javascript
250
+ *
251
+ * @param name event name
252
+ * @param data data sent along with event
253
+ */
254
+ private void emitEvent(final String name, final Map<String, String> data) {
255
+ WritableMap eventData = Arguments.createMap();
256
+ for (final Map.Entry<String, String> entry : data.entrySet()) {
257
+ eventData.putString(entry.getKey(), entry.getValue());
258
+ }
259
+ reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(name, eventData);
260
+ }
37
261
  }
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2021 Adobe. All rights reserved.
2
+ Copyright 2022 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2021 Adobe. All rights reserved.
2
+ Copyright 2022 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -9,9 +9,12 @@
9
9
  governing permissions and limitations under the License.
10
10
  */
11
11
 
12
- #import <React/RCTBridgeModule.h>
13
- #import <Foundation/Foundation.h>
12
+ #import <React/RCTBridgeModule.h>
13
+ #import <Foundation/Foundation.h>
14
+ #import <React/RCTEventEmitter.h>
15
+ #import <React/RCTBridgeModule.h>
16
+ @import AEPServices;
14
17
 
15
- @interface RCTAEPMessaging : NSObject <RCTBridgeModule>
18
+ @interface RCTAEPMessaging : RCTEventEmitter <RCTBridgeModule, AEPMessagingDelegate>
16
19
 
17
20
  @end
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2021 Adobe. All rights reserved.
2
+ Copyright 2022 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -8,11 +8,34 @@
8
8
  OF ANY KIND, either express or implied. See the License for the specific language
9
9
  governing permissions and limitations under the License.
10
10
  */
11
-
12
11
  #import "RCTAEPMessaging.h"
13
12
  @import AEPMessaging;
13
+ @import AEPCore;
14
+
15
+ static NSString* const TAG = @"RCTAEPMessaging";
16
+
17
+ @implementation RCTAEPMessaging {
18
+ NSMutableDictionary<NSString*, AEPMessage*> * cachedMessages;
19
+ dispatch_semaphore_t semaphore;
20
+ bool shouldShowMessage;
21
+ bool hasListeners;
22
+ bool shouldSaveMessage;
23
+ }
14
24
 
15
- @implementation RCTAEPMessaging
25
+ - (instancetype) init {
26
+ self = [super init];
27
+ cachedMessages = [NSMutableDictionary dictionary];
28
+ semaphore = dispatch_semaphore_create(0);
29
+ hasListeners = false;
30
+ shouldShowMessage = true;
31
+ shouldSaveMessage = false;
32
+ return self;
33
+ }
34
+
35
+ + (BOOL)requiresMainQueueSetup
36
+ {
37
+ return NO;
38
+ }
16
39
 
17
40
  RCT_EXPORT_MODULE(AEPMessaging);
18
41
 
@@ -24,5 +47,150 @@ RCT_EXPORT_MODULE(AEPMessaging);
24
47
  RCT_EXPORT_METHOD(extensionVersion: (RCTPromiseResolveBlock) resolve rejecter:(RCTPromiseRejectBlock) reject) {
25
48
  resolve([AEPMobileMessaging extensionVersion]);
26
49
  }
50
+
51
+ RCT_EXPORT_METHOD(refreshInAppMessages) {
52
+ [AEPLog traceWithLabel:TAG message:@"refreshInAppMessages is called."];
53
+ [AEPMobileMessaging refreshInAppMessages];
54
+ }
55
+
56
+ RCT_EXPORT_METHOD(setMessagingDelegate) {
57
+ [AEPLog traceWithLabel:TAG message:@"Messaging Delegate is set."];
58
+ [AEPMobileCore setMessagingDelegate: self];
59
+ }
60
+
61
+ RCT_EXPORT_METHOD(show: (NSString *) messageId) {
62
+ [AEPLog traceWithLabel:TAG message:[NSString stringWithFormat:@"show is called with message id: %@", messageId]];
63
+ AEPMessage * message = [cachedMessages objectForKey:messageId];
64
+ if(message){
65
+ [message show];
66
+ }
67
+ }
68
+
69
+ RCT_EXPORT_METHOD(dismiss: (NSString *) messageId suppressAutoTrack: (BOOL) suppressAutoTrack) {
70
+ [AEPLog traceWithLabel:TAG message:[NSString stringWithFormat:@"dismiss is called with message id: %@ and suppressAutoTrack: %i", messageId, suppressAutoTrack]];
71
+ AEPMessage * message = [cachedMessages objectForKey:messageId];
72
+ if(message){
73
+ [message dismissSuppressingAutoTrack:suppressAutoTrack];
74
+ }
75
+ }
76
+
77
+ RCT_EXPORT_METHOD(track: (NSString *) messageId withInteraction: (NSString *) interaction eventType: (int) eventTypeValue) {
78
+ [AEPLog traceWithLabel:TAG message:[NSString stringWithFormat:@"track is called with message id: %@, withInteraction: %@ and eventType: %i", messageId, interaction, eventTypeValue]];
79
+ AEPMessage * message = [cachedMessages objectForKey:messageId];
80
+ AEPMessagingEdgeEventType messagingEdgeEventType = -1;
81
+
82
+ if(eventTypeValue == 0){
83
+ messagingEdgeEventType = AEPMessagingEdgeEventTypeInappDismiss;
84
+ } else if (eventTypeValue == 1) {
85
+ messagingEdgeEventType = AEPMessagingEdgeEventTypeInappInteract;
86
+ } else if (eventTypeValue == 2) {
87
+ messagingEdgeEventType = AEPMessagingEdgeEventTypeInappTrigger;
88
+ } else if (eventTypeValue == 3) {
89
+ messagingEdgeEventType = AEPMessagingEdgeEventTypeInappDisplay;
90
+ } else if (eventTypeValue == 4) {
91
+ messagingEdgeEventType = AEPMessagingEdgeEventTypePushApplicationOpened;
92
+ } else if (eventTypeValue == 5) {
93
+ messagingEdgeEventType = AEPMessagingEdgeEventTypePushCustomAction;
94
+ }
95
+
96
+ if(messagingEdgeEventType != -1){
97
+ [message trackInteraction:interaction withEdgeEventType:messagingEdgeEventType];
98
+ }
99
+ }
100
+
101
+ RCT_EXPORT_METHOD(handleJavascriptMessage: (NSString *) messageId
102
+ messageName: (NSString *) name resolver: (RCTPromiseResolveBlock) resolve rejector:(RCTPromiseRejectBlock) reject) {
103
+ [AEPLog traceWithLabel:TAG message:[NSString stringWithFormat:@"handleJavascriptMessage is called with message id: %@ and messageName: %@", messageId, name]];
104
+ AEPMessage * message = [cachedMessages objectForKey: messageId];
105
+ [message handleJavascriptMessage:name withHandler:^(id result) {
106
+ if(result) {
107
+ resolve(result);
108
+ } else {
109
+ reject(@"error", @"error in handleJavaScriptMessage", nil);
110
+ }
111
+ }];
112
+ }
113
+
114
+ RCT_EXPORT_METHOD(clear: (NSString *) messageId) {
115
+ [AEPLog traceWithLabel:TAG message:[NSString stringWithFormat:@"clearMessage is called with message id: %@", messageId]];
116
+ [cachedMessages removeObjectForKey:messageId];
117
+ }
118
+
119
+ RCT_EXPORT_METHOD(setAutoTrack: (NSString *) messageId autoTrack: (BOOL) autoTrack) {
120
+ [AEPLog traceWithLabel:TAG message:[NSString stringWithFormat:@"setAutoTrack called for messageId: %@ and autoTrack value: %i", messageId, autoTrack]];
121
+ AEPMessage * messageObj = [cachedMessages objectForKey:messageId];
122
+ if(messageObj) {
123
+ messageObj.autoTrack = autoTrack;
124
+ }
125
+ }
126
+
127
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(shouldShowMessage: (BOOL) shouldShowMessage shouldSaveMessage: (BOOL) saveMessage) {
128
+ [AEPLog traceWithLabel:TAG message:[NSString stringWithFormat:@"shouldShowMessage is called with values (shouldShowMessage: %i) and (shouldSaveMessage: %i)", shouldShowMessage, shouldSaveMessage]];
129
+ self->shouldShowMessage = shouldShowMessage;
130
+ self->shouldSaveMessage = saveMessage;
131
+ dispatch_semaphore_signal(semaphore);
132
+ return nil;
133
+ }
134
+
135
+ //MARK: - AEPMessagingDelegate functions.
136
+ - (void) onDismissWithMessage:(id<AEPShowable> _Nonnull) message {
137
+ AEPFullscreenMessage * fullscreenMessage = (AEPFullscreenMessage *) message;
138
+ AEPMessage * messageObj = (AEPMessage *) fullscreenMessage.settings.parent;
139
+ if(messageObj) {
140
+ [self emitEventWithName:@"onDismiss" body:@{@"id":messageObj.id, @"autoTrack":messageObj.autoTrack ? @"true" : @"false"}];
141
+ }
142
+ }
143
+
144
+ - (void) onShowWithMessage:(id<AEPShowable> _Nonnull)message {
145
+ AEPFullscreenMessage * fullscreenMessage = (AEPFullscreenMessage *) message;
146
+ AEPMessage * messageObj = (AEPMessage *) fullscreenMessage.settings.parent;
147
+ if(messageObj) {
148
+ [self emitEventWithName:@"onShow" body:@{@"id":messageObj.id, @"autoTrack":messageObj.autoTrack ? @"true" : @"false"}];
149
+ }
150
+ }
151
+
152
+ - (BOOL) shouldShowMessageWithMessage:(id<AEPShowable> _Nonnull)message {
153
+ AEPFullscreenMessage * fullscreenMessage = (AEPFullscreenMessage *) message;
154
+ AEPMessage * messageObj = (AEPMessage *) fullscreenMessage.settings.parent;
155
+ if(messageObj) {
156
+ [self emitEventWithName:@"shouldShowMessage" body:@{@"id":messageObj.id, @"autoTrack":messageObj.autoTrack ? @"true" : @"false"}];
157
+ //Semaphore stops the thread until the value to be returned from this function is received from the JS side on thread dedicated to run JS code. The function called from JS that unlock the Semaphore is "shouldShowMessage".
158
+ [AEPLog traceWithLabel:TAG message:@"Semaphore lock initiated."];
159
+ dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
160
+ [AEPLog traceWithLabel:TAG message:@"Semaphore lock removed."];
161
+ if(self->shouldSaveMessage) {
162
+ [AEPLog traceWithLabel:TAG message:[[NSString alloc] initWithFormat:@"Message is saved with id: %@", messageObj.id]];
163
+ [cachedMessages setObject:messageObj forKey:messageObj.id];
164
+ }
165
+ }
166
+ return self->shouldShowMessage;
167
+ }
168
+
169
+ - (void) urlLoaded:(NSURL *)url byMessage:(id<AEPShowable>)message {
170
+ AEPFullscreenMessage * fullscreenMessage = (AEPFullscreenMessage *) message;
171
+ AEPMessage * messageObj = (AEPMessage *) fullscreenMessage.settings.parent;
172
+ if(messageObj){
173
+ [self emitEventWithName:@"urlLoaded" body:@{@"id":messageObj.id, @"autoTrack":messageObj.autoTrack ? @"true" : @"false", @"url":url.absoluteString}];
174
+ }
175
+ }
176
+
177
+ - (NSArray<NSString *> *) supportedEvents {
178
+ return @[@"onShow", @"onDismiss", @"shouldShowMessage",@"urlLoaded"];
179
+ }
180
+
181
+ - (void) startObserving {
182
+ hasListeners = true;
183
+ }
184
+
185
+ - (void) stopObserving {
186
+ hasListeners = false;
187
+ }
188
+
189
+ - (void) emitEventWithName: (NSString *) name body: (NSDictionary<NSString*, NSString*> *) dictionary {
190
+ if(hasListeners){
191
+ [AEPLog traceWithLabel:TAG message:[NSString stringWithFormat:@"Event emitted with name: %@", name]];
192
+ [self sendEventWithName:name body:dictionary];
193
+ }
194
+ }
195
+
27
196
  @end
28
-
@@ -0,0 +1,32 @@
1
+ import Message from './models/Message';
2
+ import { MessagingDelegate } from "./models/MessagingDelegate";
3
+ export interface IMessaging {
4
+ extensionVersion: () => Promise<string>;
5
+ refreshInAppMessages: () => void;
6
+ setMessagingDelegate: (delegate?: MessagingDelegate) => void;
7
+ shouldShowMessage: (shouldShowMessage: boolean, shouldSaveMessage: boolean) => void;
8
+ saveMessage: (message: Message) => void;
9
+ }
10
+ declare const Messaging: {
11
+ /**
12
+ * Returns the version of the AEPMessaging extension
13
+ * @returns {string} Promise a promise that resolves with the extension version
14
+ */
15
+ extensionVersion(): Promise<string>;
16
+ /**
17
+ * Initiates a network call to retrieve remote In-App Message definitions.
18
+ */
19
+ refreshInAppMessages(): void;
20
+ /**
21
+ * Function to set the UI Message delegate to listen the Message lifecycle events.
22
+ */
23
+ setMessagingDelegate(delegate: MessagingDelegate): void;
24
+ /**
25
+ * Cache the Message object in-memory to use later.
26
+ * If there is a requirement to call the Message functions like show, dismiss etc. The Message object should be saved first before calling it's functions.
27
+ * If the Message is saved using this API then it is responsibility of App to free it after using.
28
+ * To remove the Message from memory call clearMessage function of Message. Failure to call clearMessage will cause the Memory leak of Message object.
29
+ */
30
+ saveMessage(message: Message): void;
31
+ };
32
+ export default Messaging;
package/js/Messaging.js CHANGED
@@ -1,5 +1,6 @@
1
+ "use strict";
1
2
  /*
2
- Copyright 2021 Adobe. All rights reserved.
3
+ Copyright 2022 Adobe. All rights reserved.
3
4
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
5
  you may not use this file except in compliance with the License. You may obtain a copy
5
6
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -8,21 +9,72 @@ Unless required by applicable law or agreed to in writing, software distributed
8
9
  the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
10
  OF ANY KIND, either express or implied. See the License for the specific language
10
11
  governing permissions and limitations under the License.
11
-
12
- @flow
13
- @format
14
12
  */
15
-
16
- 'use strict';
17
-
18
- const RCTAEPMessaging = require('react-native').NativeModules.AEPMessaging;
19
-
20
- module.exports = {
21
- /**
22
- * Returns the version of the AEPMessaging extension
23
- * @param {string} Promise a promise that resolves with the extension verison
24
- */
25
- extensionVersion(): Promise<string> {
26
- return Promise.resolve(RCTAEPMessaging.extensionVersion());
27
- }
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ const tslib_1 = require("tslib");
15
+ const react_native_1 = require("react-native");
16
+ const Message_1 = tslib_1.__importDefault(require("./models/Message"));
17
+ const RCTAEPMessaging = react_native_1.NativeModules.AEPMessaging;
18
+ var messagingDelegate;
19
+ var savedMessageId = null;
20
+ const Messaging = {
21
+ /**
22
+ * Returns the version of the AEPMessaging extension
23
+ * @returns {string} Promise a promise that resolves with the extension version
24
+ */
25
+ extensionVersion() {
26
+ return Promise.resolve(RCTAEPMessaging.extensionVersion());
27
+ },
28
+ /**
29
+ * Initiates a network call to retrieve remote In-App Message definitions.
30
+ */
31
+ refreshInAppMessages() {
32
+ RCTAEPMessaging.refreshInAppMessages();
33
+ },
34
+ /**
35
+ * Function to set the UI Message delegate to listen the Message lifecycle events.
36
+ */
37
+ setMessagingDelegate(delegate) {
38
+ messagingDelegate = delegate;
39
+ RCTAEPMessaging.setMessagingDelegate();
40
+ const eventEmitter = new react_native_1.NativeEventEmitter(RCTAEPMessaging);
41
+ eventEmitter.addListener('onShow', (event) => {
42
+ if (messagingDelegate) {
43
+ const message = new Message_1.default(event.id, event.autoTrack === "true" ? true : false);
44
+ messagingDelegate.onShow(message);
45
+ }
46
+ });
47
+ eventEmitter.addListener('onDismiss', (event) => {
48
+ if (messagingDelegate) {
49
+ const message = new Message_1.default(event.id, event.autoTrack === "true" ? true : false);
50
+ messagingDelegate.onDismiss(message);
51
+ }
52
+ });
53
+ eventEmitter.addListener('shouldShowMessage', (event) => {
54
+ if (messagingDelegate) {
55
+ const message = new Message_1.default(event.id, event.autoTrack === "true" ? true : false);
56
+ const shouldShowMessage = messagingDelegate.shouldShowMessage(message);
57
+ RCTAEPMessaging.shouldShowMessage(shouldShowMessage, savedMessageId ? true : false);
58
+ savedMessageId = null;
59
+ }
60
+ });
61
+ eventEmitter.addListener('urlLoaded', (event) => {
62
+ if (messagingDelegate) {
63
+ const url = event.url;
64
+ const message = new Message_1.default(event.id, event.autoTrack === "true" ? true : false);
65
+ messagingDelegate.urlLoaded(url, message);
66
+ }
67
+ });
68
+ },
69
+ /**
70
+ * Cache the Message object in-memory to use later.
71
+ * If there is a requirement to call the Message functions like show, dismiss etc. The Message object should be saved first before calling it's functions.
72
+ * If the Message is saved using this API then it is responsibility of App to free it after using.
73
+ * To remove the Message from memory call clearMessage function of Message. Failure to call clearMessage will cause the Memory leak of Message object.
74
+ */
75
+ saveMessage(message) {
76
+ savedMessageId = message.id;
77
+ },
28
78
  };
79
+ exports.default = Messaging;
80
+ //# sourceMappingURL=Messaging.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Messaging.js","sourceRoot":"","sources":["../ts/Messaging.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;EAUE;;;AAEF,+CAA+E;AAC/E,uEAAuC;AAWvC,MAAM,eAAe,GAA8B,4BAAa,CAAC,YAAY,CAAC;AAK9E,IAAI,iBAAoC,CAAC;AACzC,IAAI,cAAc,GAAW,IAAI,CAAC;AAElC,MAAM,SAAS,GAAG;IAChB;;;OAGG;IACH,gBAAgB;QACd,OAAO,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED;;MAEE;IACF,oBAAoB;QAClB,eAAe,CAAC,oBAAoB,EAAE,CAAC;IACzC,CAAC;IAED;;MAEE;IACF,oBAAoB,CAAC,QAA2B;QAC9C,iBAAiB,GAAG,QAAQ,CAAC;QAC7B,eAAe,CAAC,oBAAoB,EAAE,CAAC;QACvC,MAAM,YAAY,GAAG,IAAI,iCAAkB,CAAC,eAAe,CAAC,CAAC;QAC7D,YAAY,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;YAC3C,IAAG,iBAAiB,EAAC;gBACnB,MAAM,OAAO,GAAG,IAAI,iBAAO,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAA,CAAC,CAAC,KAAK,CAAC,CAAC;gBAChF,iBAAiB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;aACnC;QACH,CAAC,CAAC,CAAC;QAEH,YAAY,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE;YAC9C,IAAG,iBAAiB,EAAC;gBACnB,MAAM,OAAO,GAAG,IAAI,iBAAO,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAA,CAAC,CAAC,KAAK,CAAC,CAAC;gBAChF,iBAAiB,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;aACtC;QACH,CAAC,CAAC,CAAC;QAEH,YAAY,CAAC,WAAW,CAAC,mBAAmB,EAAE,CAAC,KAAK,EAAE,EAAE;YACtD,IAAI,iBAAiB,EAAC;gBACpB,MAAM,OAAO,GAAG,IAAI,iBAAO,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAA,CAAC,CAAC,KAAK,CAAC,CAAC;gBAChF,MAAM,iBAAiB,GAAY,iBAAiB,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;gBAChF,eAAe,CAAC,iBAAiB,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;gBACpF,cAAc,GAAG,IAAI,CAAC;aACvB;QACH,CAAC,CAAC,CAAC;QAEH,YAAY,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE;YAC9C,IAAG,iBAAiB,EAAC;gBACnB,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;gBACtB,MAAM,OAAO,GAAG,IAAI,iBAAO,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAA,CAAC,CAAC,KAAK,CAAC,CAAC;gBAChF,iBAAiB,CAAC,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;aAC3C;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;MAKE;IACF,WAAW,CAAC,OAAgB;QAC1B,cAAc,GAAG,OAAO,CAAC,EAAE,CAAC;IAC9B,CAAC;CACF,CAAC;AAEF,kBAAe,SAAS,CAAC"}
package/js/index.d.ts CHANGED
@@ -1,15 +1,5 @@
1
- /*
2
- Copyright 2021 Adobe. All rights reserved.
3
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License. You may obtain a copy
5
- of the License at http://www.apache.org/licenses/LICENSE-2.0
6
-
7
- Unless required by applicable law or agreed to in writing, software distributed under
8
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- OF ANY KIND, either express or implied. See the License for the specific language
10
- governing permissions and limitations under the License.
11
-
12
- */
13
- export class Messaging {
14
- static extensionVersion(): Promise<string>;
15
- };
1
+ import Messaging from './Messaging';
2
+ import Message from './models/Message';
3
+ import { MessagingDelegate } from './models/MessagingDelegate';
4
+ import MessagingEdgeEventType from './models/MessagingEdgeEventType';
5
+ export { Messaging, Message, MessagingDelegate, MessagingEdgeEventType };