import { Observable } from "rxjs" /** * PUBLIC types */ // eslint-disable-next-line @typescript-eslint/no-explicit-any export type Message = { id: string timestamp: string source: MessageSource body: B } // eslint-disable-next-line @typescript-eslint/no-explicit-any export type MessageHandler = ( message$: Observable>, deps: Deps, ) => Observable export enum MessagingStoppedReason { Manual = "manual", Restart = "restart", ClosedByPeer = "closed-by-peer", Invalidation = "invalidation", PingTimedOut = "ping-timed-out", ConnectionTimedOut = "connection-timed-out", PutToBackground = "put-to-background", } /** * Object containing public information about messaging service * @property name - name of the server * @property id - id of the service * @property shortId - short version of serviceId */ export type MessagingServiceInformation = { name: string id: string shortId: string } /** * PRIVATE types */ export type MessageSource = { name?: string serviceId?: string connectionId: string } export enum DataObjectType { Message = "message", MessageAck = "message-ack", Ping = "ping", ServiceInfo = "service-info", } // eslint-disable-next-line @typescript-eslint/no-explicit-any export type DataObjectMessage = { type: DataObjectType.Message message: Message connectionId?: string } export type DataObjectMessageAck = { type: DataObjectType.MessageAck messageId: string connectionId?: string } export type DataObjectPing = { type: DataObjectType.Ping pingId: string connectionId?: string } export type DataObjectServiceInfo = { type: DataObjectType.ServiceInfo info: MessagingServiceInformation connectionId?: string } export const composeDataObjectPing = (pingId: string, connectionId?: string): DataObjectPing => ({ type: DataObjectType.Ping, pingId: pingId, ...(connectionId ? { connectionId: connectionId } : null), }) export type DataObject = | DataObjectMessage | DataObjectMessageAck | DataObjectPing | DataObjectServiceInfo