Skip to content

Commit

Permalink
web: Move player stuff to Player module
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinnerbone committed Oct 6, 2024
1 parent c50c0f9 commit 9576c2e
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 33 deletions.
5 changes: 1 addition & 4 deletions web/packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@

export * as Setup from "./public/setup";
export * as Config from "./public/config";
export * as Player from "./public/player";
export * from "./build-info";
export * from "./movie-metadata";
export * from "./public/flash";
export * from "./public/legacy";
export * from "./public/player-element";
2 changes: 1 addition & 1 deletion web/packages/core/src/internal/internal-source-api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { buildInfo } from "../build-info";
import { pluginPolyfill, polyfill } from "../polyfills";
import { PlayerElement } from "../public/player-element";
import { PlayerElement } from "../public/player";
import { registerElement } from "./register-element";
import { RufflePlayerElement } from "./player/ruffle-player-element";
import { InstallationOptions } from "../public/setup";
Expand Down
2 changes: 1 addition & 1 deletion web/packages/core/src/internal/player/inner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
WindowMode,
DEFAULT_CONFIG,
} from "../../public/config";
import type { MovieMetadata } from "../../movie-metadata";
import type { MovieMetadata } from "../../public/player";
import { ruffleShadowTemplate } from "../ui/shadow-template";
import { text, textAsParagraphs } from "../i18n";
import { swfFileName } from "../../swf-utils";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { DataLoadOptions, URLLoadOptions } from "../../public/config";
import type { MovieMetadata } from "../../movie-metadata";
import type { MovieMetadata, PlayerElement } from "../../public/player";
import { InnerPlayer, ReadyState } from "./inner";
import { PlayerElement } from "../../public/player-element";

