0

We have an Aura component that contains a Canvas App. The Canvas App uses the Canvas SDK to publish events.

This is my Aura component's controller...

({
  doInit: function (component, event, helper) {
    helper.setParameters(component);

    // Listen for messages posted to the window
    window.addEventListener('message', function (message) {
      if (!message.data || typeof message.data !== 'string') return;
      try {
        const data = JSON.parse(message.data);

        if (!data.body || !data.body.event || !data.body.event.name || !data.body.event.payload) return;

        const eventName = data.body.event.name;
        const payload = data.body.event.payload;

        if (eventName === 'ns.showAlert') {
          var alertLwc = component.find('alertLwc');
          if (alertLwc) {
            alertLwc.showAlert(payload);
          }
        }
      } catch (e) {
        console.log(message.data, e.message);
      }
    });
  }
});

Is this the right way to receive a Canvas App published event? Seems like it works but I was wondering if could have used the Aura event approach instead.

0

You must log in to answer this question.