service.register("ping", function(message) {
	console.log("Ping! setting up activity");
	var activitySpec = {
	    "activity": {
	        "name": "My Activity", //this needs to be unique, per service
	        "description": "do something", //required
	        "background": true,    // can use foreground or background, or set individual properties (see Activity Specification below, for details)
	        "persist": true,       // this activity will be persistent across reboots
	        "explicit": true,      // this activity *must* be completed or cancelled explicitly, or it will be re-launched until it does
	        "callback": {          // what service to call when this activity starts
	            "method": "luna://@SERVICE-NAME@/pong", // URI to service
	            "params": {        // parameters/arguments to pass to service
	            }
	        }
	    },
	    "start": true,             // start the activity immediately when its requirements (if any) are met
	    "replace": true,           // if an activity with the same name already exists, replace it
	    "subscribe": false         // if "subscribe" is false, the activity needs to be adopted immediately, or it gets canceled
	};
	service.call("luna://com.palm.activitymanager/create", activitySpec, function(reply) {
		var activityId = reply.payload.activityId;
		console.log("ActivityId = "+activityId);
		message.respond({msg: "Created activity "+activityId});
	});
});
service.register("locale", function(message) {
	console.log("locale callback");
	service.call("luna://com.webos.settingsservice/getSystemSettings", {"key":"localeInfo"}, function(m2) {
		var response = "You appear to have your locale set to: " + m2.payload.settings.localeInfo.locales.UI;
		console.log(response);
		message.respond({message: response});
	});
});
Beispiel #3
0
// helloclient.js
// Subscribe & cancel subscription to helloworld's heartbeat service
var Service = require('webos-service');

// Register com.example.helloworld, on both buses
var service = new Service("com.example.helloclient");
console.log("simple call");
	service.call("luna://twitter.com.connect.app.service/hello", {}, function(message) {
	console.log("message payload: " + JSON.stringify(message.payload));
	var sub = service.subscribe("luna://twitter.com.connect.app.service/heartbeat", {subscribe: true});
	var count = 0;
	var max = 10;
	sub.addListener("response", function(msg) {
		console.log(JSON.stringify(msg.payload));
		if (++count >= max) {
			sub.cancel();
			setTimeout(function(){
				console.log(max+" responses received, exiting...");
				process.exit(0);
			}, 1000);
		}
	});
});