import { EvaContext } from "@springtree/eva-sdk-core-service"; import { BaseHub, IHubConnectionOptions, THubConnectionEventHandler } from "./base-hub.js"; import { IClientApp, IClientAppMessage, IJoinClientAppHub } from "../request/client-app-hub.js"; import { IHubEventClientAppMessage, IHubEventClientAppRegistered, IHubEventClientAppUnregistered, IHubEventJoinedChannelMessage, IHubEventLeftChannelMessage } from "../response/client-app-hub.js"; import { TClientAppStatus } from "../request/client-app-hub-client.js"; import { GetApplicationConfigurationResponse } from "@springtree/eva-services-core"; /** * The hub event handler types */ export type TClientAppRegisteredHandler = (event: IHubEventClientAppRegistered) => void; export type TClientAppUnregisteredHandler = (event: IHubEventClientAppUnregistered) => void; export type TClientAppMessageHandler = (event: IHubEventClientAppMessage) => void; export type TClientAppJoinedChannelHandler = (event: IHubEventJoinedChannelMessage) => void; export type TClientAppLeftChannelHandler = (event: IHubEventLeftChannelMessage) => void; /** * The information we collect from every peer client that sends us their status (ping) * * @export * @interface IPeerClientStatus */ export interface IPeerClientStatus { clientApp: IClientApp; lastSeen: Date; channels: string[]; status: TClientAppStatus; endpointUri: string; } /** * The information about a single channels clients * * @export * @interface IChannelStatus */ export interface IChannelStatus { channelName: string; clients: { app: IClientApp; lastSeen: Date; status: "active" | "stale"; }[]; } /** * The ClientApp signalr hub is used to send message between various EVA application * operating in the same context (ie host, organization unit, linked device, etc) * * @export * @class ClientAppHub * @extends {BaseHub} */ export declare class ClientAppHub extends BaseHub { private statusDebounceTimeMs; setEventHandler(eventName: "connection", handler: THubConnectionEventHandler): void; setEventHandler(eventName: "Registered", handler: TClientAppRegisteredHandler): void; setEventHandler(eventName: "Unregistered", handler: TClientAppUnregisteredHandler): void; setEventHandler(eventName: "JoinedChannel", handler: TClientAppJoinedChannelHandler): void; setEventHandler(eventName: "LeftChannel", handler: TClientAppLeftChannelHandler): void; setEventHandler(eventName: "ReceivedMessage", handler: TClientAppMessageHandler): void; /** * This is the special purpose channel used for client status notifications * * @private */ private clientAppStatusChannel; /** * The details of the registered client application * * @private * @type {(IClientApp | undefined)} */ private clientApp; /** * The list of all channels we are connected to and a unix timestamp * of when we joined it * * @private * @type {{[channelName: string]: IChannelStatus}} */ private channels; /** * The list of seen peers and their status * * @private * @type {{[UUID: string]: IPeerClientStatus }} */ private peers; /** * Used to mark peers that haven't sent a message recently * * @private */ private idleThreshold; /** * Used to mark peers that have missed multiple heartbeats as disconnected * * @private */ private disconnectedThreshold; /** * Used to remove peers that haven't sent a heartbeat in a while * * @private */ private staleThreshold; /** * The interval at which the client sends an update about its peers * * @private */ private heartbeatInterval; /** * The interval at which the client sends a status update * * @private */ private clientStatusInterval; /** * The date the last client status update was sent at * * @private */ private lastSentClientStatusAt; /** * The interval timer used to send the heartbeat message * * @private * @type {(ReturnType | undefined)} */ private heartbeatTimer; /** * Client status updates need to be debounced to prevent update * message overload on reconnects * * @private * @type {(ReturnType | undefined)} */ private debouncedStatusTimer; /** * Sends the status of this client to the others * Will be sent on request when a Ping is received and at an interval * * @private */ private sendClientStatus; /** * Removes all clients from the peers list that haven't been seen in a while */ purgeStalePeers(): void; /** * Retrieves the names of the currently connected channels * * @return {*} {string[]} */ getChannels(): string[]; /** * Retrieves the list of all other clients currently connected to the * client app hub. * * @return {*} {IPeerClientStatus[]} */ getPeers(): IPeerClientStatus[]; /** * Retrieves the connected clients for a specific channel * * @param {string} channelName * @return {*} IChannelStatus */ getChannelStatus(channelName: string): IChannelStatus | undefined; /** * Creates a ClientAppHub hub instance */ constructor({ configuration, context, options, }: { configuration: GetApplicationConfigurationResponse; context: EvaContext; options?: IHubConnectionOptions; }, statusDebounceTimeMs?: number); /** * Override the leave method to kill the timer when a close is requested */ leave(): Promise; /** * Registers a client application * Once registered it can start joining and leaving channels. * A client application should remembers its unique identifier for future use. * * @param {IClientApp} app Client application details * @returns */ registerClientApplication(app: IClientApp): Promise; /** * Unregister a client application * * @returns */ unregisterClientApplication(): Promise; /** * Join a channel for inter-application communication * * @param {string} channelName The name of the channel * @returns */ joinChannel(channelName: string): Promise; /** * Leave a channel for inter-application communication * * @param {string} channelName The name of the channel * @returns */ leaveChannel(channelName: string): Promise; /** * Push a message to all apps registered on the same hub * * @param {IPushSessionToDeviceID} request * @returns */ sendMessage(request: IClientAppMessage): Promise; /** * Manually triggers a ping to see which other clients are currently connected to the hub * * @returns */ ping(uuid: string): Promise; } //# sourceMappingURL=client-app-hub.d.ts.map