Represents the Ruffle public API.

The public API exists primarily to allow multiple installations 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

Constructors

  • Construct the Ruffle public API.

    Do not use this function to negotiate a public API. Instead, use public_api to register your Ruffle source with an existing public API if it exists.

    Constructing a Public API will also trigger it to initialize Ruffle once the page loads, if the API has not already been superseded.

    Parameters

    • Optionalprev: null | PublicAPILike

      What used to be in the public API slot.

      This is used to upgrade from a prior version of the public API, or from a user-defined configuration object placed in the public API slot.

    Returns PublicAPI

Properties

config: object | URLLoadOptions | DataLoadOptions

The configuration object used when Ruffle is instantiated.

sources: Record<string, SourceAPI>
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

  • 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 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 | SourceAPI

    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 | SourceAPI

    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 | SourceAPI

    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