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 { public_path } from "./public-path";
declare global {
interface Window {
RufflePlayer: any;
}
}
if (!window.RufflePlayer) {
window.RufflePlayer = {};
}

View File

@ -3,6 +3,18 @@ import { VersionRange } from "./version-range";
import { SourceAPI } from "./source-api";
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.
*
@ -15,8 +27,12 @@ import { Config } from "./config";
* backwards- and forwards-compatible with all known sources.
*/
export class PublicAPI {
/**
* The configuration object used when Ruffle is instantiated.
*/
config: Config;
private sources: Record<string, SourceAPI>;
private config: Config;
private invoked: boolean;
private newestName: string | null;
private conflict: Record<string, unknown> | null;

View File

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