Class PublicAPI

Represents the Ruffle public API.

The public API exists primarily to allow multiple installs of Ruffle on a page (e.g. an extension install and a local one) to cooperate. In an ideal situation, all Ruffle sources on the page install themselves into a single public API, and then the public API picks the newest version by default.

This API is versioned, in case we need to upgrade it. However, it must be backwards- and forwards-compatible with all known sources.

Implements

  • PublicAPILike

Properties

config: object | URLLoadOptions | DataLoadOptions

The configuration object used when Ruffle is instantiated.

sources: Record<string, {
    version: string;
    polyfill(): void;
    pluginPolyfill(): void;
    createPlayer(): RufflePlayer;
}>

Type declaration

  • version: string

    The version of this particular API, as a string in a semver compatible format.

  • polyfill:function
  • pluginPolyfill:function
  • createPlayer:function
invoked: boolean
newestName: null | string

Accessors

  • get version(): string
  • The version of the public API.

    This is not the version of Ruffle itself.

    This allows a page with an old version of the Public API to be upgraded to a new version of the API. The public API is intended to be changed very infrequently, if at all, but this provides an escape mechanism for newer Ruffle sources to upgrade older installations.

    Returns string

    The version of this public API.

Methods

  • Join a source into the public API, if it doesn't already exist.

    Parameters

    • Optional prevRuffle: null | PublicAPILike

      The previous iteration of the Ruffle API.

      The prevRuffle param lists the previous object in the RufflePlayer slot. We perform some checks to see if this is a Ruffle public API or a conflicting object. If this is conflicting, then a new public API will be constructed (see the constructor information for what happens to prevRuffle).

      Note that Public API upgrades are deliberately not enabled in this version of Ruffle, since there is no Public API to upgrade from.

    • Optional sourceName: string

      The name of this particular Ruffle source.

      If both parameters are provided they will be used to define a new Ruffle source to register with the public API.

    Returns PublicAPI

    The Ruffle Public API.

  • Register a given source with the Ruffle Public API.

    Parameters

    • name: string

      The name of the source.

    Returns void

  • Determine the name of the newest registered source in the Public API.

    Returns null | string

    The name of the source, or null if no source has yet to be registered.

  • Negotiate and start Ruffle.

    This function reads the config parameter to determine which polyfills should be enabled. If the configuration parameter is missing, then we use a built-in set of defaults sufficient to fool sites with static content and weak plugin detection.

    Returns void

  • Look up the newest Ruffle source and return it's API.

    Returns null | {
        version: string;
        polyfill(): void;
        pluginPolyfill(): void;
        createPlayer(): RufflePlayer;
    }

    An instance of the Source API.

  • Look up a specific Ruffle version (or any version satisfying a given set of requirements) and return it's API.

    Parameters

    • requirementString: string

      A set of semantic version requirement strings that the player version must satisfy.

    Returns null | {
        version: string;
        polyfill(): void;
        pluginPolyfill(): void;
        createPlayer(): RufflePlayer;
    }

    An instance of the Source API, if one or more sources satisfied the requirement.

  • Look up the newest Ruffle version compatible with the local source, if it's installed. Otherwise, use the latest version.

    Returns null | {
        version: string;
        polyfill(): void;
        pluginPolyfill(): void;
        createPlayer(): RufflePlayer;
    }

    An instance of the Source API

  • Look up the newest Ruffle version with the exact same version as the local source, if it's installed. Otherwise, use the latest version.

    Returns null | {
        version: string;
        polyfill(): void;
        pluginPolyfill(): void;
        createPlayer(): RufflePlayer;
    }

    An instance of the Source API

  • Indicates that this version of the public API has been superseded by a newer version.

    This should only be called by a newer version of the Public API. Identical versions of the Public API should not supersede older versions of that same API.

    Unfortunately, we can't disable polyfills after-the-fact, so this only lets you disable the init event...

    Returns void