Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PostMessageChannel

PostMessageChannel class. This is an class which warp postMessage communication and allow to work with it with higher API. This have dataSerializer feature, auto-connect feature (with defer), ensure url of the target (security), send (with wait connect), listener on messages, and events for lisfecycle of postmessageChannel status

Hierarchy

Index

Properties

prefixed: string | boolean
url: URL

The allowed URL for PostMessage communication

dataSerializer: DataSerializer

The dataserializer to use for parse and stringify object into PostMessage

property

{parse} function used to unserialize data

property

{stringify} function used to serialize data

_channelListener: EventEmitter<string | symbol, any> = ...

Channel where everything will be broadcast

_socket: false | Window = false

The socket used to directly send PostMessage

_domElement: false | HTMLIFrameElement = false

The domElement which contains socket to send PostMessage (in contentWindow)

_previouslyConnected: boolean = false

Flag to know if we have a reconnect without a disconnect

_listenerReference: false | ((e: MessageEvent<any>) => void) = false

Private property to save the message eventListener function

_isConnected: boolean = false

Private property to save the statuts of the PostMessage communication.

Constructors

  • new PostMessageChannel(target: HTMLIFrameElement | Window, targetUrl: string | URL, __namedParameters?: { dataSerializer?: DataSerializer; autoConnect?: boolean }): PostMessageChannel
  • Constructor of PostMessageChannel

    Parameters

    • target: HTMLIFrameElement | Window

      Target of the PostMessageChannel

    • targetUrl: string | URL

      Url allowed to communicate

    • __namedParameters: { dataSerializer?: DataSerializer; autoConnect?: boolean } = {}
      • Optional dataSerializer?: DataSerializer
      • Optional autoConnect?: boolean

    Returns PostMessageChannel

Accessors

  • get isConnected(): boolean
  • get isParentFrame(): boolean
  • get isChildFrame(): boolean

Methods

  • childFrameCheck(): void
  • parentFrameCheck(): void
  • connect(): boolean
  • Try to connect to postMessageChannel

    Returns boolean

    return false if we are already connected or true if the request is handled

  • disconnect(): boolean
  • Disconnect to the postMessageChannel

    Returns boolean

    return false if we are already disconnected or true if the request is handled

  • addListeners(): void
  • removeListeners(): void
  • socketSend(eventName: string, data?: {}, waitConnected?: boolean): void
  • Send a message into the postMessageChannel

    Parameters

    • eventName: string

      The identifier of the message

    • data: {} = {}
      • waitConnected: boolean = true

      Returns void

    • socketOn(...args: [event: string | symbol, fn: (...args: any[]) => void, context?: any]): EventEmitter<string | symbol, any>
    • socketOnce(...args: [event: string | symbol, fn: (...args: any[]) => void, context?: any]): EventEmitter<string | symbol, any>
    • eventNames(): (string | symbol)[]
    • Return an array listing the events for which the emitter has registered listeners.

      Returns (string | symbol)[]

    • listeners<T>(event: T): ((...args: any[]) => void)[]
    • Return the listeners registered for a given event.

      Type parameters

      • T: string | symbol

      Parameters

      • event: T

      Returns ((...args: any[]) => void)[]

    • listenerCount(event: string | symbol): number
    • Return the number of listeners listening to a given event.

      Parameters

      • event: string | symbol

      Returns number

    • emit<T>(event: T, ...args: any[]): boolean
    • Calls each of the listeners registered for a given event.

      Type parameters

      • T: string | symbol

      Parameters

      • event: T
      • Rest ...args: any[]

      Returns boolean

    • Add a listener for a given event.

      Type parameters

      • T: string | symbol

      Parameters

      • event: T
      • fn: (...args: any[]) => void
          • (...args: any[]): void
          • Parameters

            • Rest ...args: any[]

            Returns void

      • Optional context: any

      Returns PostMessageChannel

    • Type parameters

      • T: string | symbol

      Parameters

      • event: T
      • fn: (...args: any[]) => void
          • (...args: any[]): void
          • Parameters

            • Rest ...args: any[]

            Returns void

      • Optional context: any

      Returns PostMessageChannel

    • Add a one-time listener for a given event.

      Type parameters

      • T: string | symbol

      Parameters

      • event: T
      • fn: (...args: any[]) => void
          • (...args: any[]): void
          • Parameters

            • Rest ...args: any[]

            Returns void

      • Optional context: any

      Returns PostMessageChannel

    • removeListener<T>(event: T, fn?: (...args: any[]) => void, context?: any, once?: boolean): PostMessageChannel
    • Remove the listeners of a given event.

      Type parameters

      • T: string | symbol

      Parameters

      • event: T
      • Optional fn: (...args: any[]) => void
          • (...args: any[]): void
          • Parameters

            • Rest ...args: any[]

            Returns void

      • Optional context: any
      • Optional once: boolean

      Returns PostMessageChannel

    • off<T>(event: T, fn?: (...args: any[]) => void, context?: any, once?: boolean): PostMessageChannel
    • Type parameters

      • T: string | symbol

      Parameters

      • event: T
      • Optional fn: (...args: any[]) => void
          • (...args: any[]): void
          • Parameters

            • Rest ...args: any[]

            Returns void

      • Optional context: any
      • Optional once: boolean

      Returns PostMessageChannel

    • Remove all listeners, or those of the specified event.

      Parameters

      • Optional event: string | symbol

      Returns PostMessageChannel

    • _initializeSocket(autoConnect: boolean): void
    • Register the callbacks for handle connection of postMessageChannel and auto-connect if asked.

      Parameters

      • autoConnect: boolean

      Returns void

    • _messageListenerCallback(e: MessageEvent<any>): void

    Generated using TypeDoc