Application management examples

[THIS SHOULD BE MOVED INTO THE DEVELOPER GUIDE]

Declaring an Application Manager

The oipfApplicationManager embedded object must be declared in the body on the HTML document of the HbbTV application, before it can be accessed.

<object type="application/oipfApplicationManager" id="applicationManager"> </object>

Locating the Application object

The ApplicationManager object provides the getOwnerApplication() method, which returns the document’s owning application:

const appMgr = document.getElementById("applicationManager");
const appObject = appMgr.getOwnerApplication(document);

All other application functionality is available from this object.

Make an application visible

A typical requirement on an application is to only become visible once it has fully loaded. To do this, it can take advantage of load events. Here is an example from a clock application, which wants to load an image to become the background of the clock, upon which it can write the text of the clock.

<script>
function loaded() {

    const screen = document.defaultView.screen;
    const clock = document.getElementById('clock');

    setup_clock( clock.width, clock.height );

    // Assumes that the application/oipfApplicationManager object has the ID 
    // “applicationManager”
    const appMgr = document.getElementById("applicationManager");
    const appObject = appMgr.getOwnerApplication(document);
    appObject.show();
}
</script>

<style> * { margin: 0cm } </style>

<body onload="loaded()">
   <div>
        <object type="application/oipfApplicationManager" id="applicationManager"> </object>
        <object type="application/oipfCapabilities" id="capabilities"></object>
        <object type="application/oipfConfiguration" id="configuration"></object>
   </div>
   <img id="clock" src="clockbackground.png" style="position: absolute; 
     top: 0px; left=0px">
</body>