Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
console.log('PulsarFSL: dispatchToHomeApp handler added.'); 

////////////////////////////////////////////////////////////////////////
// Registration for dispatchtohomeapp handling is a two step process. //
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
// Step 1: add a special handler to the bridge                        //
// * Note: We use camelCase when sending the dispatchToHomeApp        //
// message.                                                           //
////////////////////////////////////////////////////////////////////////
this.bridge.addHandler('dispatchToHomeApp', function (dataObject: object) => {
  if (dataObject.hasOwnProperty("action")) {

    let action = dataObject['action'];
    let parameters = dataObject.hasOwnProperty('parameters') ? dataObject['parameters'] : {};

    // Handle all the actions you want here //
    // goHome and view are special examples //
    switch (action) {
      case 'goHome': yourCustomGoHomeHandler(); break;
      case 'view': yourCustomViewHandler(parameters); break;
      default:
        break;
    }
  }
});

////////////////////////////////////////////////////////////////////////
// Step 2: Use the registerdispatchtohomeapp API to inform the native //
// Pulsar app that your homeApp would like to handle messages from    //
// dispatchtohomeapp calls from all custom documents.                 //
////////////////////////////////////////////////////////////////////////
let registrationRequest = {
  type: 'registerdispatchtohomeapp',
  object: '',
  data: {
    enabled: "TRUE",
    actions: [
      'goHome',
      'view'
    ],
  },
}

pulsarBridge.sendRequest(registrationRequest, function (result) {
  if (result.type == 'registerdispatchtohomeappResponse') {
    console.log("HomeApp: Registered to handle dispatchToHomeApp actions: " + actionsToHandle);
  } else {
    console.log("HomeApp: FAILED to register to handle dispatchToHomeApp actions: " + actionsToHandle);
  }
});