import MessageSubscriber from './message-subscriber'; import UserPresence from './user-presence'; import type { Filter, ConnectionConfig, TokenData, LocalMessagePayload } from './types'; /** * @description * Exposes APIs for websocket Messaging Service. * @public */ declare class MessagingServiceManager { /** * { * "": * } */ static subscribers: { [key: string]: MessageSubscriber; }; static connectionsCount: number; static webSocket: WebSocket | null; static connectionConfig: ConnectionConfig | null; static inProgressSubscriptions: { messageSubscriber: MessageSubscriber; id: string; }[]; static inProgressMessages: Record[]; static isServiceAlive: boolean | null; static serviceAliveHandler: ReturnType | null; static userPresence: UserPresence; static refreshB2SOffset: number; private static tokenExpiryTime; private static reInitInterval?; private static agentSubscribeIdMap; private static filterKeyToSubscriberIdMap; /** Whether the mobile app has offline support enabled (pxUsesOffline in userAgent). */ private static get offlineEnabled(); static isAuthenticated: boolean; private static boundHandleOnOpen; private static boundHandleOnMessage; private static boundHandleOnError; private static boundHandleOnClose; /** * Initializing the connection to message service. * @param config object to initialize connection to messaging service * example: * { * messagingService: "ws://localhost:3000/c11n-msg" * } * @private */ static initConnection(config?: { messagingService?: string; } | null): void; static handleOnError(event: Event): void; static handleOnClose(event: CloseEvent): void; static handleOnOpen(): void; static unsubscribeAgentMessageCaseValues(dispatchData: { caseKey: string; assignmentID: string; actionInContext: string; }): void; static subscribeAgentMessageCaseValues(dispatchData: { caseKey: string; assignmentID: string; actionInContext: string; }): void; static handleOnMessage(event: { data: string; }): void; /** * Dispatches a message to all subscribers whose filter matches the given matcher and criteria. * Shared by both WebSocket message handling and local message dispatch. * @param matcher - the filter matcher string (e.g. "DATAPAGE_UPDATED", "CASE") * @param criteria - the filter criteria to match against subscriber filters * @param data - the message data to pass to matched subscriber handlers * @private */ private static dispatchToSubscribers; /** * Api to reInitialize connection on abrupt closing of connection or ALIVE message not received in specified time. * @param skipSetInterval passed true if broadcast message not received in given time period * @private */ static reInitialization(skipSetInterval?: boolean): void; /** * Api to check server liveliness broadcast message based on time passed as argument, to receive recurring ALIVE message on network * @param timeToPing time in ms. * @private */ static checkLiveliness(timeToPing: number): void; /** * Sets the messaging service url * @param connectionConfig service url to be connected for websocket. * eq., * { * messagingService: "ws://localhost:3000/c11n-msg" * } * @private */ static setConnectionConfig(connectionConfig: ConnectionConfig): void; /** * Api to remove all listener attached on websocket * @private */ static cleanSocketListeners(): void; /** * Api to clean and nullify websocket * @private */ static disconnect(): void; private static getFilterKey; private static findExistingSubscriberId; /** * Api to subscribe to messaging service and depends on the filter creteria messages will * be forwarded to subscribers. * @param filter Object to hold filter creteria, * It helps to receive only targetted changes. * eq., * 1. * { * matcher: "interaction" * } * * 2. * { * matcher: "pulse", * filter: { * caseId: "EPIC-201" * } * } * @param messageHandler callback handler * @param contextName - Name of the context eq., app/primary_1 * @param id any specific id or id will be autogenerated. Id can be used for unsubscribing from * message service. * @example Example subscribe() * Example usage - PCore.getMessagingServiceManager().subscribe({matcher: "interaction"}, message => { * // Do process message here * }); * @returns returns the subscription id, can be used for unsubscribing from * message service. * @public */ static subscribe(filter: Filter, messageHandler: Function, contextName?: string, id?: string): string; /** * Subscribes to socket. * @param messageSubscriber message subscriber * @param id subscriber id * @private */ static subscribeToSocket(messageSubscriber: MessageSubscriber, id: string): void; /** * Removes the handler from subscriptions and disconnects from service. * @param id Pass id returned by subscribe method. * @example Example unsubscribe() * const subId = PCore.getMessagingServiceManager().subscribe({matcher: "interaction"}, message => { * // Do process message here * })); * PCore.getMessagingServiceManager().unsubscribe(subId); * @public */ static unsubscribe(id: string, notRemove?: boolean): void; /** * Removes a subscription from the in-progress queue and cleans up * the filter-to-subscriber-id mapping. * @param id - subscription id to remove * @private */ private static removeFromInProgressSubscriptions; /** * Publishes the message to subscribers received from server. * @param message message object received from messaging service. * @private */ static publishMessage(message: Record): void; static getUserPresence: () => UserPresence; /** * Dispatches a locally-constructed message through the subscriber dispatch pipeline, * bypassing the WebSocket connection. Existing subscribers receive the message through * the same mechanism as server-pushed updates — no consumer-side changes are required. * * Intended for offline-sync scenarios where the mobile client needs to notify the UI * that data has changed without a live WebSocket connection. * * @param payload - the message to dispatch locally: * - `matcher` — the filter matcher string (e.g. `"DATAPAGE_UPDATED"`, `"CASE"`, or any custom value) * - `criteria` — key/value pairs that must match a subscriber's filter criteria * - `message` — optional payload forwarded to matching subscriber handlers * * @example Notify UI after offline sync updates a data page * PCore.getMessagingServiceManager().dispatchLocalMessage({ * matcher: 'DATAPAGE_UPDATED', * criteria: { datapage: 'D_InsightsList' } * }); * * @example Notify UI after offline sync updates a case * PCore.getMessagingServiceManager().dispatchLocalMessage({ * matcher: 'CASE', * criteria: { caseId: 'MYWORK-123' } * }); * * @example Notify UI with additional message properties * PCore.getMessagingServiceManager().dispatchLocalMessage({ * matcher: 'CASE', * criteria: { caseId: 'MYWORK-123' }, * message: { attachmentUpdated: 'true' } * }); * @public */ static dispatchLocalMessage(payload: LocalMessagePayload): void; static getCaseSubscription: (caseId: string) => import("./atomic-subscription").default; static initObjectRedirectionSubscription: () => void; static refreshB2STokenReInit: () => Promise; static getTokenExpiryTime: () => number; static setTokenExpiryTime: (token: TokenData) => void; /** * Removes the cache of all subscribers. * @param contextName name of the context. * @private */ static clearContext(contextName: string): void; } export default MessagingServiceManager;