Overview

Version added 07-Mar-2018| Modified 04-May-2018

Web apps built for a webOS device are similar to standard web apps that use web-based technologies like HTML, CSS, and JavaScript. Any developer with experience in building web apps can easily start developing web apps for webOS OSE.

Let us understand some webOS-specific concepts.

 

Managing Web Apps

The webOS system provides the following app management services:

  • SAM (System and Application Manager) - Oversees the behavior of apps and manages each app throughout its lifecycle, including the installation, launch, termination, and removal of the app.  

  • WAM (Web Application Manager) - Responsible for launching and managing web apps.

For details, please see Architecture and App Lifecycle.

 

Packaging/Delivering Web Apps

In a webOS system, a web app can be packaged/delivered as follows:

  • Added in webOS image – The web app is built into the webOS image. This approach is used by platform developers to enhance the functionality of the platform. For details, see Creating a Built-in Web App.

  • Installed on webOS device – The web app is installed on the webOS target device. This approach helps 3rd party application developers to create web apps for webOS devices. For details, see Creating an Installable Web App.

 

Calling webOS Services in Web Apps

Web apps built for webOS devices can provide enhanced functionality by leveraging the APIs provided by webOS services. Let us understand this with a sample code that prints a hello message and also prints the current time on the console.

Prerequisite: Download the webOS library file from webOSjs-0.1.0.zip and decompress it to the source code directory. This library is required to call LS2 API.
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
                width: 100%;
                height: 100%;
                background-color: #202020;
}
div {
            position:absolute;
                height:100%;
                width:100%;
                display: table;
}
h1 {
            display: table-cell;
                vertical-align: middle;
                text-align:center;
                color: #FFFFFF;
}
</style>
        <script src="webOSjs-0.1.0/webOS.js" charset="utf-8"></script>
        <script type="text/javascript">
        //sample code for calling LS2 API
        var lunaReq= webOS.service.request("luna://com.webos.service.systemservice",
        {
            method:"clock/getTime",
            parameters:{},
            onSuccess: function (args) {
                                console.log("UTC:" + args.utc);
            },
            onFailure: function (args) {
            }
        });
        </script>
</head>
<body>
        <div>
                <h1>Hello, Web Application!!</h1>
        </div>
</body>
</html>

A brief explanation of the webOS-specific lines of code:

  • Line(22) : Include the webOS.js JavaScript file.

  • Line(23~35) : Define a JS script that calls the luna://com.webos.service.systemservice/clock/getTime method. If it succeeds, it prints the UTC value to console (/var/log/messages file on target).

Except as noted, this content is licensed under Creative Commons Attribution 4.0 and sample code is licensed under Apache License 2.0.