Calling JS Service

Importing JS File

In webOS TV SDK v2.0.0 or later, bootplate-web template contains the webOS library in its webOSjs-0.1.0 directory. You can add this library to your app as below:

<script type="text/javascript" src="webOSjs-0.1.0/webOS.js"></script>

If you use webOS TV SDK v1.2.0 or import already existing web app, follow next steps: 

  1. Download the compressed library file from here. Then, unzip

  2. In your app project, create a subfolder named webOSjs-0.1.0 and copy the downloaded webOS.js into the lib folder. The webOS library file can be placed in any folder within your app project. You should set the proper directory when including the library in the source code. 

  3. Include the webOS library in your app as above.

From webOS TV 4.0, we provide webOSTV.js library instead of the webOS.js library. For more details about webOSTV.js, see the webOSTV.js guide. 

Calling Services from Any Web App

Any application can include webOS.js and make webOS service calls using the webOS.service.request method.

To call a service in an app developed without Enyo, use webOS.service.request.

var subscribeStatus = true; //change this to false to disable subscription 
var resubscribeStatus = true; //change this to false to disable resubscription 

var request = webOS.service.request("luna://com.mycom.helloworld/", {
	parameters: {  
	onSuccess: function(inResponse) {  
	onFailure: function(inError) {  
	onComplete: function(inResponse) {  
	subscribe: subscribeStatus,
	resubscribe: resubscribeStatus

See HelloWorld Service (Any Web App) for the code sample. 

Calling JS Services from Enyo 

Create an enyo.LunaService kind with the information of the service that you want to use.

	name: "HelloWorldService",
	kind: "enyo.LunaService",
	service: "luna://com.mycom.helloworld/",
	method: "Hello",
	onComplete: "ServiceResponse"

Call the registered method by using send method.


See HelloWorld Service (Enyo App) for the code sample. 

Calling Service from another Service

Any service can include webOS.js and make webOS service calls using the method.

Example of how a webOS service can be called using webOS.js

var Service = require('webos-service'); 
var service = new Service("com.palm.service.helloworld");
service.register("hello", function(message) {"luna://com.palm.connectionmanager/getstatus", {}, function(response) {
        if(response.payload.isInternetConnectionAvailable == true) {
            // ...
                "returnValue": true

For more detail about the webos-service module, see webos-service API Reference.

Storing and Sharing Data
JavaScript services run inside a "jail," or the permissions-restricted environment. Whenever a jailed service runs, it should always have the same user ID so that it can access files it wrote the last time it ran, but it can't access files created by other apps or services. If a service is expected to share its data with other apps or services, it must provide methods that will allow apps and other services to query and/or update its data. Data stored by a service should be saved to /media/internal.

Do Not

  • Services should not run for very long periods of time (minutes) primarily because of the cost of memory.

  • Don't use the synchronous API from node.js