@alwaysblank/denden
    Preparing search index...

    Class Hub

    Hub for sending and registering to receive messages.

    Hierarchy

    • EventTarget
      • Hub
    Index

    Constructors

    • Returns Hub

    Methods

    • The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

      MDN Reference

      Parameters

      • type: string
      • callback: EventListenerOrEventListenerObject | null
      • Optionaloptions: boolean | AddEventListenerOptions

      Returns void

    • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.

      MDN Reference

      Parameters

      • event: Event

      Returns boolean

    • Get a set of Message that were already sent to the channel.

      Messages are returned in reverse chronological order (most recent -> oldest),

      Parameters

      • query: MessageQuery

        Set of query options for retrieving messages.

        Describes a query to Hub.getMessages for messages.

        • cid: ChannelRoute | ChannelRoute[]

          A argument (or array of arguments) which can resolve to channel names.

        • Optionallimit?: number

          The number of messages to return.

        • Optionalorder?: "ASC" | "DESC"

          Messages are sorted by order of dispatch: ASC is oldest -> newest, DESC is newest -> oldest.

      Returns Message<any>[]

      All messages from matching channel(s) which match query.

    • Create a channel named name.

      If such a channel already exists, this method will return the name of the existing channel.

      Parameters

      • name: string

      Returns string

    • Publish a message to a particular channel, or channels.

      Returns a Promise which resolves when all callbacks attached to routes have completed. If a callback thr

      Callbacks which returned void or undefined will have the value true.

      Type Parameters

      • Payload

        The type of the payload carried by the message(s) being published.

      Parameters

      • routes: ChannelRoute | ChannelRoute[]

        Channel route (i.e., a channel name, wildcard string, or RegExp) to publish to, or an array of the same. Routes which are not fully-qualified (i.e., they are a wildcard string or a regular expression) will only dispatch to channels which are already registered on the Hub. Fully qualified route names for unregistered channels will result in the creation of a channel with that name.

      • payload: Payload

        The item to dispatch to routes.

      Returns Promise<(PubResult | Error)[]>

    • The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.

      MDN Reference

      Parameters

      • type: string
      • callback: EventListenerOrEventListenerObject | null
      • Optionaloptions: boolean | EventListenerOptions

      Returns void

    • Listen to messages sent to a particular channel.

      Returns a method which, when called, will terminate the subscription; callback will not receive any further messages. Optionally, this

      • unsub method takes a string argument, indicating why we have
      • unsubscribed from this channel. (Currently, this is not accessible.)

      This method attempts to call listener for all historical messages in the order in which they were received, but it is theoretically possible to construct a circumstance in which messages might be received out of order. Message.order will always be greater for messages that have been dispatched more recently. However, it is a generally good practice for listener to be idempotent.

      Type Parameters

      • Payload extends unknown = any

        Value carried by the message.

      Parameters

      • channel: ChannelRoute | ChannelRoute[]

        Name of the channel to subscribe to. Does not need to exist to be subscribed to. Passing * will subscribe to all channels.

      • callback: Callback<Payload>

        Called with message payload and channel name when a message is published.

      • Optionalbacklog: number = 0

        Number of old messages in the channel(s) to send to listener before attaching subscription. *

      • OptionallistenerOptions: AddEventListenerOptions = {}

        Options passed directly to addEventListener(). Use with caution.

      Returns (reason?: string) => void