In order to integrate the six modules into your web site, you only need to insert this JavaScript code into each web page:
<script type="text/javascript">
!function (a, d) {
a[d] || (a[d] = {}), a[d].user_id = {username};
var r, s;
a.addEventListener("load", function () {
r = document.createElement('script'),
r.type = "text/javascript",
r.async = 1,
r.src = 'https://api.pisuite.com/Initial/All?cid={piSuite:API:SiteSecret}',
s = document.getElementsByTagName('script')[0],
s.parentNode.insertBefore(r, s); });
}(window, "_vdnalrtr");
</script>
The above code will be executed only once after a page is loaded. When a new page is loaded, the above code needs to be executed.
For {piSuite:API:SiteSecret} you need to use the Site Secret value you obtain when you register your website with PiSuite, as illustrated in the following picture.
The value you use for {username} depends on the user identification method.
In a single-page web application e.g, written with ReactJs or AngularJS, you need to take a slightly different approach using the following steps:
Once the user is authenticated, make a call to a Web Api method on your server that returns the encrypted username {username}.
window["_vdnalrtr"] || (window["_vdnalrtr"] = {}),
window["_vdnalrtr"].user_id = {username};
var r, s; r = document.createElement('script'), r.type = "text/javascript",
r.async = 1,
r.src = "https://api.pisuite.com/Initial/All?cid=={piSuite:API:SiteSecret}",
s = document.getElementsByTagName('script')[0], s.parentNode.insertBefore(r, s);
3. Whenever the rendered HTML is updated, e.g., the rendered markup is updated in ReactJS, then your web application needs to refresh the data from PiSuite that corresponds to the rendered markup. Call the JavaScript method pisuitePlus.RU({currentLocation}) and pass the current location {currentLocation} to the PiSuite API. This will refresh the data from PiSuite e.g., the help for the rendered HTML will be loaded from PiSuite and will be displayed.
4. The encrypted username {username} has an expiry time. If {username} has expired, then PiSuiteApi will reject all calls as unauthenticated, and pisuitePlus.RU() will throw a Custom event expiredPiSuiteToken. You need to add an event listener that will call your Web Api and refresh the encrypted username {username}:
window.addEventListener('expiredPiSuiteToken', function (e) {
console.log('expiredPiSuiteToken: ' + e.detail);
//1. Call your Web Api and refresh the encrypted username {username}
//2. Next, store {username} in window["_vdnalrtr"].user_id
window["_vdnalrtr"].user_id = {username};
});
Here is a full implementation of the event listener:
window.addEventListener('expiredPiSuiteToken', async function (e) {
try {
let x = await UserService.getEncrypted();
window["_vdnalrtr"].user_id = x; window.pisuitePlus.RU(pathname);
}
catch {}
});
The call to https://api.pisuite.com/Initial/All accepts five query parameters
r.src = 'https://api.pisuite.com/Initial/All?cid={piSuite:API:SiteSecret}&m={m}&j={j}&a={a}&b={b}',
m identifies the PiSuite modules included in your website. It is a 6-bit integer. Each binary position turns on and off the inclusion of a PiSuite module. The default value is 63, which means that all six modules are inserted into your website. For example, m = 35 = 1 + 2 + 32 means that only Alert, Help, and Feedback modules will be included in your website.
Module | Bit Position | Value |
Alert | 0 | 1 |
Favourites. | 1 | 2 |
Help | 2 | 4 |
News | 3 | 8 |
Messaging | 4 | 16 |
Feedback | 5 | 32 |
a defines if Font Awesome CSS needs to be inserted by PiSuite into your website. If 1, then https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css is included in the website. The default value is 0.
b defines if Bootstrap needs to be inserted by PiSuite into your website. The default value is 0. If 1, then https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js and https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css are included in the website.