web: Properly document and define window.RufflePlayer

This commit is contained in:
Nathan Adams 2020-11-17 22:41:24 +01:00 committed by Mike Welsh
parent 2c952e954d
commit d2d8bc6f01
3 changed files with 21 additions and 16 deletions

View File

@ -3,12 +3,6 @@ import { RuffleEmbed } from "./ruffle-embed";
import { install_plugin, FLASH_PLUGIN } from "./plugin-polyfill"; import { install_plugin, FLASH_PLUGIN } from "./plugin-polyfill";
import { public_path } from "./public-path"; import { public_path } from "./public-path";
declare global {
interface Window {
RufflePlayer: any;
}
}
if (!window.RufflePlayer) { if (!window.RufflePlayer) {
window.RufflePlayer = {}; window.RufflePlayer = {};
} }

View File

@ -3,6 +3,18 @@ import { VersionRange } from "./version-range";
import { SourceAPI } from "./source-api"; import { SourceAPI } from "./source-api";
import { Config } from "./config"; import { Config } from "./config";
declare global {
interface Window {
/**
* The public API for generating a ruffle player.
* This may be a config holder, which will be converted to a
* [[PublicAPI]] via [[PublicAPI.negotiate]], or an actual
* [[PublicAPI]] instance itself.
*/
RufflePlayer?: { config?: Config } | PublicAPI;
}
}
/** /**
* Represents the Ruffle public API. * Represents the Ruffle public API.
* *
@ -15,8 +27,12 @@ import { Config } from "./config";
* backwards- and forwards-compatible with all known sources. * backwards- and forwards-compatible with all known sources.
*/ */
export class PublicAPI { export class PublicAPI {
/**
* The configuration object used when Ruffle is instantiated.
*/
config: Config;
private sources: Record<string, SourceAPI>; private sources: Record<string, SourceAPI>;
private config: Config;
private invoked: boolean; private invoked: boolean;
private newestName: string | null; private newestName: string | null;
private conflict: Record<string, unknown> | null; private conflict: Record<string, unknown> | null;

View File

@ -14,11 +14,6 @@ export const FLASH_ACTIVEX_CLASSID =
const DIMENSION_REGEX = /^\s*(\d+(\.\d+)?(%)?)/; const DIMENSION_REGEX = /^\s*(\d+(\.\d+)?(%)?)/;
declare global { declare global {
interface Window {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
RufflePlayer: any;
}
interface Document { interface Document {
webkitFullscreenEnabled?: boolean; webkitFullscreenEnabled?: boolean;
webkitFullscreenElement?: HTMLElement; webkitFullscreenElement?: HTMLElement;
@ -412,10 +407,11 @@ export class RufflePlayer extends HTMLElement {
} }
} }
items.push({ items.push({
// TODO: ruffle version info
text: `Ruffle ${ text: `Ruffle ${
__CHANNEL__ === "nightly" __CHANNEL__ === "nightly"
? `nightly ${__COMMIT_DATE__}` ? `nightly ${__COMMIT_DATE__}`
: window.RufflePlayer.version : "0.1.0"
}`, }`,
onClick() { onClick() {
window.open("https://ruffle.rs/", "_blank"); window.open("https://ruffle.rs/", "_blank");
@ -681,9 +677,8 @@ export class RufflePlayer extends HTMLElement {
errorText += `Useragent: ${window.navigator.userAgent}\n`; errorText += `Useragent: ${window.navigator.userAgent}\n`;
errorText += `OS: ${window.navigator.platform}\n`; errorText += `OS: ${window.navigator.platform}\n`;
errorText += "\n# Ruffle Info\n"; // TODO: Ruffle source version. No way to know right now?
errorText += `Ruffle version: ${window.RufflePlayer.version}\n`;
errorText += `Ruffle source: ${window.RufflePlayer.name}\n`;
this.container.querySelector( this.container.querySelector(
"#panic-body" "#panic-body"
)!.innerHTML = `<textarea>${errorText}</textarea>`; )!.innerHTML = `<textarea>${errorText}</textarea>`;