// @ts-ignore import type { EventEmitter } from 'events' /** @internal */ export interface SessionStream extends EventEmitter { /** Metrics associated with the stream */ metrics: SessionStreamMetrics /** Start listening for events coming across the stream */ connect: () => void /** Stop listenining for events */ disconnect: () => void /** Send a sync event */ sendSync: (options?: Partial) => void /** Send a highlight event */ sendHighlight: (options?: Partial) => void } /** @internal */ export interface SessionStreamEventMap { close: [] error: [unknown] open: [] change: [ChangeEvent] frame: [FrameEvent] highlight: [HighlightEvent] input: [InputEvent] mouse: [MouseEvent] viewhierarchy: [ViewHierarchyEvent] } /** @internal */ export interface SessionStreamMetrics { /** Total time for a keep alive message to go to the client and for its response to come back */ rtt: number | undefined /** The last time the socket can be considered alive */ last_alive: Date | undefined /** Total time it took the last message to go to the client and for its response to come back */ latency: number | undefined } /** @internal */ export interface BaseOptions { id: string } /** @internal */ export interface HighlightOptions extends BaseOptions { display: string | null target: Target title: string agent: string } /** @internal */ export interface Target { /** The cobrowse identifier for this node */ id: string /** Whether the target is redacted */ redacted?: boolean; /** The associated value of this element */ value?: string /** Whether the target is checked or not */ checked?: boolean } /** * An event that's received from an end-user device * * @internal */ export interface BaseDeviceEvent { /** When the event was emitted on the end-user device */ timestamp: Date; } /** * An end-user device event that's emited from an element * * @internal */ export interface BaseTargetedDeviceEvent extends BaseDeviceEvent { /** * The target (element) of the event * * The target is undefined when it's not known to the SDK (e.g., an ignored sub tree) */ target: Target | undefined } /** * A form field was changed * * @internal */ export interface ChangeEvent extends BaseTargetedDeviceEvent { type: 'Change' state: 'change' } /** * An input field was changed, but perhaps not blurred * * @internal */ export interface InputEvent extends BaseTargetedDeviceEvent { type: 'Input' state: 'input' } /** * A mouse event took place * * @internal */ export interface MouseEvent extends BaseTargetedDeviceEvent { type: 'Mouse' state: 'click' | 'mouseout' | 'mousedown' | 'mouseup' x: number y: number } /** * A highlight event was acknowledged * * @internal */ export interface HighlightEvent extends BaseDeviceEvent { type: 'Highlight' /** The id of the highlight that was resolved */ id: string } /** * The device sends a frame holding view data * * @internal */ export interface FrameEvent extends BaseDeviceEvent { type: 'Frame' data: VDOMData } /** * The view hierarchy for a mobile device * * @internal */ export interface ViewHierarchyEvent extends BaseDeviceEvent, VDOMData { type: 'viewhierarchy' } /** * VDOM Data that's passed in a `Frame` event * * @internal */ export interface VDOMData { /** The document ID the patches belong to */ document_id: string /** A set of incremental serialized patches with view data */ patch: Patch[] } /** @internal */ export interface Patch { id: string nodeType: HTMLElement['nodeType'] tagName?: HTMLElement['tagName'] content?: HTMLElement['nodeValue'] childNodes?: [{ id: string }] } /** * Union for all events that are related to a specific element target * * @internal */ export type TargetedDeviceEvent = ChangeEvent | InputEvent | MouseEvent /** * Union for all possible events emitted by a device * * @internal */ export type DeviceEvent = TargetedDeviceEvent | HighlightEvent | FrameEvent | ViewHierarchyEvent