Versions Compared

Key

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

...

The two actions we demonstrate here are actions that are triggered through common events in the native Pulsar UI. Your custom home app may want to respond to these as well. If your custom home app has registered for dispatchtohomeapp, any tap on a native Pulsar Home Button will fire the ‘goHome’ action. Similarly, when a deep link is opened in Pulsar, the “view” action will be fired with the object type and Id in the parameters of that call. Your custom home app may wish to respect any of these actions.

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', (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);
  }
});