Guest User

Untitled

a guest
May 25th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. // A rough sketch of how a NodeJS service might look
  2. // Take 2 - keep services flat.
  3.  
  4. service = require('browserplus').service;
  5. log = require('browserplus').log;
  6.  
  7. service.name = "HelloWorld";
  8. service.version = "1.0.1";
  9. service.doc = "A hello world service for BrowserPlus";
  10.  
  11. // A hook that is called just after the service is loaded
  12. service.atStartup = function() {
  13. log('info', "we're starting up!");
  14. };
  15.  
  16. // A hook that is called just before the service is unloaded
  17. service.atShutdown = function() {
  18. log('info', "we're shutting down!");
  19. };
  20.  
  21. // initialize is a reserved word and is the constructor, invoked
  22. // when a page allocates an instance of this service
  23. service.initialize = function(args) {
  24. log('info', "new session started for " + args.uri);
  25. };
  26.  
  27. function myPrivateFunc() {
  28. // functions not exported are not visible
  29. // outside of this module
  30. }
  31.  
  32. // exported below so it can be called through browserplus
  33. function hello(trans, arg) {
  34. // args is how you can access arguments. callback arguments
  35. // are proper objects that support an "invoke" method
  36. args.cb.invoke("Hi there " + args.who);
  37. trans.complete("hello " + args.who);
  38. };
  39.  
  40. // first param is function to be exported
  41. // second param is function doc
  42. // third param+ is argument doc
  43. service.export(
  44. hello,
  45. "A function that says hello",
  46. "<name: string> the person's name",
  47. "[greeting: string] the optional greeting (defaults to Hello)",
  48. "[cb: callback] the function to invoke with the greeting"
  49. );
Add Comment
Please, Sign In to add comment