JavaScript Service FAQ

Q1. How do I test my service?
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. For information about using the CLI to debug a JS service, see Launch Node Inspector.

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

For more information on using node-inspector, refer to 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:

  • It has a subscription taken on it from another application or service

  • It has received a message that it has not yet responded to using `message.respond()`.

Q4. Why does my service never exit?

Consequently, if your service continues running when it should have already exited, there are several possible causes. It may have received a message for which it never called `respond()`, have an outstanding subscription from another service, or be stuck in an infinite loop.

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

There will be an 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 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 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 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 name under which the service is registered.