web: Add callExternalInterface to PlayerV1
This commit is contained in:
parent
04f640b926
commit
b6477d62bf
|
@ -102,4 +102,8 @@ export class PlayerV1Impl implements PlayerV1 {
|
|||
set config(value: URLLoadOptions | DataLoadOptions | object) {
|
||||
this.#inner.config = value;
|
||||
}
|
||||
|
||||
callExternalInterface(name: string, ...args: unknown[]): unknown {
|
||||
return this.#inner.callExternalInterface(name, args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,4 +158,16 @@ export interface PlayerV1 {
|
|||
* @param message The message shown to the user.
|
||||
*/
|
||||
displayMessage(message: string): void;
|
||||
|
||||
/**
|
||||
* Calls an External Interface callback with the given name and arguments.
|
||||
*
|
||||
* This will call any ActionScript code assigned to the given name.
|
||||
* If no such External Interface callback exists with the given name, this method silently fails and returns `undefined`.
|
||||
*
|
||||
* @param name Name of the callback to call.
|
||||
* @param args Any arguments to pass to the callback.
|
||||
* @returns Any value returned by the callback.
|
||||
*/
|
||||
callExternalInterface(name: string, ...args: unknown[]): unknown;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
} from "../../utils.js";
|
||||
import { expect, use } from "chai";
|
||||
import chaiHtml from "chai-html";
|
||||
import { APIVersions } from "ruffle-core";
|
||||
|
||||
use(chaiHtml);
|
||||
|
||||
|
@ -50,6 +51,10 @@ declare global {
|
|||
|
||||
// Going to be redefined as part of a test
|
||||
redefinedMethod: () => string;
|
||||
|
||||
ruffle<V extends keyof APIVersions = 1>(
|
||||
version?: V,
|
||||
): APIVersions[V];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,7 +140,7 @@ ExternalInterface.objectID: "flash_name"
|
|||
);
|
||||
});
|
||||
|
||||
it("returns a value", async () => {
|
||||
it("returns a value with legacy API", async () => {
|
||||
const player = await browser.$("<ruffle-object>");
|
||||
const returned = await browser.execute(
|
||||
(player) => player.returnAValue(123.4),
|
||||
|
@ -154,6 +159,26 @@ ExternalInterface.objectID: "flash_name"
|
|||
);
|
||||
});
|
||||
|
||||
it("returns a value with V1 API", async () => {
|
||||
const player = await browser.$("<ruffle-object>");
|
||||
const returned = await browser.execute(
|
||||
(player) =>
|
||||
player.ruffle().callExternalInterface("returnAValue", 123.4),
|
||||
player,
|
||||
);
|
||||
|
||||
expect(returned).to.eql(123.4);
|
||||
|
||||
const actualOutput = await getTraceOutput(browser, player);
|
||||
expect(actualOutput).to.eql(
|
||||
`returnAValue called with 123.4
|
||||
[
|
||||
123.4
|
||||
]
|
||||
`,
|
||||
);
|
||||
});
|
||||
|
||||
it("calls a method with delay", async () => {
|
||||
const player = await browser.$("<ruffle-object>");
|
||||
await browser.execute(
|
||||
|
|
Loading…
Reference in New Issue