// file: Web/game-realtime-webtransport-browser-smoke/frontend/ts/main.ts // version: 1 import init, { run_browser_smoke } from "@webtransport-browser-smoke-wasm"; function requireElement(selector: string): T { const element = document.querySelector(selector); if (element === null) { throw new Error(`Required browser smoke element is missing: ${selector}`); } return element; } function populateFromQuery(endpoint: HTMLInputElement, certificateHash: HTMLInputElement): void { const parameters = new URLSearchParams(window.location.search); const endpointValue = parameters.get("endpoint"); const hashValue = parameters.get("sha256"); if (endpointValue !== null) { endpoint.value = endpointValue; } if (hashValue !== null) { certificateHash.value = hashValue; } } async function main(): Promise { const environmentStatus = requireElement("#environment-status"); const endpoint = requireElement("#endpoint"); const certificateHash = requireElement("#certificate-hash"); const run = requireElement("#run"); const result = requireElement("#result"); populateFromQuery(endpoint, certificateHash); if (!window.isSecureContext) { environmentStatus.textContent = "FAIL: page is not running in a secure context"; run.disabled = true; return; } if (!("WebTransport" in window)) { environmentStatus.textContent = "FAIL: this browser does not expose WebTransport"; run.disabled = true; return; } await init(); environmentStatus.textContent = "Secure context and WebTransport available; WASM loaded"; run.addEventListener("click", () => { run.disabled = true; result.textContent = "RUNNING"; void run_browser_smoke(endpoint.value.trim(), certificateHash.value.trim()) .then(message => { result.textContent = message; }) .catch(caughtError => { result.textContent = `game-realtime-webtransport-browser-smoke: FAIL: ${String(caughtError)}`; }) .finally(() => { run.disabled = false; }); }); if (endpoint.value.length > 0 && certificateHash.value.length > 0) { run.click(); } } void main().catch(caughtError => { const result = document.querySelector("#result"); if (result !== null) { result.textContent = `game-realtime-webtransport-browser-smoke: FAIL: ${String(caughtError)}`; } });