No public description

PiperOrigin-RevId: 565755048
This commit is contained in:
Sebastian Schmidt 2023-09-15 12:52:31 -07:00 committed by Copybara-Service
parent a933e324b5
commit 94477b1342
3 changed files with 42 additions and 21 deletions

View File

@ -60,6 +60,7 @@ mediapipe_ts_library(
":graph_runner_factory_api", ":graph_runner_factory_api",
":listener_types", ":listener_types",
":platform_utils", ":platform_utils",
":run_script_helper",
":wasm_module_private", ":wasm_module_private",
], ],
) )
@ -98,6 +99,18 @@ mediapipe_ts_library(
deps = [":platform_utils"], deps = [":platform_utils"],
) )
genrule(
name = "run_script_genrule",
srcs = ["run_script_helper.ts.template"],
outs = ["run_script_helper.ts"],
cmd = "cp $< $@",
)
mediapipe_ts_library(
name = "run_script_helper",
srcs = ["run_script_helper.ts"],
)
jasmine_node_test( jasmine_node_test(
name = "platform_utils_test", name = "platform_utils_test",
deps = [ deps = [

View File

@ -1,6 +1,6 @@
// Placeholder for internal dependency on assertTruthy // Placeholder for internal dependency on assertTruthy
// Placeholder for internal dependency on jsloader
import {isWebKit} from '../../web/graph_runner/platform_utils'; import {isWebKit} from '../../web/graph_runner/platform_utils';
import {runScript} from '../../web/graph_runner/run_script_helper';
// Placeholder for internal dependency on trusted resource url // Placeholder for internal dependency on trusted resource url
import {GraphRunnerApi, ImageSource} from './graph_runner_api'; import {GraphRunnerApi, ImageSource} from './graph_runner_api';
@ -717,26 +717,6 @@ export class GraphRunner implements GraphRunnerApi {
} }
} }
// Quick private helper to run the given script safely
async function runScript(scriptUrl: string|string) {
if (typeof importScripts === 'function') {
importScripts(scriptUrl.toString());
} else {
const script = document.createElement('script');
script.setAttribute('src', scriptUrl);
script.setAttribute('crossorigin', 'anonymous');
return new Promise<void>((resolve) => {
script.addEventListener('load', () => {
resolve();
}, false);
script.addEventListener('error', () => {
resolve();
}, false);
document.body.appendChild(script);
});
}
}
/** {@override CreateMediaPipeLibApi} */ /** {@override CreateMediaPipeLibApi} */
export const createMediaPipeLib: CreateMediaPipeLibApi = async<LibType>( export const createMediaPipeLib: CreateMediaPipeLibApi = async<LibType>(
constructorFcn: WasmMediaPipeConstructor<LibType>, constructorFcn: WasmMediaPipeConstructor<LibType>,

View File

@ -0,0 +1,28 @@
// Placeholder for internal dependency on jsloader
// Placeholder for internal dependency on trusted resource url
/**
* Fetches each URL in urls, executes them one-by-one in the order they are
* passed, and then returns (or throws if something went amiss).
*/
declare function importScripts(...urls: Array<string|URL>): void;
// Quick helper to run the given script safely
export async function runScript(scriptUrl: string) {
if (typeof importScripts === 'function') {
importScripts(scriptUrl.toString());
} else {
const script = document.createElement('script');
script.setAttribute('src', scriptUrl);
script.setAttribute('crossorigin', 'anonymous');
return new Promise<void>((resolve, revoke) => {
script.addEventListener('load', () => {
resolve();
}, false);
script.addEventListener('error', e => {
revoke(e);
}, false);
document.body.appendChild(script);
});
}
}