Class Broker

central message broker which uses various dom constructs to broadcast messages into subelements

we use the dom event system as transport and iframe and shadow dom mechanisms in a transparent way to pull this off

usage

broker = new Broker(optional rootElement)

defines a message broker within a scope of rootElement (without it is window aka the current isolation level)

broker.registerListener(channel, listener) registers a new listener to the current broker and channel broker.unregisterListener(channel, listener) unregisters the given listener

broker.broadcast(message, optional direction, optional callBrokerListeners) sends a message (channel included in the message object) in a direction (up, down, both) and also optionally calls the listeners on the same broker (default off)

the flow is like up messages are propagated upwards only until it reaches the outer top of the dom downwards, the messages are propagated downwards only both the message is propagated into both directions

Usually messages sent from the same broker are not processed within... however by setting callBrokerListeners to true the listeners on the same broker also are called brokers on the same level will get the message and process it automatically no matter what. That way you can exclude the source from message processing (and it is done that way automatically)

Isolation levels. Usually every isolation level needs its own broker object registering on the outer bounds

aka documents will register on window iframes on the iframe windowObject isolated shadow doms... document

Hierarchy

  • BaseBroker
    • Broker

Constructors

  • constructor has an optional root element and an internal name

    Parameters

    • scopeElement: Window | HTMLElement | ShadowRoot = window
    • brokerGroup: string = "brokr"
    • crypto: Crypto = noEncryption

    Returns Broker

Properties

brokerGroup: string = "brokr"
crypto: NoCrypto = noEncryption
EVENT_TYPE: "brokerEvent" = "brokerEvent"

Methods

  • answers a bidirectional message received usage, the client can use this method, to answer an incoming message in a precise manner so that the caller sending the bidirectional message knows how to deal with it this mechanism can be used for global storages where we have one answering entity per channel delivering the requested data, the request can be done asynchronously via promises waiting for answers

    Parameters

    • channel: string

      the channel the originating message

    • request: string | Message

      the requesting message

    • answer: Message

      the answer to the request

    Returns BaseBroker

  • returns an observable on the baseBroker

    Parameters

    • channel: string

    Returns Observable<Message>

  • binding into rxjs produces a subject which can be used via next calls to send messages on the other hand we

    Parameters

    • channel: string

    Returns Subject<Message>

  • broadcast a message the message contains the channel and the data and some internal bookkeeping data

    Parameters

    • channel: string

      the channel to broadcast to

    • message: string | Message

      the message dot send (for instance 2 iframes within the same parent broker)

    Returns BaseBroker

  • register the current broker into a scope defined by wnd

    Parameters

    • scopeElement: Window | HTMLElement | ShadowRoot

    Returns BaseBroker

  • registers a listener on a channel

    Parameters

    • channel: string

      the channel to register the listeners for

    • listener: ((msg: Message) => void)

      the listener to register

    Returns BaseBroker

  • idea... a bidirectional broadcast sends a message and waits for the first answer coming in from one of the receivers sending the message back with a messageIdentifier_broadCastId answer

    Parameters

    • channel: string
    • message: string | Message

    Returns Promise<Message>

  • manual unregister function, to unregister as broker from the current scope

    Returns BaseBroker

  • unregisters a listener from this channel

    Parameters

    • channel: string

      the channel to unregister from

    • listener: ((msg: Message) => void)

      the listener to unregister the channel from

    Returns BaseBroker

Generated using TypeDoc