Views: 4545
Last Modified: 17.08.2020
Let's review standard Push & Pull client within an application. Here's an example of app page with web interface:
<!DOCTYPE html>
<html>
<head>
<title>Bitri24 application with Push & Pull</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="//api.bitrix24.com/api/v1/"></script>
<script src="//api.bitrix24.com/api/v1/pull/"></script>
</head>
<body>
<script>
window.appPullClient = new BX.PullClient({
restApplication: 'myApplication_test.bitrix24.ru',
restClient: BX24,
userId: 1
});
window.appPullClient.subscribe({
moduleId: 'application',
callback: function (data) {
console.warn(data); // {command: '...', params: {...}, extra: {...}}
}.bind(this)
});
window.appPullClient.start();
</script>
</body>
</html>
Indicate the following parameters when initializing BX.PullClient:
- restApplication - indicate arbitrary app's string identifier. (Can be unique for each portal with your application installed)
- userId - indicate currently authorized user ID
Connecting PullClient allows for your app's front-end to receive an event from your app's back-end channel via при помощи метода pull.application.event.add.