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.
getGlobalContext(): Promise<IGlobalContext>;
/// <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 frameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID', 'v1');
const globalContext = await frameworkProvider.getGlobalContext();
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.
subscribe: (payload: IEventSubscriptionPayload, callbackFunction: (response:IEventResponsePayload) => void)
=> ISubscriptionContext;
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. |
/// <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
});
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.
subscribeOnce: (payload: IEventSubscriptionPayload, callbackFunction: (response: IEventResponsePayload) => void => ISubscriptionContext;
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. |
/// <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
});
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.
publish: (requestObject: IOperationRequest) => Promise<IOperationResponse>;
/// <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
})
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
dispose:() => void;
/// <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();
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.
getSuportedEvents(): string[];
/// <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.
getSupportedActions(): string[];
/// <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..
getGlobalContextId(): string;
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.
- 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
- The client who requested this action will get positive feedback only when all the browser tabs successfully mark this request as completed.
- The client then receives an array of IOperationResponse in the publish request's then-block, instead of getting a single response as before.
- Each entry in the OperationResponse array will contain the context of each browser tab in which it was executed and the corresponding response data.
- 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.