Namespace: channel

channel

Manage the communication between AskiaPortal window and the module iFrame.

 // Listen when the user change the language of the interface
 portal.channel.addEventListener("language", (data) => {
     portal.i18n.setConfig({
         languageKey : data.currentLanguage.key
     });
     portal.i18n.reloadUi();
 });


 // Register the action to do when setting the portal info
 let isLoaded = false;
 portal.channel.addEventListener("portalInfo", (data) => {
     if (isLoaded) {
         return;
     }
     isLoaded = true;

     // Configure the internationalization
     portal.i18n.setConfig({
         languageKey : data.currentLanguage.key,
         relativeUrlToPortal: '../../',
         localeUrlFormat: `content/Locale/MyModule.json`
     });

     // Reload the ui
     portal.i18n.reloadUi();

     // Resume the reception of messages
     portal.channel.resume();
 };

 // ===============================
 // Entry point of the application
 // -------------------------------
 // Listen AskiaPortal message
 // ===============================
 portal.channel.listen().then(() => {
     // Indicates that the module is ready
     portal.channel.postMessage({
         type: "appready",
         defaultHash: "Home/" // Default workspace to show if none is specified in the URL
     });
 });
Dependencies:
  • ./js/portal.EventEmitter.js

Methods

(static) Channel#listen()

Listen messages from AskiaPortal. This method usually served as the entry point of AskiaPortal modules.

 portal.channel.listen().then(() => {
     portal.channel.postMessage({
         type: "appready",
         defaultHash: "Home/"
     });
 });

(static) Channel#postMessage(message)

Post a message to AskiaPortal.

 portal.channel.listen().then(() => {
     portal.channel.postMessage({
         type: "appready",
         defaultHash: "Home/"
     });
 });
Parameters:
Name Type Description
message Object | String

Message to send to AskiaPortal.

(static) Channel#postMessageToModule(message)

Post a message to the module.

Parameters:
Name Type Description
message Object | String

Message to send.

(static) Channel#resume()

Resume pending messages. While the module is loading, AskiaPortal accumulate all messages until this method is called.

 portal.channel.listen().then(() => {
     portal.channel.postMessage({
         type: "appready",
         defaultHash: "Home/"
     });

      portal.channel.resume();
 });

Events

changedUserPreferences

When the user preferences has been changed.

Parameters:
Name Type Description
data Object

Data of the event

language

When the channel receive the change language message.

Parameters:
Name Type Description
data Object

Data of the event

message

When the channel receive a message.

Parameters:
Name Type Description
data Object

Data of the event

portalInfo

When the channel receive the message with the AskiaPortal information.

Parameters:
Name Type Description
data Object

Data of the event

redirect

When the channel receive a redirection message.

Parameters:
Name Type Description
data Object

Data of the event

savingUserPreferences

When the user is saving his preferences.

Parameters:
Name Type Description
data Object

Data of the event