How to use the iframe integration library
Web Portal provides front-end APIs to manage navigation events, receive user information, send notifications and more. A comprehensive documentation is available to provide details on how these APIs work in conjunction with the iframe integration library.
Iframe integration library
The API is accessible through the plain JavaScript NPM library @bci-portal/iframe-integration
. While, all communication goes through the browser’s postMessage
API and could be implemented manually, it is mandatory to use the iframe-integration library (IIL). This library handles correct initialization and ensures secure communication between the two parties.
The library’s major and minor version is aligned with the Web Portal version.
Installation
The library is currently only accessible to Bosch Developers. Efforts are underway to make it available in a more widely accessible manner, along with the appropriate licensing. |
@bci-portal/iframe-integration is available in Bosch Cloud Artifactory.
Add library with yarn/npm
# Yarn
yarn add @bci-portal/iframe-integration
# NPM
npm install @bci-portal/iframe-integration
Initialization
During the initial start-up of your application, Web Portal or the view with an embedded view, will communicate the way a view will be using the postMessage API during an initial handshake between them.
Example for an Angular AppModule
// providers
{
provide: APP_INITIALIZER,
useFactory: IFrameLibraryInitFactory.initialize,
deps: [Location],
multi: true,
},
// the factory
export class IFrameLibraryInitFactory {
public static initialize(location: Location): () => Promise<void> {
return async (): Promise<void> => {
await IframeIntegrationLibrary.init();
if (IframeIntegrationLibrary.isFeatureAvailable('urlChange')) {
location.onUrlChange(() => IframeIntegrationLibrary.urlChange());
}
};
}
}
Example for static HTML or server side rendered sites, simply call urlChange() on startup and whenever JavaScript is altering the URL or history.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Some static site</title>
</head>
<body>
<!-- your content -->
<script src="iframe-integration/index.bundle.js"></script>
<script>
await iframeIntegration.IframeIntegrationLibrary.init();
iframeIntegration.urlChange();
</script>
</body>
</html>
URL updates
The URL in the iframe typically changes frequently, such as when the user navigates within the module or updates filter states in the URL. Due to the iframe sandbox, Web Portal is unable to read the current URL of the iframe and must be informed by the module. This allows Web Portal to update the navigation menu, header title, and its own URL. If Web Portal is not informed about the current URL, it may become out of sync with the content area, and deep-linking will not function properly.
To inform Web Portal about the current URL, utilize the IframeIntegrationLibrary.urlChange()
function for all navigation events inside the module.
Simply call the function as demonstrated in the examples above, and it will handle the rest of the process.
Usage of Functionality
This code block demonstrates how to use the iframe-integration library in a TypeScript project, calling one of the provided functions.
Example for TypeScript
import { IframeIntegrationLibrary } from '@bci-portal/iframe-integration'; // import the view module
IframeIntegrationLibrary.showMessage('My Title', 'success', 'My Description'); // display a toast banner, using the common API
Functionalities
Starting with version 5.10, Web Portal performs a handshake with the application during iframe initialization to inform it about the host it will communicate with and how the view is currently being displayed within the application.
This enables the use of a common API called IframeIntegrationLibrary. This new common API allows developers to be informed of how and where their view is being used, and which features are currently available. Below is a list of functionalities, their descriptions, where they are available, and code examples.
Function | Description | Available for | Example | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
init |
Sets up the view so that it can be made aware of how it is being used, and is used to establish a trusted connection with Web Portal.
|
View |
Iframe Integration Library
|
|||||||||||||||
initWidget |
Set up a widget with or without settings
|
View |
Iframe Integration Library
|
|||||||||||||||
initWidgetSettings |
This function is used to set up a widget settings instance, including what is returned when widget settings are queried about setting state. It should be implemented when a widget requires more than the default settings, such as width and height.
|
View |
Iframe Integration Library
|
|||||||||||||||
getMode |
This function returns the mode in which the module view is currently being used. Depending on the mode, different features are available (see the "Available for" column of this documentation or use 'isFeatureAvailable' of the iframe integration library). Modes supported by Web Portal:
|
View |
Iframe Integration Library
|
|||||||||||||||
isFeatureAvailable |
Returns a boolean value, indicating if a feature from IframeIntegrationLibrary is available or not.
|
View |
Iframe Integration Library
|
|||||||||||||||
setBreadcrumbs |
Inform portal about the current breadcrumbs that should be present in the header of portal. Web Portal will maintain its own breadcrumbs, a module is able to extend it with its own. The full history of the breadcrumbs should always be provided in terms of the module, as they will overwrite what is presented in the portal. If an empty list is given, the breadcrumbs will be reset to the state that is within the portal, and the module’s breadcrumbs will be removed.
|
View |
Iframe Integration Library
|
|||||||||||||||
getUserSettings |
Return a user setting value defined by any module. Asynchronously returned as a promise, so that caching mechanisms are transparent for the SCS UIs.
|
View |
Iframe Integration Library
|
|||||||||||||||
getCookieSettings |
Return the cookie settings that the user has chosen in the cookie dialog. User settings and other data that is not technically necessary are only to be stored to local storage/cookie if the comfort cookie setting is set to true! |
View |
Iframe Integration Library
Example Cookie Settings
|
|||||||||||||||
showMessage |
Emit a message to the user e.g. if a update was successful or new data was received.
|
View |
Iframe Integration Library
|
|||||||||||||||
showBanner |
Displays a banner with the passed text and returns a banner id.
|
View |
Iframe Integration Library
|
|||||||||||||||
hideBanner |
Hides a banner which is shown previously with showBanner function.
|
View |
Iframe Integration Library
|
|||||||||||||||
getContextContribution |
The context concept can be used to show data contributed by other modules for a given context.
|
View |
Iframe Integration Library
|
|||||||||||||||
getDataForContextContribution |
The context contribution data can be used by modules (context consumers) to get the data from the context contributor. The default timeout to try and get context contribution data is set to 3s and Web Portal will reject the promise if it didn’t receive the data by this time. The caller of the method has to handle the reject scenario as well.
|
View |
Iframe Integration Library
Note: the data returned depends on the context contributor |
|||||||||||||||
getDataForContextContributionResponseFromIframe |
The ContextContributionDataResponseFromIframe can be used by modules (context contributors) to give the data back to Web Portal
|
View |
Iframe Integration Library usage for metadata response
|
|||||||||||||||
showContextMenu |
Displays a context menu next to a certain html element. The context menu will contain links to all SCS views that provide actions for the given context.
Configuring the SCS views from a consumer side, see |
View |
Iframe Integration Library
|
|||||||||||||||
isContextMenuEmpty |
Returns true when no actions are registered for the given context and the context menu would be empty. |
View |
Iframe Integration Library
|
|||||||||||||||
enableBrowserFullscreen |
Enable Browser fullscreen. Returns status of operation (successful or not). It is the only way to trigger browser fullscreen as allowfullscreen attribute is not set on IFrame. |
View |
Iframe Integration Library
|
|||||||||||||||
disableBrowserFullscreen |
Disable Browser fullscreen and returns status of operation (successful or not). |
View |
Iframe Integration Library
|
|||||||||||||||
isBrowserFullscreenEnabled |
Returns if browser is in fullscreen mode or not. |
View |
Iframe Integration Library
|
|||||||||||||||
isBrowserFullscreenEnabled$ |
Returns an observable that one can observe to be informed about browser fullscreen enabled changes. |
View |
Iframe Integration Library
|
|||||||||||||||
enablePortalFullscreen |
Enables Web Portal fullscreen and returns the status of operation (successful or not). Web Portal fullscreen is a maximized mode, where Web Portal hides the navigation sidebar, the header and the footer. The supergraphic stays visible on top. |
View |
Iframe Integration Library
|
|||||||||||||||
disablePortalFullscreen |
Disables Web Portal fullscreen and returns status of operation (successful or not). Web Portal fullscreen is a maximized mode, where Web Portal hides the navigation sidebar, the header and the footer. The supergraphic stays visible on top. |
View |
Iframe Integration Library
|
|||||||||||||||
isPortalFullscreenEnabled |
Returns if Web Portal is in fullscreen mode or not. |
View |
Iframe Integration Library
|
|||||||||||||||
isPortalFullscreenEnabled$ |
Returns an observable that one can observe to be informed about portal fullscreen enabled changes. |
View |
Iframe Integration Library
|
|||||||||||||||
getDashboardWidgetsMetaData |
Returns available widget metadata to modules which integrate via Iframe |
View |
Iframe Integration Library
Example Widget Meta Data
|
|||||||||||||||
embedView |
Show an iframe view from another module
How placeholders are treatedPlaceholder in the path Such placeholders are considered mandatory and if not provided Web Portal will simply do nothing.
Placeholder in the query parameters Such placeholders are considered optional and if not provided are removed from the URL.
Values for not existing placeholders Web Portal ignores all values that are provided and no placeholder is present.
|
View |
Iframe Integration Library
|
|||||||||||||||
listenToEmbeddedView |
Listen for events from an embedded view that is loaded into the page.
|
View |
Iframe Integration Library
|
|||||||||||||||
sendEventToEmbeddedView |
Send an event to the embedded view, optionally data can be included
|
View |
Iframe Integration Library
|
|||||||||||||||
requestBrowseToLink |
Request Web Portal to navigate to given contribution of type link by its id
|
View |
Iframe Integration Library
|
|||||||||||||||
informHostViewWithCallback |
Used to send a custom event where you expect a reply from the host view
|
View |
Iframe Integration Library
|
|||||||||||||||
informHostView |
Used to send a custom event from an embedded view to its host view.
|
View |
Iframe Integration Library
|
|||||||||||||||
showViewInDialog |
Requests Web Portal to show a specific view in a dialog. showViewInDialog returns a promise that is fulfilled with data provided by the view when the dialog is closed. See closeDialog for an example on how to pass data to the dialog opener.
|
View |
Iframe Integration Library
|
|||||||||||||||
closeDialog |
Requests Web Portal to close the dialog where this view is at the moment shown in.
|
View |
Iframe Integration Library
|