.sendPromise(method[, params])
Sends a message to native client and returns the Promise
object with response data
Parameters
method
required The Boxo JS SDK method
params
optional Message data object
Example
// Sending event to client
appboxo
.sendPromise('AppBoxoWebAppGetInitData')
.then(data => {
// Handling received data
console.log(data.email);
})
.catch(error => {
// Handling an error
});
You can also use imperative way
try {
const data = await appboxo.sendPromise('AppBoxoWebAppGetInitData');
// Handling received data
console.log(data.email);
} catch (error) {
// Handling an error
}
.send(method[, params])
Sends a message to native client
Parameters
method
required The Boxo JS SDK method
params
optional Message data object
Example
// App initialization
appboxo.send('AppBoxoWebAppInit');
// Opening images
appboxo.send('AppBoxoWebAppShowImages', {
images: [
"https://pp.userapi.com/c639229/v639229113/31b31/KLVUrSZwAM4.jpg",
"https://pp.userapi.com/c639229/v639229113/31b94/mWQwkgDjav0.jpg",
"https://pp.userapi.com/c639229/v639229113/31b3a/Lw2it6bdISc.jpg"
]
})
.subscribe(fn)
Subscribes a function to events listening
Parameters
fn
required Function to be subscribed to events
Example
// Subscribing to receiving events
appboxo.subscribe(event => {
if (!event.detail) {
return;
}
const { type, data } = event.detail;
if (type === 'AppBoxoWebAppOpenQRCodeReaderResult') {
// Reading result of the Code Reader
console.log(data.code_data);
}
if (type === 'AppBoxoWebAppOpenQRCodeReaderFailed') {
// Catching the error
console.log(data.error_type, data.error_data);
}
});
// Sending method
appboxo.send('AppBoxoWebAppOpenQRCodeReader', {});
.unsubscribe(fn)
Unsubscribes a function from events listening
Parameters
- ```fn“ required Event subscribed function
Example
const fn = event => {
// ...
};
// Subscribing
appboxo.subscribe(fn);
// Unsubscribing
appboxo.unsubscribe(fn);
.supports(method)
Checks if an event is available on the current device
Parameters
method
required The Boxo JS SDK method
.isWebView()
Returns true
if Boxo JS SDK is running in mobile app, or false
if not