IGlobalContext

IGlobalContext enables you to listen to application-level events and perform application-level operations. For example, listening to context open, context close, and so on.

To get the reference to GlobalContext, you can use the getGlobalContext function. This function provides a reference to the application globalContext.

The following code sample shows the syntax for getGlobalContext method:
getGlobalContext(): Promise<IGlobalContext>;
The following is a code sample Typescript:
/// <reference path="uiEventsFramework.d.ts"/>
    const frameworkProvider: IUiEventsFrameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID', 'v1');
    const globalContext: IGlobalContext = await frameworkProvider.getGlobalContext();
The following is a code sample in JavaScript:
const frameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID', 'v1');
    const globalContext = await frameworkProvider.getGlobalContext();

Functions

Here's a list of the supported functions:
  • subscribe
  • subscribeOnce
  • publish
  • dispose
  • getSupportedEvents
  • getSupportedActions

subscribe

Use this API to subscribe to an event from the Fusion application. Using this API, the external application can listen to the application level events from the the Fusion application. Once an event is subscribed using this API, an external application will be notified until the subscription is disposed.

The following code sample shows the syntax for subscribe:
subscribe: (payload: IEventSubscriptionPayload, callbackFunction: (response:IEventResponsePayload) => void)
=> ISubscriptionContext;
Here are the parameters:
Parameter Required? Description
payload Yes Request object for the event being subscribed to.
callbackFunction Yes A callback function where we get the event response as its arguments.
The following is a code sample in Typescript:
/// <reference path="uiEventsFramework.d.ts"/>
    const frameworkProvider: IUiEventsFrameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID''v1');
    const globalContext: IGlobalContext = await frameworkProvider.getGlobalContext();
    const payload: IEventRequest = frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusTabCloseEvent');
    const subscriptionContext: ISubscriptionContext  = globalContext.subscribe(payload, (response: IEventResponse) => {
         // custom code
     });
The following is a code sample in JavaScript:
const frameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID''v1');
    const globalContext = await frameworkProvider.getGlobalContext();
    const payload = frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusTabCloseEvent');
    const subscriptionContext  = globalContext.subscribe(payload, (response) => {
        // custom code
    });

subscribeOnce

Use this API to subscribe to a the Fusion application event just once. Using this API, external applications can listen to the application level events from the the Fusion application. But this subscription will be disposed of automatically after the first notification.

