2020-11-14 21:20:42 +00:00
|
|
|
import { plugin_polyfill, polyfill } from "./polyfills";
|
2020-11-12 22:32:53 +00:00
|
|
|
import { register_element } from "./register-element";
|
|
|
|
import { RufflePlayer } from "./ruffle-player";
|
2019-10-13 02:01:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents this particular version of Ruffle.
|
2020-05-12 22:24:41 +00:00
|
|
|
*
|
2019-10-13 02:01:01 +00:00
|
|
|
* Multiple APIs can be instantiated from different sources; e.g. an "extension"
|
|
|
|
* version, versus a "local" version. This expresses to the Public API
|
2020-11-14 21:20:42 +00:00
|
|
|
* negotiator (see [[PublicAPI]]) what this particular version of Ruffle is and
|
2019-10-13 02:01:01 +00:00
|
|
|
* how to control it.
|
|
|
|
*/
|
2020-11-12 22:32:53 +00:00
|
|
|
export class SourceAPI {
|
|
|
|
private name: string;
|
2020-11-14 21:20:42 +00:00
|
|
|
|
2019-10-15 02:52:53 +00:00
|
|
|
/**
|
|
|
|
* Construct a Source API.
|
2020-05-12 22:24:41 +00:00
|
|
|
*
|
2020-11-14 21:20:42 +00:00
|
|
|
* @param source_name The name of this particular source.
|
2019-10-15 02:52:53 +00:00
|
|
|
*/
|
2020-11-12 22:32:53 +00:00
|
|
|
constructor(source_name: string) {
|
2020-05-12 21:36:51 +00:00
|
|
|
this.name = source_name;
|
2019-10-15 02:52:53 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 21:20:42 +00:00
|
|
|
/**
|
|
|
|
* The version of this particular API.
|
|
|
|
*
|
|
|
|
* This is returned as a string in a semver compatible format.
|
|
|
|
*/
|
|
|
|
get version(): string {
|
2019-10-13 02:01:01 +00:00
|
|
|
return "0.1.0";
|
|
|
|
}
|
2020-05-12 22:24:41 +00:00
|
|
|
|
2019-10-14 18:56:30 +00:00
|
|
|
/**
|
2020-08-12 02:22:06 +00:00
|
|
|
* Start up the polyfills.
|
2020-05-12 22:24:41 +00:00
|
|
|
*
|
2019-10-20 19:14:02 +00:00
|
|
|
* Do not run polyfills for more than one Ruffle source at a time.
|
2019-10-14 18:56:30 +00:00
|
|
|
*/
|
2020-11-14 21:20:42 +00:00
|
|
|
polyfill(): void {
|
2020-08-12 02:22:06 +00:00
|
|
|
polyfill();
|
|
|
|
}
|
2020-11-14 21:20:42 +00:00
|
|
|
|
2020-08-12 02:22:06 +00:00
|
|
|
/**
|
|
|
|
* Polyfill the plugin detection.
|
|
|
|
*
|
|
|
|
* This needs to run before any plugin detection script does.
|
|
|
|
*/
|
2020-11-14 21:20:42 +00:00
|
|
|
plugin_polyfill(): void {
|
2020-08-12 02:22:06 +00:00
|
|
|
plugin_polyfill();
|
2019-10-13 02:01:01 +00:00
|
|
|
}
|
2020-05-12 22:24:41 +00:00
|
|
|
|
2019-10-20 19:14:02 +00:00
|
|
|
/**
|
|
|
|
* Create a Ruffle player element using this particular version of Ruffle.
|
2020-05-12 22:24:41 +00:00
|
|
|
*
|
2020-11-14 21:20:42 +00:00
|
|
|
* @returns The player element. This is a DOM element that may be inserted
|
|
|
|
* into the current page as you wish.
|
2019-10-20 19:14:02 +00:00
|
|
|
*/
|
2020-11-14 21:20:42 +00:00
|
|
|
create_player(): RufflePlayer {
|
2020-11-12 22:32:53 +00:00
|
|
|
const player_element_name = register_element(
|
2020-05-12 22:24:41 +00:00
|
|
|
"ruffle-player",
|
|
|
|
RufflePlayer
|
|
|
|
);
|
2020-11-14 21:20:42 +00:00
|
|
|
return <RufflePlayer>document.createElement(player_element_name);
|
2019-10-20 19:14:02 +00:00
|
|
|
}
|
2020-11-12 22:32:53 +00:00
|
|
|
}
|