Difference between revisions of "JavaScript Services"

From WebOS Internals
Jump to navigation Jump to search
(Service Initialization)
m (ref to LG docs)
Line 1: Line 1:
'''Some notes to flesh out the [https://developer.palm.com/content/api/dev-guide/js-services/overview.html primary documentation]'''
+
'''Some notes to flesh out the [https://developer.palm.com/content/api/dev-guide/js-services/overview.html old primary documentation]''' and the [http://developer.lge.com/webOSTV/develop/js-services/ new primary documentation]
  
 
== Node versions ==
 
== Node versions ==

Revision as of 19:28, 14 October 2014

Some notes to flesh out the old primary documentation and the new primary documentation

Node versions

  • webOS 1.x: node not present
  • webOS 2.x: node v0.2.3
  • webOS 3.0: node v0.4.12
  • webOS TV: ?
  • LuneOS (webOS 3.5): node v0.10.25


Values returned over the PalmBus

To return a success, set future.result to an object with the desired properties (where future is the future passed to the Command Assistant).

To return a failure, set future.exception to an object (often some kind of Error). Best practice is to set both message and errorCode properties.

(If you set the errorCode property of the object, that will be the errorCode returned over PalmBus, and the errorText will be copied from the message property. Otherwise, errorCode will be -9999 and errorText will be "MojoService: no errorCode supplied "+(reply.errorText||""))


While the Command Assistant run() method is called "inside" the future, it's not clear that you can compose the passed future with others.


Service Initialization

If you have common setup which must be done, regardless of which command is called first, define a Service Assistant

If you return a Future from the Service Assistant's setup method your Command Assistant will not be called until that Future is resolved. If that Future fails, your Command Assistant will never be called, and the service call will eventually time out. So, ensure the Future always succeeds (storing an error if necessary):

MyServiceAssistant.prototype.setup = function () {
	return this.myAsyncMethod().then(function (f) {
		console.log("MyServiceAssistant.setup overall success", f.result);
		return f.result = f.result;
	}, function (f) {
		console.error("MyServiceAssistant.setup overall failure", f.exception);
		f.result = {foo: "bar"};
	});
};