Publish Custom Event on GlobalContext
Here's a TypeScript example for adding custom event publish request on
GlobalContext:
const publishCustomEvent = async () => {
const frameworkProvider: IUiEventsFrameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID','V1');
const payload: ICustomEventRequest = frameworkProvider.requestHelper.createPublishRequest('CustomEvent') as ICustomEventRequest;
payload.setCustomEventName('customEventName');
payload.setEventPayload({ message: 'any data' });
const globalContext: IGlobalContext = await frameworkProvider.getGlobalContext();
globalContext.publish(payload).then((message: IOperationResponse) => {
const response: ICustomEventResponse = message as ICustomEventResponse;
console.log(response.getResponseData());
console.log(response.getResponseData().getData());
console.log(response.getResponseData().getCustomEventName());
}).catch((err) => {
console.log(err);
});
};
Here's a JavaScript example:
const publishCustomEvent = async () => {
const frameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID','V1');
const payload = frameworkProvider.requestHelper.createPublishRequest('CustomEvent');
payload.setCustomEventName('customEventName');
payload.setEventPayload({ message: 'any data' });
const globalContext = await frameworkProvider.getGlobalContext();
globalContext.publish(payload).then((message) => {
console.log(message.getResponseData());
console.log(message.getResponseData().getData());
console.log(message.getResponseData().getCustomEventName());
}).catch((err) => {
console.log(err);
});
};