App Lifecycle
#
Starting the appThe 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 valueThe 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:
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 readyYour 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:
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 scenarioIf 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.
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 appIn 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:
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 durationAs 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.
enplug.appStatus.setCanInterrupt(false);
Once your app is ready to be taken offscreen, set it back to true:
enplug.appStatus.setCanInterrupt(true);
See more: enplug.appStatus.setCanInterrupt()
#
Summary- When the Player decides it is time to run your app, it will run a new instance of it in a new iframe automatically.
- Fetch the asset's value by calling
enplug.assets.getNext()
. - Your app should prepare the content and then call the
enplug.appStatus.start()
method. - If an error happens, use
enplug.appStatus.error()
. - The app will be hidden automatically after the time specified in
asset.Duration
passes, if it was provided. - In other cases, you can use
enplug.appStatus.hide()
andenplug.appStatus.setCanInterrupt()
methods to control when the app can be hidden.