The following code sample shows the syntax for subscribeOnce:
subscribeOnce: (payload: IEventSubscriptionPayload, callbackFunction: (response: IEventResponsePayload) => void => ISubscriptionContext;
Here are the parameters:
Parameter Required? Description
payload Yes Request object for the event being subscribed to.
callbackFunction Yes A callback function where we get the event response as its arguments.
The following is a code sample in Typescript:
/// <reference path="uiEventsFramework.d.ts"/>
    const frameworkProvider: IUiEventsFrameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID''v1');
    const globalContext: IGlobalContext = await frameworkProvider.getGlobalContext();
    const payload: IEventRequest = frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusTabCloseEvent');
    const subscriptionContext: ISubscriptionContext  = globalContext.subscribeOnce(payload, (response: IEventResponse) => {
         // custom code
    });
The following is a code sample in JavaScript:
const frameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID''v1');
    const globalContext = await frameworkProvider.getGlobalContext();
    const payload = frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusTabCloseEvent');
    const subscriptionContext  = globalContext.subscribeOnce(payload, (response) => {
        // custom code
    });

publish

This API can inform the Fusion application to operate. The API returns a promise to which you can add a then-catch block. The then block would return the operation's status and any data returned after the process is completed.

The following code sample shows the syntax for subscribeOnce:
publish: (requestObject: IOperationRequest) => Promise<IOperationResponse>;
The following is a code sample in Typescript:
/// <reference path="uiEventsFramework.d.ts"/>
    const frameworkProvider: IUiEventsFrameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID''v1');
    const globalContext: IGlobalContext = await frameworkProvider.getGlobalContext();
    const payload: IEventRequest = frameworkProvider.requestHelper.createPublishRequest('cxEventBusCustomEventOperation');
    globalContext.publish(payload).then((response: IOperationResponse)=>{
        // custom code
    }).catch((error)=>{
        // error
    })
The following is a code sample in JavaScript:
const frameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID''v1');
const globalContext = await frameworkProvider.getGlobalContext();
const payload = frameworkProvider.requestHelper.createPublishRequest('cxEventBusCustomEventOperation');
globalContext.publish(payload).then((response) => {
    // custom code
}).catch((error) => {
    // error
})

dispose

This API can dispose or unregister any subscriptions that's added for an event. By disposing the subscription, the API will not trigger any further notifications to the client side receiver.
dispose:() => void;
The following code sample shows an example in typescript for dispose API.
/// <reference path="uiEventsFramework.d.ts"/>
const frameworkProvider: CX_SVC_UI_EVENTS_FRAMEWORK.IUiEventsFrameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID''v1');
const globalContext: CX_SVC_UI_EVENTS_FRAMEWORK.IGlobalContext = await frameworkProvider.getGlobalContext();
const requestObject: CX_SVC_UI_EVENTS_FRAMEWORK.IEventRequest = uiEventsFrameworkInstance.requestHelper.createSubscriptionRequest('cxEventBusContextCloseEvent');
const subscriptionContext:  CX_SVC_UI_EVENTS_FRAMEWORK.ISubscriptionContext  = globalContext.subscribe(requestObject, (response: CX_SVC_UI_EVENTS_FRAMEWORK.IEventResponse) => {
     // custom code
 });
globalContext.dispose();
The following code sample shows an example in Javascript for dispose API.
const frameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID''v1');
const globalContext = await frameworkProvider.getGlobalContext();
const requestObject = uiEventsFrameworkInstance.requestHelper.createSubscriptionRequest('cxEventBusContextCloseEvent');
const subscriptionContext  = globalContext.subscribe(requestObject, (response: CX_SVC_UI_EVENTS_FRAMEWORK.IEventResponse) => {
// custom code
});
globalContext.dispose();

getSupportedEvents

This method returns all the supported events on top of globalContext.

The following code sample shows the syntax for getSupportedEvents:
getSuportedEvents(): string[];
The following code sample shows example for getSupportedEvents in Javascript.
/// <reference path="uiEventsFramework.d.ts"/>
const frameworkProvider: CX_SVC_UI_EVENTS_FRAMEWORK.IUiEventsFrameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID''v1');
const globalContext = await frameworkProvider.getGlobalContext();
const supportedEvents= globalContext.getSupportedEvents();

getSupportedActions

This method returns all the supported actions on top of globalContext.

The following code sample shows the syntax for getSupportedActions:
getSupportedActions(): string[];
The following code sample shows example for getSupportedActions in Javascript.
/// <reference path="uiEventsFramework.d.ts"/>
    const frameworkProvider: IUiEventsFrameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID''v1');
    const globalContext: IGlobalContext = await frameworkProvider.getGlobalContext();
    const supportedActions: string[] = globalContext.getSupportedActions();

getGlobalContextId

This method returns all unique context id of the GlobalContext object..

The following code sample shows the syntax for getGlobalContextId:
getGlobalContextId(): string;
The following code sample shows example for getSupportedActions in Javascript.
const frameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID''v1');
const globalContext = await frameworkProvider.getGlobalContext();
const globalContextId = globalContext.getGlobalContextId();

UI Events Framework actions on GlobalContext for multiple browser tabs

UI Events Framework supports four different contexts such as GlobalContext, TabContext and RecordContexts and PhoneContext. If you listen to an event that's supported on GlobalContext, you can get its notification whenever this event is originated from any of the browser tabs which are loaded with the application.

However, for actions, an action performed on top of globalContext,would be executed only on the current browser tab. So, there's different behavior with globalContext for events and for actions.

There are also some use cases where you could perform an action on every browser tab. This might not return the results you expect. Using CustomEvent, PopUp, Modal and GetAgentInfo are the actions supported on GlobalContext can perform in multiple browser tabs in a single action publish.

Publishing an action from globalContext works in the following way.
  1. If there are multiple browser tabs opened, then the operation request is sent to all the browser tabs if user sets the setPropagateToTabs method to True
  2. The client who requested this action will get positive feedback only when all the browser tabs successfully mark this request as completed.
  3. The client then receives an array of IOperationResponse in the publish request's then-block, instead of getting a single response as before.
  4. Each entry in the OperationResponse array will contain the context of each browser tab in which it was executed and the corresponding response data.
  5. The catch block is executed when any one of the browser tab rejects this action request.
    Note: The response structure will be same as in previous releases, for actions in TabContext and RecordContext. Only GlobalContext level action response will be changed to array of IOperationResponse.