@adobe/react-native-aepmessaging 7.2.0 → 7.3.0
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 +5 -10
- package/android/src/main/java/com/adobe/marketing/mobile/reactnative/messaging/RCTAEPMessagingConstants.java +3 -0
- package/android/src/main/java/com/adobe/marketing/mobile/reactnative/messaging/RCTAEPMessagingModule.java +22 -1
- package/dist/Messaging.js +8 -1
- package/dist/Messaging.js.map +1 -1
- package/dist/models/Message.d.ts +13 -0
- package/dist/models/Message.js +50 -1
- package/dist/models/Message.js.map +1 -1
- package/dist/models/MessagingProposition.js.map +1 -1
- package/dist/models/PersonalizationSchema.js +1 -1
- package/dist/models/PersonalizationSchema.js.map +1 -1
- package/dist/models/PropositionItem.js.map +1 -1
- package/ios/src/RCTAEPMessaging.mm +23 -0
- package/ios/src/RCTAEPMessaging.swift +58 -39
- package/ios/src/RCTAEPMessagingConstants.swift +4 -1
- package/package.json +2 -2
- package/src/Messaging.ts +13 -1
- package/src/models/Message.ts +61 -2
- package/tutorials/In-App Messaging.md +31 -0
package/README.md
CHANGED
|
@@ -222,7 +222,7 @@ propositionItem.track(
|
|
|
222
222
|
);
|
|
223
223
|
```
|
|
224
224
|
|
|
225
|
-
When using `getPropositionsForSurfaces`, the returned objects
|
|
225
|
+
When using `getPropositionsForSurfaces`, the returned objects are already `MessagingProposition` instances with typed items and convenient tracking via `PropositionItem.track(...)`.
|
|
226
226
|
|
|
227
227
|
```javascript
|
|
228
228
|
import { Messaging, MessagingProposition, MessagingEdgeEventType } from '@adobe/react-native-aepmessaging';
|
|
@@ -232,17 +232,12 @@ const messages = await Messaging.getPropositionsForSurfaces(SURFACES);
|
|
|
232
232
|
|
|
233
233
|
for (const surface of SURFACES) {
|
|
234
234
|
const propositions = messages[surface] || [];
|
|
235
|
-
|
|
236
235
|
for (const proposition of propositions) {
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
if (msgProp.items.length > 0) {
|
|
240
|
-
const propositionItem = msgProp.items[0];
|
|
241
|
-
|
|
236
|
+
for (const propositionItem of proposition.items) {
|
|
242
237
|
// Track interaction with custom data
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
238
|
+
propositionItem.track('content_card_clicked', MessagingEdgeEventType.INTERACT, null);
|
|
239
|
+
// Track with tokens for sub-item tracking
|
|
240
|
+
propositionItem.track('button_click', MessagingEdgeEventType.INTERACT, ['token-1', 'token-2']);
|
|
246
241
|
}
|
|
247
242
|
}
|
|
248
243
|
}
|
|
@@ -14,6 +14,9 @@ package com.adobe.marketing.mobile.reactnative.messaging;
|
|
|
14
14
|
class RCTAEPMessagingConstants {
|
|
15
15
|
static final String MESSAGE_ID_KEY = "messageId";
|
|
16
16
|
static final String HANDLER_NAME_KEY = "handlerName";
|
|
17
|
+
static final String JAVASCRIPT_STRING_KEY = "javascriptString";
|
|
17
18
|
static final String CONTENT_KEY = "content";
|
|
19
|
+
static final String RESULT_KEY = "result";
|
|
18
20
|
static final String ON_JAVASCRIPT_MESSAGE_EVENT = "onJavascriptMessage";
|
|
21
|
+
static final String ON_JAVASCRIPT_RESULT_EVENT = "onJavascriptResult";
|
|
19
22
|
}
|
|
@@ -204,6 +204,7 @@ public final class RCTAEPMessagingModule
|
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
+
|
|
207
208
|
@ReactMethod
|
|
208
209
|
public void dismiss(final String messageId) {
|
|
209
210
|
if (messageId != null && messageCache.get(messageId) != null) {
|
|
@@ -257,6 +258,25 @@ public final class RCTAEPMessagingModule
|
|
|
257
258
|
});
|
|
258
259
|
}
|
|
259
260
|
|
|
261
|
+
@ReactMethod
|
|
262
|
+
public void evaluateJavascript(final String messageId, final String javascriptString) {
|
|
263
|
+
Presentable<?> presentable = presentableCache.get(messageId);
|
|
264
|
+
if (presentable == null || !(presentable.getPresentation() instanceof InAppMessage)) {
|
|
265
|
+
Log.w(TAG, "evaluateJavascript: No presentable found for messageId: " + messageId);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
Presentable<InAppMessage> inAppMessagePresentable = (Presentable<InAppMessage>) presentable;
|
|
270
|
+
InAppMessageEventHandler eventHandler = inAppMessagePresentable.getPresentation().getEventHandler();
|
|
271
|
+
eventHandler.evaluateJavascript(javascriptString, result -> {
|
|
272
|
+
Map<String, String> params = new HashMap<>();
|
|
273
|
+
params.put(RCTAEPMessagingConstants.MESSAGE_ID_KEY, messageId);
|
|
274
|
+
params.put(RCTAEPMessagingConstants.JAVASCRIPT_STRING_KEY, javascriptString);
|
|
275
|
+
params.put(RCTAEPMessagingConstants.RESULT_KEY, result);
|
|
276
|
+
emitEvent(RCTAEPMessagingConstants.ON_JAVASCRIPT_RESULT_EVENT, params);
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
260
280
|
// Messaging Delegate functions
|
|
261
281
|
@Override
|
|
262
282
|
public void onShow(final Presentable<?> presentable) {
|
|
@@ -334,11 +354,12 @@ public final class RCTAEPMessagingModule
|
|
|
334
354
|
|
|
335
355
|
// Messaging Delegate Callback
|
|
336
356
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
337
|
-
public
|
|
357
|
+
public boolean setMessageSettings(final boolean shouldShowMessage,
|
|
338
358
|
final boolean shouldSaveMessage) {
|
|
339
359
|
this.shouldShowMessage = shouldShowMessage;
|
|
340
360
|
this.shouldSaveMessage = shouldSaveMessage;
|
|
341
361
|
latch.countDown();
|
|
362
|
+
return true;
|
|
342
363
|
}
|
|
343
364
|
|
|
344
365
|
/**
|
package/dist/Messaging.js
CHANGED
|
@@ -14,6 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
const tslib_1 = require("tslib");
|
|
15
15
|
const react_native_1 = require("react-native");
|
|
16
16
|
const Message_1 = tslib_1.__importDefault(require("./models/Message"));
|
|
17
|
+
const MessagingProposition_1 = require("./models/MessagingProposition");
|
|
17
18
|
const RCTAEPMessaging = react_native_1.NativeModules.AEPMessaging;
|
|
18
19
|
var messagingDelegate;
|
|
19
20
|
class Messaging {
|
|
@@ -60,7 +61,12 @@ class Messaging {
|
|
|
60
61
|
*/
|
|
61
62
|
static getPropositionsForSurfaces(surfaces) {
|
|
62
63
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
|
|
64
|
+
const propositionsList = yield RCTAEPMessaging.getPropositionsForSurfaces(surfaces);
|
|
65
|
+
let messagingPropositionsForSurfaces = {};
|
|
66
|
+
for (const [surface, propositions] of Object.entries(propositionsList)) {
|
|
67
|
+
messagingPropositionsForSurfaces[surface] = propositions.map((proposition) => new MessagingProposition_1.MessagingProposition(proposition));
|
|
68
|
+
}
|
|
69
|
+
return messagingPropositionsForSurfaces;
|
|
64
70
|
});
|
|
65
71
|
}
|
|
66
72
|
/**
|
|
@@ -99,6 +105,7 @@ class Messaging {
|
|
|
99
105
|
var _a;
|
|
100
106
|
const messageInstance = new Message_1.default(message);
|
|
101
107
|
messageInstance._clearJavascriptMessageHandlers();
|
|
108
|
+
messageInstance._clearJavascriptResultHandlers();
|
|
102
109
|
(_a = messagingDelegate === null || messagingDelegate === void 0 ? void 0 : messagingDelegate.onDismiss) === null || _a === void 0 ? void 0 : _a.call(messagingDelegate, messageInstance);
|
|
103
110
|
});
|
|
104
111
|
eventEmitter.addListener('shouldShowMessage', (message) => {
|
package/dist/Messaging.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Messaging.js","sourceRoot":"","sources":["../src/Messaging.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;EAUE;;;AAEF,+CAKsB;AACtB,uEAAuC;
|
|
1
|
+
{"version":3,"file":"Messaging.js","sourceRoot":"","sources":["../src/Messaging.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;EAUE;;;AAEF,+CAKsB;AACtB,uEAAuC;AAEvC,wEAAqE;AAsBrE,MAAM,eAAe,GACnB,4BAAa,CAAC,YAAY,CAA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WAAW,CAAC,CAAC;YAC7C,YAAY,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,CAAC;QACrD,CAAC,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,kBAAkB,CACvB,iBAA0B,EAC1B,iBAA0B;QAE1B,eAAe,CAAC,kBAAkB,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;IAC3E,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,6BAA6B,CAAC,QAAkB;QACrD,eAAe,CAAC,6BAA6B,CAAC,QAAQ,CAAC,CAAC;IAC1D,CAAC;CACF;AAED,kBAAe,SAAS,CAAC"}
|
package/dist/models/Message.d.ts
CHANGED
|
@@ -42,6 +42,12 @@ declare class Message {
|
|
|
42
42
|
* @param {function} handler: The method or closure to be called with the body of the message created in the Message's JavaScript
|
|
43
43
|
*/
|
|
44
44
|
handleJavascriptMessage(handlerName: string, handler: (content: string) => void): void;
|
|
45
|
+
/**
|
|
46
|
+
* Asynchronously evaluates the specified JavaScript string in the context of the message's WebView.
|
|
47
|
+
* @param {string} javascriptString: The JavaScript string to evaluate.
|
|
48
|
+
* @param {function} callback: A callback to be invoked when the script execution completes with the result of the execution.
|
|
49
|
+
*/
|
|
50
|
+
evaluateJavascript(javascriptString: string, callback: (result: string) => void): void;
|
|
45
51
|
/**
|
|
46
52
|
* @internal - For internal use only.
|
|
47
53
|
* Clears all the javascript message handlers for the message.
|
|
@@ -49,5 +55,12 @@ declare class Message {
|
|
|
49
55
|
* Failure to call this function may lead to memory leaks.
|
|
50
56
|
*/
|
|
51
57
|
_clearJavascriptMessageHandlers(): void;
|
|
58
|
+
/**
|
|
59
|
+
* @internal - For internal use only.
|
|
60
|
+
* Clears all the javascript result handlers for the message.
|
|
61
|
+
* This function must be called if the callbacks registered in evaluateJavascript are no longer needed.
|
|
62
|
+
* Failure to call this function may lead to memory leaks.
|
|
63
|
+
*/
|
|
64
|
+
_clearJavascriptResultHandlers(): void;
|
|
52
65
|
}
|
|
53
66
|
export default Message;
|
package/dist/models/Message.js
CHANGED
|
@@ -16,6 +16,9 @@ const RCTAEPMessaging = react_native_1.NativeModules.AEPMessaging;
|
|
|
16
16
|
// Registery to store inAppMessage callbacks for each message in Message.handleJavascriptMessage
|
|
17
17
|
// Record - {messageId : {handlerName : callback}}
|
|
18
18
|
const jsMessageHandlers = {};
|
|
19
|
+
// Registery to store inAppMessage result callbacks for each message in Message.evaluateJavascript
|
|
20
|
+
// Record - {messageId : {javascriptString : callback}}
|
|
21
|
+
const jsResultHandlers = {};
|
|
19
22
|
const handleJSMessageEventEmitter = new react_native_1.NativeEventEmitter(RCTAEPMessaging);
|
|
20
23
|
// invokes the callback registered in Message.handleJavascriptMessage with the content received from the inAppMessage webview
|
|
21
24
|
handleJSMessageEventEmitter.addListener('onJavascriptMessage', (event) => {
|
|
@@ -24,6 +27,14 @@ handleJSMessageEventEmitter.addListener('onJavascriptMessage', (event) => {
|
|
|
24
27
|
jsMessageHandlers[messageId][handlerName](content);
|
|
25
28
|
}
|
|
26
29
|
});
|
|
30
|
+
handleJSMessageEventEmitter.addListener('onJavascriptResult', (event) => {
|
|
31
|
+
const { messageId, javascriptString, result } = event;
|
|
32
|
+
if (jsResultHandlers[messageId] && jsResultHandlers[messageId][javascriptString]) {
|
|
33
|
+
// Convert result to string to maintain API parity
|
|
34
|
+
const resultString = result == null ? '' : String(result);
|
|
35
|
+
jsResultHandlers[messageId][javascriptString](resultString);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
27
38
|
class Message {
|
|
28
39
|
constructor({ id, autoTrack = false }) {
|
|
29
40
|
this.id = id;
|
|
@@ -52,7 +63,14 @@ class Message {
|
|
|
52
63
|
* of the autoTrack setting.
|
|
53
64
|
*/
|
|
54
65
|
dismiss(suppressAutoTrack) {
|
|
55
|
-
|
|
66
|
+
// iOS message.dismiss() accepts a boolean parameter to suppress autoTrack
|
|
67
|
+
// but on android side, message.dismiss() does not accept any parameters
|
|
68
|
+
if (react_native_1.Platform.OS === 'android') {
|
|
69
|
+
RCTAEPMessaging.dismiss(this.id);
|
|
70
|
+
}
|
|
71
|
+
if (react_native_1.Platform.OS === 'ios') {
|
|
72
|
+
RCTAEPMessaging.dismiss(this.id, suppressAutoTrack ? true : false);
|
|
73
|
+
}
|
|
56
74
|
}
|
|
57
75
|
/**
|
|
58
76
|
* Generates an Edge Event for the provided interaction and eventType.
|
|
@@ -93,6 +111,28 @@ class Message {
|
|
|
93
111
|
jsMessageHandlers[this.id][handlerName] = handler;
|
|
94
112
|
RCTAEPMessaging.handleJavascriptMessage(this.id, handlerName);
|
|
95
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Asynchronously evaluates the specified JavaScript string in the context of the message's WebView.
|
|
116
|
+
* @param {string} javascriptString: The JavaScript string to evaluate.
|
|
117
|
+
* @param {function} callback: A callback to be invoked when the script execution completes with the result of the execution.
|
|
118
|
+
*/
|
|
119
|
+
evaluateJavascript(javascriptString, callback) {
|
|
120
|
+
// validate parameters
|
|
121
|
+
if (!javascriptString) {
|
|
122
|
+
console.warn('[AEP Messaging] evaluateJavascript: javascriptString is required');
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (typeof callback !== 'function') {
|
|
126
|
+
console.warn('[AEP Messaging] evaluateJavascript: callback must be a function');
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
// cache the callback
|
|
130
|
+
if (!jsResultHandlers[this.id]) {
|
|
131
|
+
jsResultHandlers[this.id] = {};
|
|
132
|
+
}
|
|
133
|
+
jsResultHandlers[this.id][javascriptString] = callback;
|
|
134
|
+
RCTAEPMessaging.evaluateJavascript(this.id, javascriptString);
|
|
135
|
+
}
|
|
96
136
|
/**
|
|
97
137
|
* @internal - For internal use only.
|
|
98
138
|
* Clears all the javascript message handlers for the message.
|
|
@@ -102,6 +142,15 @@ class Message {
|
|
|
102
142
|
_clearJavascriptMessageHandlers() {
|
|
103
143
|
delete jsMessageHandlers[this.id];
|
|
104
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* @internal - For internal use only.
|
|
147
|
+
* Clears all the javascript result handlers for the message.
|
|
148
|
+
* This function must be called if the callbacks registered in evaluateJavascript are no longer needed.
|
|
149
|
+
* Failure to call this function may lead to memory leaks.
|
|
150
|
+
*/
|
|
151
|
+
_clearJavascriptResultHandlers() {
|
|
152
|
+
delete jsResultHandlers[this.id];
|
|
153
|
+
}
|
|
105
154
|
}
|
|
106
155
|
exports.default = Message;
|
|
107
156
|
//# sourceMappingURL=Message.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Message.js","sourceRoot":"","sources":["../../src/models/Message.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;EAUE;;AAEF,+
|
|
1
|
+
{"version":3,"file":"Message.js","sourceRoot":"","sources":["../../src/models/Message.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;EAUE;;AAEF,+CAA2E;AAE3E,MAAM,eAAe,GAAG,4BAAa,CAAC,YAAY,CAAC;AAEnD,gGAAgG;AAChG,kDAAkD;AAClD,MAAM,iBAAiB,GAA8D,EAAE,CAAC;AAExF,kGAAkG;AAClG,uDAAuD;AACvD,MAAM,gBAAgB,GAA6D,EAAE,CAAC;AAEtF,MAAM,2BAA2B,GAAG,IAAI,iCAAkB,CAAC,eAAe,CAAC,CAAC;AAE5E,6HAA6H;AAC7H,2BAA2B,CAAC,WAAW,CAAC,qBAAqB,EAAE,CAAC,KAAK,EAAE,EAAE;IACvE,MAAM,EAAC,SAAS,EAAE,WAAW,EAAE,OAAO,EAAC,GAAG,KAAK,CAAC;IAChD,IAAI,iBAAiB,CAAC,SAAS,CAAC,IAAI,iBAAiB,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC;QAC9E,iBAAiB,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC;IACrD,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,2BAA2B,CAAC,WAAW,CAAC,oBAAoB,EA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;YAClB,QAAQ,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,EAAE,CAAC;gBACzB,KAAK,6CAAqB,CAAC,YAAY;oBACrC,QAAQ,GAAG,IAAI,yBAAW,CAAC,QAAe,CAAC,CAAC;oBAC3C,QAAgB,CAAC,UAAU,GAAG,UAAU,CAAC;oBAC1C,OAAO,QAAQ,CAAC;gBAClB,KAAK,6CAAqB,CAAC,YAAY;oBACrC,QAAQ,GAAG,IAAI,iCAAe,CAAC,QAAe,CAAC,CAAC;oBAC/C,QAAgB,CAAC,UAAU,GAAG,UAAU,CAAC;oBAC1C,OAAO,QAAQ,CAAC;gBAClB,KAAK,6CAAqB,CAAC,YAAY;oBACrC,QAAQ,GAAG,IAAI,qCAAmB,CAAC,QAAe,CAAC,CAAC;oBACnD,QAAgB,CAAC,UAAU,GAAG,UAAU,CAAC;oBAC1C,OAAO,QAAQ,CAAC;gBAClB;oBACE,QAAQ,GAAG,IAAI,iCAAe,CAAC,QAAe,CAAC,CAAC;oBAC/C,QAAgB,CAAC,UAAU,GAAG,UAAU,CAAC;oBAC1C,OAAO,QAAQ,CAAC;YACpB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAzCD,gDAyCC;AAE8B,kDAAoB"}
|
|
@@ -21,5 +21,5 @@ var PersonalizationSchema;
|
|
|
21
21
|
PersonalizationSchema["JSON_CONTENT"] = "https://ns.adobe.com/personalization/json-content-item";
|
|
22
22
|
PersonalizationSchema["NATIVE_ALERT"] = "https://ns.adobe.com/personalization/message/native-alert";
|
|
23
23
|
PersonalizationSchema["RULESET_ITEM"] = "https://ns.adobe.com/personalization/ruleset-item";
|
|
24
|
-
})(PersonalizationSchema
|
|
24
|
+
})(PersonalizationSchema || (exports.PersonalizationSchema = PersonalizationSchema = {}));
|
|
25
25
|
//# sourceMappingURL=PersonalizationSchema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersonalizationSchema.js","sourceRoot":"","sources":["../../src/models/PersonalizationSchema.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;EAUE;;;AAEF,IAAY,qBAQX;AARD,WAAY,qBAAqB;IAC/B,mGAA0E,CAAA;IAC1E,sGAA6E,CAAA;IAC7E,gGAAuE,CAAA;IACvE,uFAA8D,CAAA;IAC9D,gGAAuE,CAAA;IACvE,mGAA0E,CAAA;IAC1E,2FAAkE,CAAA;AACpE,CAAC,EARW,qBAAqB,
|
|
1
|
+
{"version":3,"file":"PersonalizationSchema.js","sourceRoot":"","sources":["../../src/models/PersonalizationSchema.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;EAUE;;;AAEF,IAAY,qBAQX;AARD,WAAY,qBAAqB;IAC/B,mGAA0E,CAAA;IAC1E,sGAA6E,CAAA;IAC7E,gGAAuE,CAAA;IACvE,uFAA8D,CAAA;IAC9D,gGAAuE,CAAA;IACvE,mGAA0E,CAAA;IAC1E,2FAAkE,CAAA;AACpE,CAAC,EARW,qBAAqB,qCAArB,qBAAqB,QAQhC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropositionItem.js","sourceRoot":"","sources":["../../src/models/PropositionItem.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;EAUE;;;AAEF,+CAA6C;AAI7C,MAAM,eAAe,GAAG,4BAAa,CAAC,YAAY,CAAC;AAenD;;;;;;GAMG;AACH,MAAa,eAAe;IAO1B,YAAY,mBAAwC;QAClD,IAAI,CAAC,EAAE,GAAG,mBAAmB,CAAC,EAAE,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,mBAAmB,CAAC,MAAM,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC,IAAI,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC,IAAI,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,mBAAmB,CAAC,UAAU,CAAC;IACnD,CAAC;IAED;;;;OAIG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,EAAE,CAAC;IACjB,CAAC;IAED;;;;OAIG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAgCD,iBAAiB;IACjB,KAAK,CACH,sBAA8D,EAC9D,SAAkC,EAClC,MAAwB;QAExB,sCAAsC;QACtC,IAAI,OAAO,sBAAsB,KAAK,QAAQ,IAAI,SAAS,KAAK,SAAS,EAAE;
|
|
1
|
+
{"version":3,"file":"PropositionItem.js","sourceRoot":"","sources":["../../src/models/PropositionItem.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;EAUE;;;AAEF,+CAA6C;AAI7C,MAAM,eAAe,GAAG,4BAAa,CAAC,YAAY,CAAC;AAenD;;;;;;GAMG;AACH,MAAa,eAAe;IAO1B,YAAY,mBAAwC;QAClD,IAAI,CAAC,EAAE,GAAG,mBAAmB,CAAC,EAAE,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,mBAAmB,CAAC,MAAM,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC,IAAI,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC,IAAI,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,mBAAmB,CAAC,UAAU,CAAC;IACnD,CAAC;IAED;;;;OAIG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,EAAE,CAAC;IACjB,CAAC;IAED;;;;OAIG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAgCD,iBAAiB;IACjB,KAAK,CACH,sBAA8D,EAC9D,SAAkC,EAClC,MAAwB;QAExB,sCAAsC;QACtC,IAAI,OAAO,sBAAsB,KAAK,QAAQ,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC1E,mCAAmC;YACnC,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,sBAAsB,EAAE,IAAI,CAAC,CAAC;QAC5D,CAAC;aAAM,IAAI,OAAO,sBAAsB,KAAK,QAAQ,IAAI,sBAAsB,KAAK,IAAI,EAAE,CAAC;YACzF,yDAAyD;YACzD,IAAI,CAAC,gBAAgB,CAAC,sBAAsB,EAAE,SAAU,EAAE,MAAM,IAAI,IAAI,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;IAED;;OAEG;IACK,gBAAgB,CAAC,WAA0B,EAAE,SAAiC,EAAE,MAAuB;;QAC7G,MAAM,gBAAgB,GAAG,MAAA,IAAI,CAAC,UAAU,mCAAI,IAAI,CAAC;QACjD,eAAe,CAAC,oBAAoB,CAAC,gBAAgB,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IACzF,CAAC;CAEF;AAhGD,0CAgGC"}
|
|
@@ -60,6 +60,10 @@ RCT_EXTERN_METHOD(handleJavascriptMessage
|
|
|
60
60
|
: (NSString *)messageId handlerName
|
|
61
61
|
: (NSString *)handlerName)
|
|
62
62
|
|
|
63
|
+
RCT_EXTERN_METHOD(evaluateJavascript
|
|
64
|
+
: (NSString *)messageId javascriptString
|
|
65
|
+
: (NSString *)javascriptString)
|
|
66
|
+
|
|
63
67
|
RCT_EXTERN_METHOD(trackPropositionItem
|
|
64
68
|
: (NSString *)uuid interaction
|
|
65
69
|
: (NSString * _Nullable)interaction eventType
|
|
@@ -68,4 +72,23 @@ RCT_EXTERN_METHOD(trackPropositionItem
|
|
|
68
72
|
: (RCTPromiseResolveBlock)resolve withRejecter
|
|
69
73
|
: (RCTPromiseRejectBlock)reject);
|
|
70
74
|
|
|
75
|
+
RCT_EXTERN_METHOD(setAutoTrack
|
|
76
|
+
: (NSString *)messageId autoTrack
|
|
77
|
+
: (BOOL)autoTrack);
|
|
78
|
+
|
|
79
|
+
RCT_EXTERN_METHOD(show
|
|
80
|
+
: (NSString *)messageId);
|
|
81
|
+
|
|
82
|
+
RCT_EXTERN_METHOD(dismiss
|
|
83
|
+
: (NSString *)messageId suppressAutoTrack
|
|
84
|
+
: (BOOL)suppressAutoTrack);
|
|
85
|
+
|
|
86
|
+
RCT_EXTERN_METHOD(track
|
|
87
|
+
: (NSString *)messageId interaction
|
|
88
|
+
: (NSString *)interaction eventType
|
|
89
|
+
: (NSInteger)eventType);
|
|
90
|
+
|
|
91
|
+
RCT_EXTERN_METHOD(clear
|
|
92
|
+
: (NSString *)messageId);
|
|
93
|
+
|
|
71
94
|
@end
|
|
@@ -133,87 +133,75 @@ public class RCTAEPMessaging: RCTEventEmitter, MessagingDelegate {
|
|
|
133
133
|
|
|
134
134
|
/// Message Class Methods
|
|
135
135
|
@objc
|
|
136
|
-
func
|
|
137
|
-
_ id: String
|
|
138
|
-
withResolver resolve: @escaping RCTPromiseResolveBlock,
|
|
139
|
-
withRejecter reject: @escaping RCTPromiseRejectBlock
|
|
136
|
+
func clear(
|
|
137
|
+
_ id: String
|
|
140
138
|
) {
|
|
141
139
|
let msg = messageCache[id]
|
|
142
140
|
if msg != nil {
|
|
143
141
|
messageCache.removeValue(forKey: msg!.id)
|
|
144
|
-
|
|
142
|
+
print("clear: \(id) removed")
|
|
143
|
+
} else {
|
|
144
|
+
print("clear: \(id) not found")
|
|
145
145
|
}
|
|
146
|
-
reject(Constants.CACHE_MISS, nil, nil)
|
|
147
146
|
}
|
|
148
147
|
|
|
149
148
|
@objc
|
|
150
|
-
func
|
|
149
|
+
func dismiss(
|
|
151
150
|
_ id: String,
|
|
152
|
-
|
|
153
|
-
withResolver resolve: @escaping RCTPromiseResolveBlock,
|
|
154
|
-
withRejecter reject: @escaping RCTPromiseRejectBlock
|
|
151
|
+
suppressAutoTrack: Bool
|
|
155
152
|
) {
|
|
156
153
|
let msg = messageCache[id]
|
|
157
154
|
if msg != nil {
|
|
158
155
|
msg!.dismiss(suppressAutoTrack: suppressAutoTrack)
|
|
159
|
-
|
|
160
|
-
|
|
156
|
+
print("dismiss: \(id) to \(suppressAutoTrack)")
|
|
157
|
+
} else {
|
|
158
|
+
print("dismiss: \(id) not found")
|
|
161
159
|
}
|
|
162
|
-
reject(Constants.CACHE_MISS, nil, nil)
|
|
163
160
|
}
|
|
164
161
|
|
|
165
162
|
@objc
|
|
166
163
|
func setAutoTrack(
|
|
167
164
|
_ id: String,
|
|
168
|
-
|
|
169
|
-
withResolver resolve: @escaping RCTPromiseResolveBlock,
|
|
170
|
-
withRejecter reject: @escaping RCTPromiseRejectBlock
|
|
165
|
+
autoTrack: Bool
|
|
171
166
|
) {
|
|
172
|
-
|
|
173
167
|
let msg = messageCache[id]
|
|
174
|
-
if msg != nil {
|
|
175
|
-
msg!.autoTrack =
|
|
176
|
-
|
|
177
|
-
|
|
168
|
+
if (msg != nil) {
|
|
169
|
+
msg!.autoTrack = autoTrack
|
|
170
|
+
print("setAutoTrack: \(id) to \(autoTrack)")
|
|
171
|
+
} else {
|
|
172
|
+
print("setAutoTrack: \(id) not found")
|
|
178
173
|
}
|
|
179
|
-
reject(Constants.CACHE_MISS, nil, nil)
|
|
180
174
|
}
|
|
181
175
|
|
|
182
176
|
@objc
|
|
183
|
-
private func
|
|
184
|
-
_ id: String
|
|
185
|
-
withResolver resolve: @escaping RCTPromiseResolveBlock,
|
|
186
|
-
withRejecter reject: @escaping RCTPromiseRejectBlock
|
|
177
|
+
private func show(
|
|
178
|
+
_ id: String
|
|
187
179
|
) {
|
|
188
180
|
let msg = messageCache[id]
|
|
189
181
|
if msg != nil {
|
|
190
182
|
msg!.show()
|
|
191
|
-
|
|
192
|
-
|
|
183
|
+
print("show: \(id) shown")
|
|
184
|
+
} else {
|
|
185
|
+
print("show: \(id) not found")
|
|
193
186
|
}
|
|
194
|
-
reject(Constants.CACHE_MISS, nil, nil)
|
|
195
|
-
|
|
196
187
|
}
|
|
197
188
|
|
|
198
189
|
@objc
|
|
199
|
-
func
|
|
190
|
+
func track(
|
|
200
191
|
_ id: String,
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
withResolver resolve: @escaping RCTPromiseResolveBlock,
|
|
204
|
-
withRejecter reject: @escaping RCTPromiseRejectBlock
|
|
192
|
+
interaction: String,
|
|
193
|
+
eventType: Int
|
|
205
194
|
) {
|
|
206
|
-
|
|
207
195
|
let msg = messageCache[id]
|
|
208
196
|
let eventType =
|
|
209
197
|
MessagingEdgeEventType.init(rawValue: eventType)
|
|
210
198
|
?? MessagingEdgeEventType.dismiss
|
|
211
199
|
if msg != nil {
|
|
212
200
|
msg!.track(interaction, withEdgeEventType: eventType)
|
|
213
|
-
|
|
214
|
-
|
|
201
|
+
print("track: \(id) to \(interaction) and \(eventType)")
|
|
202
|
+
} else {
|
|
203
|
+
print("track: \(id) not found")
|
|
215
204
|
}
|
|
216
|
-
reject(Constants.CACHE_MISS, nil, nil)
|
|
217
205
|
}
|
|
218
206
|
|
|
219
207
|
@objc
|
|
@@ -286,6 +274,37 @@ public class RCTAEPMessaging: RCTEventEmitter, MessagingDelegate {
|
|
|
286
274
|
}
|
|
287
275
|
}
|
|
288
276
|
|
|
277
|
+
@objc
|
|
278
|
+
func evaluateJavascript(
|
|
279
|
+
_ messageId: String,
|
|
280
|
+
javascriptString: String
|
|
281
|
+
) {
|
|
282
|
+
guard let message = jsHandlerMessageCache[messageId] else {
|
|
283
|
+
print("[RCTAEPMessaging] evaluateJavascript: No message found in cache for messageId: \(messageId)")
|
|
284
|
+
return
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
guard let messageWebView = message.view as? WKWebView else {
|
|
288
|
+
print("[RCTAEPMessaging] evaluateJavascript: Could not get WKWebView from message")
|
|
289
|
+
return
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
messageWebView.evaluateJavaScript(javascriptString) { [weak self] result, error in
|
|
293
|
+
if let error = error {
|
|
294
|
+
print("[RCTAEPMessaging] evaluateJavascript error: \(error)")
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
self?.emitNativeEvent(
|
|
298
|
+
name: Constants.ON_JAVASCRIPT_RESULT_EVENT,
|
|
299
|
+
body: [
|
|
300
|
+
Constants.MESSAGE_ID_KEY: messageId,
|
|
301
|
+
Constants.JAVASCRIPT_STRING_KEY: javascriptString,
|
|
302
|
+
Constants.RESULT_KEY: result ?? NSNull()
|
|
303
|
+
]
|
|
304
|
+
)
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
289
308
|
/// MARK: - Unified PropositionItem Tracking Methods
|
|
290
309
|
|
|
291
310
|
/**
|
|
@@ -17,10 +17,13 @@ class Constants {
|
|
|
17
17
|
static let SHOULD_SHOW_MESSAGE_EVENT = "shouldShowMessage"
|
|
18
18
|
static let URL_LOADED_EVENT = "urlLoaded"
|
|
19
19
|
static let ON_JAVASCRIPT_MESSAGE_EVENT = "onJavascriptMessage"
|
|
20
|
+
static let ON_JAVASCRIPT_RESULT_EVENT = "onJavascriptResult"
|
|
20
21
|
static let SUPPORTED_EVENTS = [
|
|
21
|
-
ON_DISMISS_EVENT, ON_SHOW_EVENT, SHOULD_SHOW_MESSAGE_EVENT, URL_LOADED_EVENT, ON_JAVASCRIPT_MESSAGE_EVENT
|
|
22
|
+
ON_DISMISS_EVENT, ON_SHOW_EVENT, SHOULD_SHOW_MESSAGE_EVENT, URL_LOADED_EVENT, ON_JAVASCRIPT_MESSAGE_EVENT, ON_JAVASCRIPT_RESULT_EVENT
|
|
22
23
|
]
|
|
23
24
|
static let MESSAGE_ID_KEY = "messageId"
|
|
24
25
|
static let HANDLER_NAME_KEY = "handlerName"
|
|
26
|
+
static let JAVASCRIPT_STRING_KEY = "javascriptString"
|
|
25
27
|
static let CONTENT_KEY = "content"
|
|
28
|
+
static let RESULT_KEY = "result"
|
|
26
29
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/react-native-aepmessaging",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.0",
|
|
4
4
|
"description": "Adobe Experience Platform support for React Native apps.",
|
|
5
5
|
"homepage": "https://developer.adobe.com/client-sdks/documentation/",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"installConfig": {
|
|
40
40
|
"hoistingLimits": "dependencies"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "a55b63342c700922500ee85897a4f8ab5d9ca78c"
|
|
43
43
|
}
|
package/src/Messaging.ts
CHANGED
|
@@ -91,8 +91,19 @@ class Messaging {
|
|
|
91
91
|
static async getPropositionsForSurfaces(
|
|
92
92
|
surfaces: string[]
|
|
93
93
|
): Promise<Record<string, MessagingProposition[]>> {
|
|
94
|
-
|
|
94
|
+
|
|
95
|
+
const propositionsList = await RCTAEPMessaging.getPropositionsForSurfaces(surfaces);
|
|
96
|
+
let messagingPropositionsForSurfaces: Record<string, MessagingProposition[]> = {};
|
|
97
|
+
|
|
98
|
+
for (const [surface, propositions] of Object.entries(propositionsList)) {
|
|
99
|
+
messagingPropositionsForSurfaces[surface] = propositions.map(
|
|
100
|
+
(proposition) => new MessagingProposition(proposition)
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return messagingPropositionsForSurfaces;
|
|
95
105
|
}
|
|
106
|
+
|
|
96
107
|
/**
|
|
97
108
|
* @deprecated Use PropositionItem.track(...) instead.
|
|
98
109
|
*/
|
|
@@ -136,6 +147,7 @@ class Messaging {
|
|
|
136
147
|
eventEmitter.addListener('onDismiss', (message: Message) => {
|
|
137
148
|
const messageInstance = new Message(message);
|
|
138
149
|
messageInstance._clearJavascriptMessageHandlers();
|
|
150
|
+
messageInstance._clearJavascriptResultHandlers();
|
|
139
151
|
messagingDelegate?.onDismiss?.(messageInstance);
|
|
140
152
|
});
|
|
141
153
|
|
package/src/models/Message.ts
CHANGED
|
@@ -10,13 +10,18 @@ OF ANY KIND, either express or implied. See the License for the specific languag
|
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { NativeEventEmitter, NativeModules } from 'react-native';
|
|
13
|
+
import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
|
|
14
14
|
|
|
15
15
|
const RCTAEPMessaging = NativeModules.AEPMessaging;
|
|
16
16
|
|
|
17
17
|
// Registery to store inAppMessage callbacks for each message in Message.handleJavascriptMessage
|
|
18
18
|
// Record - {messageId : {handlerName : callback}}
|
|
19
19
|
const jsMessageHandlers: Record<string, Record<string, (content: string) => void>> = {};
|
|
20
|
+
|
|
21
|
+
// Registery to store inAppMessage result callbacks for each message in Message.evaluateJavascript
|
|
22
|
+
// Record - {messageId : {javascriptString : callback}}
|
|
23
|
+
const jsResultHandlers: Record<string, Record<string, (result: string) => void>> = {};
|
|
24
|
+
|
|
20
25
|
const handleJSMessageEventEmitter = new NativeEventEmitter(RCTAEPMessaging);
|
|
21
26
|
|
|
22
27
|
// invokes the callback registered in Message.handleJavascriptMessage with the content received from the inAppMessage webview
|
|
@@ -27,6 +32,15 @@ handleJSMessageEventEmitter.addListener('onJavascriptMessage', (event) => {
|
|
|
27
32
|
}
|
|
28
33
|
});
|
|
29
34
|
|
|
35
|
+
handleJSMessageEventEmitter.addListener('onJavascriptResult', (event) => {
|
|
36
|
+
const {messageId, javascriptString, result} = event;
|
|
37
|
+
if (jsResultHandlers[messageId] && jsResultHandlers[messageId][javascriptString]) {
|
|
38
|
+
// Convert result to string to maintain API parity
|
|
39
|
+
const resultString = result == null ? '' : String(result);
|
|
40
|
+
jsResultHandlers[messageId][javascriptString](resultString);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
30
44
|
class Message {
|
|
31
45
|
id: string;
|
|
32
46
|
autoTrack: boolean;
|
|
@@ -61,7 +75,16 @@ class Message {
|
|
|
61
75
|
* of the autoTrack setting.
|
|
62
76
|
*/
|
|
63
77
|
dismiss(suppressAutoTrack?: boolean) {
|
|
64
|
-
|
|
78
|
+
// iOS message.dismiss() accepts a boolean parameter to suppress autoTrack
|
|
79
|
+
// but on android side, message.dismiss() does not accept any parameters
|
|
80
|
+
if (Platform.OS === 'android') {
|
|
81
|
+
RCTAEPMessaging.dismiss(this.id);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (Platform.OS === 'ios') {
|
|
85
|
+
RCTAEPMessaging.dismiss(this.id, suppressAutoTrack ? true : false);
|
|
86
|
+
}
|
|
87
|
+
|
|
65
88
|
}
|
|
66
89
|
|
|
67
90
|
/**
|
|
@@ -108,6 +131,32 @@ class Message {
|
|
|
108
131
|
RCTAEPMessaging.handleJavascriptMessage(this.id, handlerName);
|
|
109
132
|
}
|
|
110
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Asynchronously evaluates the specified JavaScript string in the context of the message's WebView.
|
|
136
|
+
* @param {string} javascriptString: The JavaScript string to evaluate.
|
|
137
|
+
* @param {function} callback: A callback to be invoked when the script execution completes with the result of the execution.
|
|
138
|
+
*/
|
|
139
|
+
evaluateJavascript(javascriptString: string, callback: (result: string) => void) {
|
|
140
|
+
// validate parameters
|
|
141
|
+
if (!javascriptString) {
|
|
142
|
+
console.warn('[AEP Messaging] evaluateJavascript: javascriptString is required');
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (typeof callback !== 'function') {
|
|
147
|
+
console.warn('[AEP Messaging] evaluateJavascript: callback must be a function');
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// cache the callback
|
|
152
|
+
if (!jsResultHandlers[this.id]) {
|
|
153
|
+
jsResultHandlers[this.id] = {};
|
|
154
|
+
}
|
|
155
|
+
jsResultHandlers[this.id][javascriptString] = callback;
|
|
156
|
+
|
|
157
|
+
RCTAEPMessaging.evaluateJavascript(this.id, javascriptString);
|
|
158
|
+
}
|
|
159
|
+
|
|
111
160
|
/**
|
|
112
161
|
* @internal - For internal use only.
|
|
113
162
|
* Clears all the javascript message handlers for the message.
|
|
@@ -117,6 +166,16 @@ class Message {
|
|
|
117
166
|
_clearJavascriptMessageHandlers() {
|
|
118
167
|
delete jsMessageHandlers[this.id];
|
|
119
168
|
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @internal - For internal use only.
|
|
172
|
+
* Clears all the javascript result handlers for the message.
|
|
173
|
+
* This function must be called if the callbacks registered in evaluateJavascript are no longer needed.
|
|
174
|
+
* Failure to call this function may lead to memory leaks.
|
|
175
|
+
*/
|
|
176
|
+
_clearJavascriptResultHandlers() {
|
|
177
|
+
delete jsResultHandlers[this.id];
|
|
178
|
+
}
|
|
120
179
|
}
|
|
121
180
|
|
|
122
181
|
export default Message;
|
|
@@ -65,3 +65,34 @@ When the user clicks the button inside of this in-app message, the handler confi
|
|
|
65
65
|
```bash
|
|
66
66
|
JavaScript body passed to react native callback: callbacks are cool!
|
|
67
67
|
```
|
|
68
|
+
|
|
69
|
+
# Execute JavaScript methods from native code
|
|
70
|
+
|
|
71
|
+
You can execute JavaScript in an in-app message from native code by completing the following steps:
|
|
72
|
+
- [Implement and assign a `Messaging Delegate`](#implement-and-assign-a-messaging-delegate-1)
|
|
73
|
+
- [Call the Javascript method](#call-the-javascript-method)
|
|
74
|
+
|
|
75
|
+
## Implement and assign a `Messaging Delegate`
|
|
76
|
+
|
|
77
|
+
To register a JavaScript event handler with a Message object, you will first need to implement and set a MessagingDelegate.
|
|
78
|
+
Please read the [documentation](../README.md/#programmatically-control-the-display-of-in-app-messages) for more detailed instructions on implementing and using a MessagingDelegate.
|
|
79
|
+
|
|
80
|
+
## Call the JavaScript method
|
|
81
|
+
|
|
82
|
+
In the `onShow` function of `MessagingDelegate`, call `evaluateJavascript(javascriptString: string, callback: (result: string) => void)`.
|
|
83
|
+
|
|
84
|
+
### Example
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
Messaging.setMessagingDelegate({
|
|
88
|
+
onShow: msg => {
|
|
89
|
+
console.log('show', msg);
|
|
90
|
+
msg.evaluateJavascript(
|
|
91
|
+
"(function() {console.log('my test'); return 'some result';})();",
|
|
92
|
+
(result: string) => {
|
|
93
|
+
console.log('Result:', result);
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
```
|