Interface EventBridge

The event bridge that transports events between Android and web.

interface EventBridge {
    connect(): Promise<Required<Connection>>;
    getConnection(): null | Required<Connection>;
    isSupported(eventType: string): boolean;
    request(event: Event): Event;
    requestAsync(event: Event): Promise<Event>;
    subscribe(listener: ((event: Event) => void)): Unsubscribe;
    subscribe(eventType: string, listener: ((payload: any) => void)): Unsubscribe;
}

Methods

  • Returns the promise that is resolved when a connection becomes available. Usually, you don't have to call this method manually, since the connection would be established automatically as soon as the first request is sent or the first listener is subscribed.

    Returns Promise<Required<Connection>>

  • Returns true if an event of the given type is supported, or false otherwise.

    Parameters

    • eventType: string

      The type of event to check.

    Returns boolean

  • Sends an event through a connection to Android and returns a response event.

    The connection is automatically established when this method is called.

    The error is thrown if org.racehorse.ExceptionEvent is published as a response, if the response event wasn't published synchronously, or if connection cannot be established synchronously.

    Parameters

    • event: Event

      The request event to send.

    Returns Event

    The response event.

  • Sends an event through a connection to Android and returns a promise that is resolved with a response event.

    The connection is automatically established when this method is called.

    The returned promise is rejected if org.racehorse.ExceptionEvent is published as a response.

    Parameters

    • event: Event

      The request event to send.

    Returns Promise<Event>

    The response event.

  • Subscribes a listener to all notice events pushed by Android.

    The connection is automatically established when this method is called.

    Parameters

    • listener: ((event: Event) => void)

      The listener to subscribe.

        • (event): void
        • Parameters

          Returns void

    Returns Unsubscribe

    The callback that unsubscribes the listener.

  • Subscribes a listener to notice events of the particular type pushed by Android.

    The connection is automatically established when this method is called.

    Parameters

    • eventType: string

      The type of the event to subscribe to.

    • listener: ((payload: any) => void)

      The listener to subscribe.

        • (payload): void
        • Parameters

          • payload: any

          Returns void

    Returns Unsubscribe

    The callback that unsubscribes the listener.