Note The Enact framework includes a webOS support module for interfacing with LS2. To call LS2 API in the Enact framework, please refer to the Luna Service API in the Enact documentation.
webOS OSE 2.0 or higher
webOS OSE 2.0 or higher provides WebOSServiceBridge, a built-in JavaScript API for web apps to access Luna Bus.
You can use the WebOSServiceBridge API to call LS2 API methods in your web app.
On webOS OSE 1.x, using the webOS library lets you call LS2 API methods in your web app.
For details on how to prepare the webOS library, see the Appendix.
After including the webOS library, use the webOS.service.request method as below in order to call LS2 API.
var subscriptionStatus =true; //change this to false to disable subscription
var request = webOS.service.request("luna://com.webos.service.<required_service>/", {
method:"<method_to_call>",
parameters: {
foo:"bar" },
onSuccess:function(inResponse) {
//....
},
onFailure:function(inError) {
//....
},
subscribe: subscriptionStatus
});
Identify the ACG Group of the Methods
You need to identify the ACG (Access Control Groups) information for the methods being used.
Find out the ACG information using the ls-monitor command with the -i option.
$ ls-monitor -i com.webos.service.<required_service>
METHODS AND SIGNALS REGISTERED BY SERVICE 'com.webos.service.<required_service>' WITH UNIQUE NAME '********' AT HUB
"/":
...
"<method_to_call>": {"provides:["group1","group2"]}
...
Specify the Permissions for Using the Methods
In your web app project, add the requiredPermissions property to the appinfo.json file and specify the ACG information of the methods on the property.
You need to iterate the steps above for each LS2 API method used in your web app.
After you finish implementing the web app, proceed with the rest of the development process to build and run your app.
Appendix: Preparing webOS libarary for webOS OSE 1.x
In webOS OSE 1.x, the webOS library (webOS.js) is required in order to call LS2 API method from a web app.
Note If you create a web app using the “basic” template of the Command-Line Interface (CLI) tool, the web app will already contain the webOS library in its webOSjs-0.1.0 directory and have the library included in the index.html file. In this case, you don’t need to add additional code to import the library, so you can safely skip this step.
To include the library in a web app, follow the steps below:
Download the webOS library file from webOSjs-0.1.0.zip and decompress it to the project root directory. The following directory will be created:
webOSjs-0.1.0
├── LICENSE-2.0.txt
└── webOS.js
In the index.html file, include the webOS library with the following code.
Note The webOS library file can be placed in any folder within your app project, but you must set the proper directory when including the library in the source code.