Options
All
  • Public
  • Public/Protected
  • All
Menu

Type parameters

  • C = any

Hierarchy

  • SharedClient<C>
    • ChildClient

Index

Constructors

constructor

  • new ChildClient<C>(options?: ChildClientOptions): ChildClient<C>

Properties

Protected Readonly channel

channel: Deferred<Channel<C>>

context

context: any

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

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(ev: MessageEvent<Message<C>>): 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>

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