Options
All
  • Public
  • Public/Protected
  • All
Menu

Type parameters

  • C = any

Hierarchy

  • SharedClient<C>
    • ParentClient

Index

Constructors

constructor

  • new ParentClient<C>(options?: ParentClientOptions): ParentClient<C>

Properties

Protected Readonly channel

channel: Deferred<Channel<C>>

Protected Readonly debug

debug: boolean

Protected destroyed

destroyed: boolean

Protected eventSubscriptions

eventSubscriptions: {}

Type declaration

Protected Readonly handshakeTimeout

handshakeTimeout: number

Protected Optional initTimer

initTimer?: Timeout

Protected Readonly logger

logger: Logger

Protected Optional messagePort

messagePort?: MessagePort

Protected onDestroyRequestHandlers

onDestroyRequestHandlers: {}

Type declaration

  • [id: string]: () => void
      • (): void
      • Returns void

Protected Readonly profile

profile: boolean

Protected Readonly profiler

profiler: Profiler

Protected requestSubscriptions

requestSubscriptions: {}

Type declaration

Protected Readonly requestTimeout

requestTimeout: number

Protected responseSubscriptions

responseSubscriptions: {}

Type declaration

Methods

destroy

  • destroy(): void

Protected getChannel

  • A wrapper around the channel deferred object that also checks if the client has been destroyed before returning

    Returns Promise<Channel<C>>

getContext

  • getContext(): Promise<null | C>
  • Returns the context provided by the opposite client, or null if the handshake process fails

    Returns Promise<null | C>

Protected getInitMessage

  • getInitMessage<T>(context: T): Message<T>

Protected getLogger

  • getLogger(): Logger

getMessageProfile

Protected handleEvent

  • handleEvent<T>(message: Message<T>): void

Protected handleRequest

  • handleRequest<Q>(message: Message<Q>): void

Protected handleResponse

  • handleResponse<R>(message: Message<R>): void

handshake

  • handshake(): Promise<C>

Protected initListener

  • initListener(ev: MessageEvent<Message<C>>): void

Protected isInitMessage

  • isInitMessage(ev: MessageEvent<any>): boolean

Protected isValidMessage

  • isValidMessage(ev: MessageEvent<any>): boolean

Protected messageListener

  • messageListener(ev: MessageEvent<Message<any>>): Promise<void>

on

  • on<T>(eventType: string, handler: EventHandler<T>): () => void
  • Subscribes an event handler for the given eventType. Returns an unsubscribe hook

    Type parameters

    • T = any

    Parameters

    Returns () => void

      • (): void
      • Subscribes an event handler for the given eventType. Returns an unsubscribe hook

        Returns void

Protected onChannelInit

  • onChannelInit(): void

onRequest

  • onRequest<Q, R>(requestKey: string, requestHandler: RequestHandler<Q, R>): () => void
  • Subscribes a request handler for the given request key. The return value from the subscribed handler is sent back to the opposite client. The handler may be async. Unlike event handlers, there may be only one request handler per request key. Returns an unsubscribe hook.

    Type parameters

    • Q = any

    • R = any

    Parameters

    Returns () => void

      • (): void
      • Subscribes a request handler for the given request key. The return value from the subscribed handler is sent back to the opposite client. The handler may be async. Unlike event handlers, there may be only one request handler per request key. Returns an unsubscribe hook.

        Returns void

Protected postMessage

  • postMessage<T>(type: MessageType, key: string, data: T, requestId?: string): Promise<Message<T>>

request

  • request<Q, R>(requestKey: string, data?: Q, options?: RequestOptions): Promise<R>
  • Sends a request to the opposite client. There must be an accompanying request handler subscribed with onRequest. Resolves with the returned data or times out.

    Type parameters

    • Q = any

    • R = any

    Parameters

    Returns Promise<R>

requestChannel

  • requestChannel<T>(frame: HTMLIFrameElement, context: T): void
  • Request a channel with a child client in an iframe. Must be called after child frame is fully loaded.

    Type parameters

    • T

    Parameters

    • frame: HTMLIFrameElement
    • context: T

    Returns void

requestChannelWithPopup

  • requestChannelWithPopup<T>(targetWindow: Window, url: string, context: T): void
  • Request a channel with the child client in a new tab or a new window opened with window.open(). Must be called after the popup has fully loaded, if not blocked by a popup blocker.

    Type parameters

    • T

    Parameters

    • targetWindow: Window
    • url: string
    • context: T

    Returns void

Protected resolveChannel

  • resolveChannel(ev: MessageEvent<Message<C>>): void

send

  • send<T>(eventType: string, data: T): Promise<null | Message<T>>

Protected setInitTimer

  • setInitTimer(): void

Generated using TypeDoc