Skip to main content

App Lifecycle

Starting the app#

The apps are started automatically by the Enplug Player. Once the Player decides it is time to present certain asset of your app, a new iframe with a new instance of your app will be prepared in the background. Each time a new asset is to be displayed, a new instance/iframe with your app will be instatiated. The URL provided in the app's Player URL field when creating the app will be used. You can edit this URL by editing your app in the 'My Apps' section in the dashboard.

Fetching the asset's value#

The Player created a new iframe with a new instance of your app. Now your app should prepare the content to display.

Your app can fetch the asset's value by using:

Fetching the asset's value
const assetValue = await enplug.assets.getNext();

See more: enplug.assets.getNext()

This will give you the asset.Value which contains all the customizations saved in the dashboard part of your app.

Informing that your app is ready#

Your app should preload all images, fonts, etc. and perform all layout calculations prior to displaying it to the screen, so there is no flickering or jumping seen on the screen. Once your app is ready to be displayed, it should inform the Player about this fact by calling the following code:

Telling the Player that the app is ready to be displayed
enplug.appStatus.start();

See more: enplug.appStatus.start()

Calling the start() method informs the Player that the app is ready to be displayed, however it does not guarantee that it will be displayed immediately. The returned Promise will resolve after the app gets shown on screen.

Error scenario#

If there was an error when preloading the data or any other issue which does not allow the app to present any user-friendly content you can inform the Player about an error.

Informing the Player about an error
enplug.appStatus.error('Could not preload images');

See more: enplug.appStatus.error()

This will inform the Player that the asset cannot be displayed and this instance of your app should be disposed.

Hiding the app#

In most cases the Player will automatically hide the app after the time set using the asset.Duration adjusted in the Deploy Dialog when saving the asset. So, in most apps, you do not need to handle hiding the app in any way as it will happen automatically.

If the asset does not have a specific duration set or the app wants to be hidden earlier than specified in the duration field it can call:

Hiding the app
enplug.appStatus.hide();

See more: enplug.appStatus.hide()

This will inform the Player that the app should be hidden as soon as possible. It might not happen immediately as the Player needs to prepare and have another app ready.

Custom duration#

As mentioned in Hiding the app, your asset can have no duration set. This happens when the asset is saved with the showDuration flag set to false in the scheduleOptions passed as DeployDialogOptions to the enplug.account.saveAsset() method.

This is useful if your app displays a video or some other content with unpredictable duration.

In such case, after your app starts you should inform the Player that the app should not be interrupted by another application and taken offscreen.

Inform the Player that the app should not be interrupted
enplug.appStatus.setCanInterrupt(false);

Once your app is ready to be taken offscreen, set it back to true:

Inform the Player that the app can now be taken offscreen
enplug.appStatus.setCanInterrupt(true);

See more: enplug.appStatus.setCanInterrupt()

Summary#