web: Fix documentation and warnings inside plugin-polyfill
This commit is contained in:
parent
48aa26460d
commit
1519642a9a
|
@ -1,9 +1,11 @@
|
||||||
/* global runtime_path */
|
/* eslint @typescript-eslint/no-explicit-any: "off" */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conditional ruffle loader
|
* Conditional ruffle loader
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { Ruffle } from "../pkg/ruffle_web";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load ruffle from an automatically-detected location.
|
* Load ruffle from an automatically-detected location.
|
||||||
*
|
*
|
||||||
|
@ -11,7 +13,7 @@
|
||||||
* You should not use it directly; this module will memoize the resource
|
* You should not use it directly; this module will memoize the resource
|
||||||
* download.
|
* download.
|
||||||
*/
|
*/
|
||||||
async function fetch_ruffle() {
|
async function fetch_ruffle(): Promise<{ new (...args: any[]): Ruffle }> {
|
||||||
try {
|
try {
|
||||||
//If runtime_path is defined then we are executing inside the extension
|
//If runtime_path is defined then we are executing inside the extension
|
||||||
//closure. In that case, we configure our local Webpack instance
|
//closure. In that case, we configure our local Webpack instance
|
||||||
|
@ -30,14 +32,14 @@ async function fetch_ruffle() {
|
||||||
return ruffle_module.Ruffle;
|
return ruffle_module.Ruffle;
|
||||||
}
|
}
|
||||||
|
|
||||||
let last_loaded_ruffle: any = null;
|
let last_loaded_ruffle: Promise<{ new (...args: any[]): Ruffle }> | null = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain an instance of `Ruffle`.
|
* Obtain an instance of `Ruffle`.
|
||||||
*
|
*
|
||||||
* This function returns a promise which yields `Ruffle` asynchronously.
|
* This function returns a promise which yields `Ruffle` asynchronously.
|
||||||
*/
|
*/
|
||||||
export function load_ruffle() {
|
export function load_ruffle(): Promise<{ new (...args: any[]): Ruffle }> {
|
||||||
if (last_loaded_ruffle == null) {
|
if (last_loaded_ruffle == null) {
|
||||||
last_loaded_ruffle = fetch_ruffle();
|
last_loaded_ruffle = fetch_ruffle();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,24 +30,24 @@ class RuffleMimeTypeArray implements MimeTypeArray {
|
||||||
*
|
*
|
||||||
* @param mimetype
|
* @param mimetype
|
||||||
*/
|
*/
|
||||||
install(mimetype: MimeType) {
|
install(mimetype: MimeType): void {
|
||||||
const id = this.__mimetypes.length;
|
const id = this.__mimetypes.length;
|
||||||
|
|
||||||
this.__mimetypes.push(mimetype);
|
this.__mimetypes.push(mimetype);
|
||||||
this.__named_mimetypes[mimetype.type] = mimetype;
|
this.__named_mimetypes[mimetype.type] = mimetype;
|
||||||
(<any>this)[mimetype.type] = mimetype;
|
(<Record<string, unknown>>this)[mimetype.type] = mimetype;
|
||||||
(<any>this)[id] = mimetype;
|
(<Record<string, unknown>>this)[id] = mimetype;
|
||||||
}
|
}
|
||||||
|
|
||||||
item(index: number) {
|
item(index: number): MimeType {
|
||||||
return this.__mimetypes[index];
|
return this.__mimetypes[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
namedItem(name: string) {
|
namedItem(name: string): MimeType {
|
||||||
return this.__named_mimetypes[name];
|
return this.__named_mimetypes[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
get length() {
|
get length(): number {
|
||||||
return this.__mimetypes.length;
|
return this.__mimetypes.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ class RufflePlugin extends RuffleMimeTypeArray implements Plugin {
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
install(mimetype: MimeType) {
|
install(mimetype: MimeType): void {
|
||||||
super.install(<MimeType>mimetype);
|
super.install(<MimeType>mimetype);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,28 +119,31 @@ class RufflePluginArray {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
install(plugin: Plugin | RufflePlugin) {
|
install(plugin: Plugin | RufflePlugin): void {
|
||||||
const id = this.__plugins.length;
|
const id = this.__plugins.length;
|
||||||
|
|
||||||
this.__plugins.push(plugin);
|
this.__plugins.push(plugin);
|
||||||
this.__named_plugins[plugin.name] = plugin;
|
this.__named_plugins[plugin.name] = plugin;
|
||||||
(<any>this)[plugin.name] = plugin;
|
(<Record<string, unknown>>this)[plugin.name] = plugin;
|
||||||
(<any>this)[id] = plugin;
|
(<Record<string, unknown>>this)[id] = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
item(index: number) {
|
item(index: number): Plugin {
|
||||||
return this.__plugins[index];
|
return this.__plugins[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
namedItem(name: string) {
|
namedItem(name: string): Plugin {
|
||||||
return this.__named_plugins[name];
|
return this.__named_plugins[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
get length() {
|
get length(): number {
|
||||||
return this.__plugins.length;
|
return this.__plugins.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A fake plugin designed to trigger Flash detection scripts.
|
||||||
|
*/
|
||||||
export const FLASH_PLUGIN = new RufflePlugin(
|
export const FLASH_PLUGIN = new RufflePlugin(
|
||||||
"Shockwave Flash",
|
"Shockwave Flash",
|
||||||
"Shockwave Flash 32.0 r0",
|
"Shockwave Flash 32.0 r0",
|
||||||
|
@ -181,7 +184,7 @@ FLASH_PLUGIN.install({
|
||||||
* that version of the plugin array. This allows the plugin polyfill to compose
|
* that version of the plugin array. This allows the plugin polyfill to compose
|
||||||
* across multiple plugin emulators with the first emulator's polyfill winning.
|
* across multiple plugin emulators with the first emulator's polyfill winning.
|
||||||
*/
|
*/
|
||||||
export function install_plugin(plugin: RufflePlugin) {
|
export function install_plugin(plugin: RufflePlugin): void {
|
||||||
if (!("install" in navigator.plugins) || !navigator.plugins["install"]) {
|
if (!("install" in navigator.plugins) || !navigator.plugins["install"]) {
|
||||||
Object.defineProperty(navigator, "plugins", {
|
Object.defineProperty(navigator, "plugins", {
|
||||||
value: new RufflePluginArray(navigator.plugins),
|
value: new RufflePluginArray(navigator.plugins),
|
||||||
|
|
Loading…
Reference in New Issue