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.
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:
const assetValue = await enplug.assets.getNext();
This will give you the
asset.Value which contains all the customizations saved in the dashboard part of your app.
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:
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.
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.
enplug.appStatus.error('Could not preload images');
This will inform the Player that the asset cannot be displayed and this instance of your app should be disposed.
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:
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.
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
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.
Once your app is ready to be taken offscreen, set it back to true:
- 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
- Your app should prepare the content and then call the
- If an error happens, use
- The app will be hidden automatically after the time specified in
asset.Durationpasses, if it was provided.
- In other cases, you can use
enplug.appStatus.setCanInterrupt()methods to control when the app can be hidden.