/**
* The ruffle player element that should be inserted onto the page.
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions web/packages/core/src/public/player/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from "./flash";
export * from "./player-element";
export * from "./movie-metadata";
export * from "./legacy";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DataLoadOptions, URLLoadOptions } from "./config";
import { MovieMetadata } from "../movie-metadata";
import { ReadyState } from "../internal/player/inner";
import { DataLoadOptions, URLLoadOptions } from "../config";
import { MovieMetadata } from "./movie-metadata";
import { ReadyState } from "../../internal/player/inner";

/**
* Legacy interface to the Ruffle API.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion web/packages/core/src/public/setup/source-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PlayerElement } from "../player-element";
import { PlayerElement } from "../player";

/**
* Represents this particular version of Ruffle.
Expand Down
6 changes: 4 additions & 2 deletions web/packages/demo/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Player } from "./player.tsx";
import { useRef, useState, DragEvent, useCallback } from "react";
import type { Config, MovieMetadata } from "ruffle-core";
import type { Config, Player as RufflePlayer } from "ruffle-core";
import { Navbar } from "./navbar.tsx";
import { MetadataPanel } from "./metadata.tsx";

Expand All @@ -15,7 +15,9 @@ export function App({
allowUrlLoading,
allowSampleSwfs,
}: AppProperties) {
const [metadata, setMetadata] = useState<MovieMetadata | null>(null);
const [metadata, setMetadata] = useState<RufflePlayer.MovieMetadata | null>(
null,
);
const [metadataVisible, setMetadataVisible] = useState<boolean>(false);
const [selectedFilename, setSelectedFilename] = useState<string | null>(
null,
Expand Down
6 changes: 3 additions & 3 deletions web/packages/demo/src/metadata.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { MovieMetadata } from "ruffle-core";
import { Player } from "ruffle-core";

interface MetadataProps {
visible: boolean;
metadata: MovieMetadata | null;
metadata: Player.MovieMetadata | null;
}

const swfToFlashVersion: { [key: number]: string } = {
Expand Down Expand Up @@ -68,7 +68,7 @@ export function MetadataPanel({ visible, metadata }: MetadataProps) {
<span>FP Version</span>
<span id="flashVersion">
{metadata
? swfToFlashVersion[metadata.swfVersion] ?? "Unknown"
? (swfToFlashVersion[metadata.swfVersion] ?? "Unknown")
: ""}
</span>
</div>
Expand Down
6 changes: 3 additions & 3 deletions web/packages/demo/src/player.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { ReactNode, DragEvent } from "react";
import { Setup, PlayerElement, MovieMetadata, Config } from "ruffle-core";
import { Setup, Player as RufflePlayer, Config } from "ruffle-core";

export interface PlayerAttributes {
id?: string | undefined;
children?: ReactNode;
onLoadedMetadata: (metadata: MovieMetadata) => void;
onLoadedMetadata: (metadata: RufflePlayer.MovieMetadata) => void;
baseConfig?: Config.BaseLoadOptions;
onDragEnter: (event: DragEvent<HTMLElement>) => void;
onDragLeave: (event: DragEvent<HTMLElement>) => void;
Expand All @@ -14,7 +14,7 @@ export interface PlayerAttributes {

export class Player extends React.Component<PlayerAttributes> {
private readonly container: React.RefObject<HTMLDivElement>;
private player: PlayerElement | null = null;
private player: RufflePlayer.PlayerElement | null = null;

// [NA] Ruffle has a bug where if you load a swf whilst it's already loading another swf, it breaks
// Combine this with React testing everything by loading things twice to catch bugs - well, they caught the bug for sure.
Expand Down
4 changes: 2 additions & 2 deletions web/packages/extension/src/player.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as utils from "./utils";
import { Setup } from "ruffle-core";

import type { Config, PlayerElement } from "ruffle-core";
import type { Config, Player } from "ruffle-core";

declare global {
interface Navigator {
Expand All @@ -15,7 +15,7 @@ declare global {

Setup.installRuffle("local");
const ruffle = (window.RufflePlayer as Setup.PublicAPI).newest()!;
let player: PlayerElement;
let player: Player.PlayerElement;

const playerContainer = document.getElementById("player-container")!;
const overlay = document.getElementById("overlay")!;
Expand Down
4 changes: 2 additions & 2 deletions web/packages/selfhosted/test/js_api/load.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { loadJsAPI, playAndMonitor } from "../utils.js";
import { use } from "chai";
import chaiHtml from "chai-html";
import { PlayerElement } from "ruffle-core";
import { Player } from "ruffle-core";

use(chaiHtml);

Expand All @@ -12,7 +12,7 @@ describe("RufflePlayer.load", () => {
const player = await browser.$("<ruffle-player>");
await browser.execute(async (playerElement) => {
// https://github.com/webdriverio/webdriverio/issues/6486
const player = playerElement as unknown as PlayerElement;
const player = playerElement as unknown as Player.PlayerElement;
await player.load("/test_assets/example.swf");
}, player);
await playAndMonitor(browser, player);
Expand Down
4 changes: 2 additions & 2 deletions web/packages/selfhosted/test/js_api/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { loadJsAPI } from "../utils.js";
import { expect, use } from "chai";
import chaiHtml from "chai-html";
import { PlayerElement } from "ruffle-core";
import { Player } from "ruffle-core";

use(chaiHtml);

Expand All @@ -12,7 +12,7 @@ describe("RufflePlayer.metadata", () => {
const player = await browser.$("<ruffle-player>");
const metadata = await browser.execute(
// https://github.com/webdriverio/webdriverio/issues/6486
(player) => (player as unknown as PlayerElement).metadata,
(player) => (player as unknown as Player.PlayerElement).metadata,
player,
);
// [NA] Work around a chrome 87 bug where it's (somehow) adding extra data to this object
Expand Down
15 changes: 8 additions & 7 deletions web/packages/selfhosted/test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expect } from "chai";
import { PlayerElement, Setup } from "ruffle-core";
import { Player, Setup } from "ruffle-core";

declare global {
interface Window {
ruffleErrors: ErrorEvent[];
}
}

declare module "ruffle-core" {
declare module "ruffle-core/dist/public/player" {
interface PlayerElement {
__ruffle_log__: string;
}
Expand All @@ -31,7 +31,7 @@ export async function isRufflePlayerLoaded(
(player) =>
// https://github.com/webdriverio/webdriverio/issues/6486
// TODO: How can we import ReadyState enum?
(player as unknown as PlayerElement).readyState,
(player as unknown as Player.PlayerElement).readyState,
player,
)) === 2
);
Expand Down Expand Up @@ -103,7 +103,7 @@ export async function setupAndPlay(
) {
await browser.execute((playerElement) => {
// https://github.com/webdriverio/webdriverio/issues/6486
const player = playerElement as unknown as PlayerElement;
const player = playerElement as unknown as Player.PlayerElement;
player.__ruffle_log__ = "";
player.traceObserver = (msg) => {
player.__ruffle_log__ += msg + "\n";
Expand All @@ -122,7 +122,8 @@ export async function getTraceOutput(
return (
(await browser.execute((player) => {
// https://github.com/webdriverio/webdriverio/issues/6486
return (player as unknown as PlayerElement).__ruffle_log__;
return (player as unknown as Player.PlayerElement)
.__ruffle_log__;
}, player)) !== ""
);
},
Expand All @@ -134,7 +135,7 @@ export async function getTraceOutput(
// Get the output, and replace it with an empty string for any future test
return await browser.execute((playerElement) => {
// https://github.com/webdriverio/webdriverio/issues/6486
const player = playerElement as unknown as PlayerElement;
const player = playerElement as unknown as Player.PlayerElement;
const log = player.__ruffle_log__;
player.__ruffle_log__ = "";
return log;
Expand Down Expand Up @@ -190,7 +191,7 @@ export function loadJsAPI(swf?: string) {
await browser.execute(
async (player, swf) => {
// https://github.com/webdriverio/webdriverio/issues/6486
await (player as unknown as PlayerElement).load(swf);
await (player as unknown as Player.PlayerElement).load(swf);
},
player,
swf,
Expand Down

0 comments on commit 9576c2e

Please sign in to comment.