/** * Known `client.globalEvent` names for Ameyo AAF iframe apps. * * Primary source: ECC `GlobalEventService.GlobalEventEnum` (eventName strings). * Additional strings appear in some integration docs or legacy UIs — included with comments. */ export interface HasGlobalEvent { globalEvent: { register: (eventName: string, eventCallback: (data: unknown) => void) => Promise; unRegister: (eventName: string, eventCallback: (data: unknown) => void) => void; }; } /** All eventName values from ECC `GlobalEventService.GlobalEventEnum` (Ameyo 4.x). */ export const GWT_GLOBAL_EVENTS_ECC = { campaignSelectionChange: "campaignSelectionChange", customerCallMemberCreated: "customerCallMemberCreated", newChatMessageAdded: "newChatMessageAdded", callRinging: "callRinging", chatDialogFocus: "chatDialogFocus", callConnected: "callConnected", callHungup: "callHungup", customerChatMemberCreated: "customerChatMemberCreated", chatConnected: "chatConnected", chatHungup: "chatHungup", pageVisibilityChange: "pageVisibilityChange", aqRequestAdded: "aqRequestAdded", aqRequestRemoved: "aqRequestRemoved", customerCallMemberDeleted: "customerCallMemberDeleted", userCallMemberDeleted: "userCallMemberDeleted", userCallMemberCreated: "userCallMemberCreated", userStateChange: "userStateChange", callHold: "callHold", missedCallAdded: "missedCallAdded", missedCallModified: "missedCallModified", missedCallRemoved: "missedCallRemoved", crmStateChange: "crmStateChange", voiceCustomerLinked: "voiceCustomerLinked", videoCallRinging: "videoCallRinging", videoCallConnected: "videoCallConnected", videoCallEnded: "videoCallEnded", canDisposeVideoStateChange: "canDisposeVideoStateChange", attachmentAddedInTicket: "attachmentAddedInTicket", attachmentMetadataUpdated: "attachmentMetadataUpdated", customerStateChange: "customerStateChange", callHungupStatus: "callHungupStatus" } as const; /** * Doc / older samples sometimes use these strings instead of the ECC enum value. * Prefer `userStateChange`, `callHold`, `chatHungup` unless you have confirmed behaviour on your build. */ export const GWT_GLOBAL_EVENTS_DOC_ALIASES = { /** Some docs use this for hold; ECC enum is `callHold`. */ callStageHold: "callStageHold", /** Listed alongside `chatHungup` in some globalEvent listings. */ chatEnded: "chatEnded", /** One doc shows register("userStateBreak", …) while the heading says userStateChange; ECC uses `userStateChange`. */ userStateBreak: "userStateBreak", /** Seen in older parent.js samples; voice teardown in GlobalEventEnum is `callHungup`. */ callEnded: "callEnded" } as const; export const GwtGlobalEventNames = { ...GWT_GLOBAL_EVENTS_ECC, ...GWT_GLOBAL_EVENTS_DOC_ALIASES } as const; export type GwtGlobalEventName = (typeof GwtGlobalEventNames)[keyof typeof GwtGlobalEventNames]; /** * Ordered list of `globalEvent` names that the `globalEvent.register` loop in the * SDK Debugger app should subscribe to. * * Only ECC `GlobalEventEnum` entries are included — the doc-only aliases in * {@link GWT_GLOBAL_EVENTS_DOC_ALIASES} (`callEnded`, `chatEnded`, `userStateBreak`, * `callStageHold`) are **not** present in `GlobalEventEnum.values()`, so the host * always answers them with code 121 (`requested data object does not exists`). * Listing them here would create permanent registration-error rows in the UI. */ export const GWT_ALL_GLOBAL_EVENT_NAMES: readonly GwtGlobalEventName[] = [ ...Object.values(GWT_GLOBAL_EVENTS_ECC) ]; export function registerGlobalEvent( client: HasGlobalEvent, eventName: GwtGlobalEventName | (string & {}), callback: (data: unknown) => void ): Promise { return client.globalEvent.register(eventName, callback); } export function unregisterGlobalEvent( client: HasGlobalEvent, eventName: GwtGlobalEventName | (string & {}), callback: (data: unknown) => void ): void { client.globalEvent.unRegister(eventName, callback); }