Initializing Frame
The App.initializeFrame() method is the main entry point of the SDK. It creates a singleton of the Frame object and prepares communication with the parent platform window.
Requirement
The application must run inside an iframe of the Аспро.Cloud platform interface
ts
import App from '@aspro-cloud/miniapp-jssdk'
const frame = await App.initializeFrame()js
const App = window.ACloudMiniApp
const frame = await App.initializeFrame()Example
Displaying a notification with the current user's name:
ts
import { App, Toast } from '@aspro-cloud/miniapp-jssdk'
try {
const frame = await App.initializeFrame()
// get current user
let result = await frame.rest.get('/core/user/get/')
const user = result?.response
if (user) {
// notification with user name
new Toast({
title: `Hello, ${user.first_name || user.last_name || user.username}!`,
}).show()
} else {
throw new Error('Failed to get current user data')
}
} catch (error) {
console.error(error)
}html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Acloud MiniApp Demo</title>
</head>
<body>
<script src="https://my.aspro.cloud/static/miniapp/jssdk@latest/dist/miniapp-jssdk.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', async () => {
const App = ACloudMiniApp;
try {
const frame = await App.initializeFrame();
// get current user
let result = await frame.rest.get('/core/user/get/');
const user = result?.response;
if (user) {
// notification with user name
new App.Frame.Toast({
title: `Hello, ${user.first_name || user.last_name || user.username}!`,
}).show();
} else {
throw new Error('Failed to get current user data');
}
} catch (error) {
console.error(error);
}
});
</script>
</body>
</html>