0.3.5-alpha.7
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>games.sasedev WebTransport browser smoke</title>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>WebTransport browser smoke</h1>
|
||||
<p id="environment-status">Checking browser environment…</p>
|
||||
<label>
|
||||
WebTransport endpoint
|
||||
<input id="endpoint" type="text" size="72" autocomplete="off">
|
||||
</label>
|
||||
<br>
|
||||
<label>
|
||||
Certificate SHA-256
|
||||
<input id="certificate-hash" type="text" size="72" autocomplete="off">
|
||||
</label>
|
||||
<br>
|
||||
<button id="run" type="button">Run smoke</button>
|
||||
<pre id="result">IDLE</pre>
|
||||
</main>
|
||||
<script type="module" src="./ts/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,69 @@
|
||||
// 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<T extends Element>(selector: string): T {
|
||||
const element = document.querySelector<T>(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<void> {
|
||||
const environmentStatus = requireElement<HTMLParagraphElement>("#environment-status");
|
||||
const endpoint = requireElement<HTMLInputElement>("#endpoint");
|
||||
const certificateHash = requireElement<HTMLInputElement>("#certificate-hash");
|
||||
const run = requireElement<HTMLButtonElement>("#run");
|
||||
const result = requireElement<HTMLPreElement>("#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<HTMLPreElement>("#result");
|
||||
if (result !== null) {
|
||||
result.textContent = `game-realtime-webtransport-browser-smoke: FAIL: ${String(caughtError)}`;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user