the name of the javascript interface registered on the native side
the name of the callback that the native side will use to send messages back to the javascript side
a secret to ensure that messages are only processed by the correct handler
Assign the incoming handler method to the global object. This is the method that Android will call to deliver messages.
Capture the global handler and remove it from the global object.
Optional
context: string = 'none'
Android shared messaging configuration. This class should be constructed once and then shared between features (because of the way it modifies globals).
For example, if Android is injecting a JavaScript module like C-S-S which contains multiple 'sub-features', then this class would be instantiated once and then shared between all sub-features.
The following example shows all the fields that are required to be passed in:
Once an instance of AndroidMessagingConfig is created, you can then use it to construct many instances of Messaging (one per feature). See
examples/android.example.js
for an example.Native integration
Assuming you have the following:
@JavascriptInterface
named"ContentScopeScripts"
"featureA"
"featureA"
called"helloWorld"
Then delivering a NotificationMessage to it, would be roughly this in JavaScript (remember
params
is optional though)When you receive the JSON payload (note that it will be a string), you'll need to deserialize/verify it according to "Messaging Implementation Guide"
Responding to a RequestMessage, or pushing a SubscriptionEvent
If you receive a RequestMessage, you'll need to deliver a MessageResponse. Similarly, if you want to push new data, you need to deliver a SubscriptionEvent. In both cases you'll do this through a global
window
method. Given the snippet below, this is how it would relate to the AndroidMessagingConfig:$messageCallback
matches AndroidMessagingConfig.messageCallback$messageSecret
matches AndroidMessagingConfig.messageSecret$message
is JSON string that represents one of MessageResponse or SubscriptionEvent