Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A rough sketch of how a NodeJS service might look
- // Take 2 - keep services flat.
- service = require('browserplus').service;
- log = require('browserplus').log;
- service.name = "HelloWorld";
- service.version = "1.0.1";
- service.doc = "A hello world service for BrowserPlus";
- // A hook that is called just after the service is loaded
- service.atStartup = function() {
- log('info', "we're starting up!");
- };
- // A hook that is called just before the service is unloaded
- service.atShutdown = function() {
- log('info', "we're shutting down!");
- };
- // initialize is a reserved word and is the constructor, invoked
- // when a page allocates an instance of this service
- service.initialize = function(args) {
- log('info', "new session started for " + args.uri);
- };
- function myPrivateFunc() {
- // functions not exported are not visible
- // outside of this module
- }
- // exported below so it can be called through browserplus
- function hello(trans, arg) {
- // args is how you can access arguments. callback arguments
- // are proper objects that support an "invoke" method
- args.cb.invoke("Hi there " + args.who);
- trans.complete("hello " + args.who);
- };
- // first param is function to be exported
- // second param is function doc
- // third param+ is argument doc
- service.export(
- hello,
- "A function that says hello",
- "<name: string> the person's name",
- "[greeting: string] the optional greeting (defaults to Hello)",
- "[cb: callback] the function to invoke with the greeting"
- );
Add Comment
Please, Sign In to add comment