Unblu Floating JS API
    Preparing search index...

    Class UnbluStaticApi

    The central entry point that allows to configure an initialize the Unblu Floating JS API.

    The Unblu Floating JS API is an optional add-on to the Unblu Floating UI. The UnbluStaticApi works without actually loading the rest of Unblu. It can do some general checks and load Unblu or connect the API to a loaded version of Unblu.

    Depending on how Unblu is integrated into the local website the API has to be initialized differently.

    a.) API-only integration If no unblu-snippet is loaded into the page, the Unblu Floating UI can be fully initialized with the API. In this case, both the configure and the initialize methods have to be called. Example:

     const api = await unblu.floating.api
    // configure the unblu server
    .configure({
    apiKey: "<your-api-key>",
    serverUrl: "<unblu-server-url>"
    })
    // initialize the api.
    .initialize();

    This implementation will load the Unblu snippet and initialize both the Unblu Floating UI and the JS API.

    b.) Snippet and JS API integration If the Unblu snippet is already present in the local website, Unblu doesn't have to be loaded and only the API has to be initialized. Example:

    // directly initialize the api without configuring.
    const api = await unblu.floating.api.initialize();

    Implements

    • UnbluFloatingApiFactory
    Index

    Methods

    • Configures the way that Unblu should be initialized.

      The configuration of the Unblu API is needed when, and only when no Unblu snippet is already present in the website.

      Note:

      • Calling this method when there's already an Unblu snippet will result in an UnbluApiError.
      • This method must be called BEFORE initialize. If it is called afterwards an UnbluApiError will be thrown.

      Parameters

      Returns UnbluStaticApi

      an instance of this allowing chaining like unblu.floating.api.configure({...}).initialize();

      isConfigurationNeeded to check if configuration is needed or not.

    • Returns the current state of the API

      Returns ApiState

      the current API state.

      isInitialized for a simpler check

    • Checks whether the API has to be configured or not.

      • If no snippet is present and the API state is still [INITIAL]ApiState.INITIAL a configuration is necessary.
      • If a snippet is present or the API is already loaded, configuration is not necessary.
      • If the API state is in [DEINITIALIZED]ApiState.DEINITIALIZED

      Returns boolean

      true if a configuration is needed to initialize the API, false otherwise.

    • Checks whether the API is initialized or not.

      Returns boolean

      true if the API is initialized, false for any other state.

      getApiState for the full state

    • Removes a previously registered listener.

      Parameters

      • event: string

        The event unregister.

      • listener: Listener

        The listener to be removed.

      Returns boolean

      true if the listener was removed, false otherwise.

    • Registers an event listener for the given event.

      Note If the API is already initialized, this listener will be called directly.

      Parameters

      • event: "ready"

        The ready event

      • listener: ReadyListener

        The listener to be called.

      Returns void

      READY

    • Registers an event listener for the given event.

      Note If the API has already failed, this listener will be called directly.

      Parameters

      • event: "error"

        The error event

      • listener: ErrorListener

        The listener to be called.

      Returns void

      ERROR

    • Registers an event listener for the given event.

      Note If the API is already deinitializing, this listener will be called directly.

      Parameters

      • event: "deinitializing"

        The deinitializing event

      • listener: DeinitializingListener

        The listener to be called.

      Returns void

    • Registers an event listener for the given event.

      Note If the API is already deinitialized, this listener will be called directly.

      Parameters

      • event: "deinitialized"

        The deinitialized event

      • listener: DeinitializedListener

        The listener to be called.

      Returns void

    • Registers an event listener for the given event.

      Parameters

      • event: "state"

        The state event

      • listener: StateListener

        The listener to be called.

      Returns void

      STATE

    Events

    DEINITIALIZED: "deinitialized" = 'deinitialized'

    Event emitted as soon as the API is completely de-initialized.

    It usually makes sense to use this event to clean up resources and/or unregistering of listeners to no try to use the API again until it is initialized again.

    deinitialized

    on for listener registration

    DEINITIALIZING: "deinitializing" = 'deinitializing'

    Event emitted as soon as the API is going to get de-initialized.

    It usually makes sense to use this event to clean up resources and/or unregistering of listeners to no try to use the API again until it is initialized again.

    deinitializing

    on for listener registration

    ERROR: "error" = 'error'

    Event emitted if the API initialization fails.

    It usually makes sense to use this event if there is some general action that has to be triggered when the API initialization fails, but there are several places in the integration code that may trigger the initialization.

    In most cases however, it is better to use

    unblu.floating.api.initialize().catch(error=> { //handle error here });
    

    or

    try{
    let api = await unblu.floating.api.initialize();
    }catch(e){
    // handle error here
    }

    error

    on for listener registration

    READY: "ready" = 'ready'

    Event emitted as soon as the API is initialized.

    It usually makes sense to use this event if there is some general action that has to be triggered when the API is initialized, but there are several places in the integration code that may trigger the initialization.

    In most cases however, it is better to use

    unblu.floating.api.initialize().then(api => { //use api here });
    

    or

    let api = await unblu.floating.api.initialize();
    // use api here

    Note: that this event will be triggered again after each initialization.

    ready

    on for listener registration

    STATE: "state" = 'state'

    Event emitted whenever the API state changes

    state

    on for listener registration