JS Service FAQ

Q1. How do I test my service?

To test the JS service, see the following articles.

Q2. How do I debug my service?

A useful CLI tool, ares-inspect, included in the SDK enables debugging. Use the following command to launch Node Inspector in your browser for the HelloWorldService example. About using CLI for debugging JS service, you can also find information from Launching Node Inspector.

ares-inspect -d emulator -s com.mycom.helloworldservice.service

 

For more information on using node inspector see their github page. 

Q3. Why does my service quit after 5 seconds, with a "No active activities" message?

There is a 5-second timer built into the webos-service library, which causes services to exit if they're not currently active. For purposes of this timer, a service is considered to be active if either of the following is true:

  1. It has a subscription taken on it from another application or service
  2. It has received a message to which it has not responded yet [with message.respond()] 

Q4. Why does my service never exit?

As a corollary to the above, if your service seems to be hanging around when it should have already quit, there are a couple of possibilities. It may have gotten a message that it never called respond() on, or it may have an outstanding subscription from another service, or it might just be stuck in an infinite loop. 

Q5. How can I change the idle timeout to last longer?

There will be API added to the Service object to support manipulating the timer. For now, you have to do this through the ActivityManager object:

var Service = require("webos-service"); 
var service = new Service("com.example.myservice"); 
service.activityManager.idleTimeout = 15; 
// this timeout is in seconds

Q6. How do I disable the idle timeout permanently?

First, make sure you actually need to do that. In general, you want to work with the standard service lifecycle, rather than against it. In particular, if your service is waiting for a some condition to change, you'd be better off registering an activity with ActivityManager, and having ActivityManager re-launch your service when the conditions are met. The best way to disable the timeout is to create an ActivityManager activity that you keep "live" for the time that you need to service to keep running. This is the best way to do this because it not only causes the timer to be disabled, but will also protect your service from being killed by the ActivityManager, if/when someone enables the idle-task-killing feature of ActivityManager.

// create an Activity 
var keepAlive; 
service.activityManager.create("keepAlive", function(activity) {
	keepAlive = activity; 
}); 
// When you're done, complete the activity 
service.activityManager.complete(keepAlive, function(activity) { 
	console.log("completed activity"); 
});

Q7. When I try to send a message to my service, I get a 'Service does not exist' error, what does that mean, and how can I fix it?

This means that the hub doesn't know about your service. Here are some things to check:

  • Check that the service name in the application exactly matches the service name the service registers under.

 

Navigation