2020-11-17 21:53:04 +00:00
|
|
|
import { pluginPolyfill, polyfill } from "./polyfills";
|
2020-11-17 19:54:58 +00:00
|
|
|
import { registerElement } from "./register-element";
|
2020-11-12 22:32:53 +00:00
|
|
|
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:23:10 +00:00
|
|
|
* @param name The name of this particular source.
|
2019-10-15 02:52:53 +00:00
|
|
|
*/
|
2020-11-14 21:23:10 +00:00
|
|
|
constructor(name: string) {
|
|
|
|
this.name = 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.
|
2020-11-17 22:53:17 +00:00
|
|
|
*
|
|
|
|
* @returns The version of this Ruffle source
|
2020-11-14 21:20:42 +00:00
|
|
|
*/
|
|
|
|
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:21:35 +00:00
|
|
|
pluginPolyfill(): void {
|
2020-11-17 21:53:04 +00:00
|
|
|
pluginPolyfill();
|
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:22:28 +00:00
|
|
|
createPlayer(): RufflePlayer {
|
2020-11-17 19:54:58 +00:00
|
|
|
const name = registerElement("ruffle-player", RufflePlayer);
|
2020-11-14 21:23:10 +00:00
|
|
|
return <RufflePlayer>document.createElement(name);
|
2019-10-20 19:14:02 +00:00
|
|
|
}
|
2020-11-12 22:32:53 +00:00
|
|
|
}
|