const url = "https://example.com:4999/wt";
async function initTransport(url) {
const transport = new WebTransport(url, {
protocols: ["chat", "file-transfer"],
});
try {
// The connection can be used once ready fulfills
await transport.ready;
console.log(transport.protocol); // e.g. "chat", or "" if none was selected
return transport;
} catch (error) {
// Ready may reject if the offered protocols aren't supported
console.error(`Connection failed: ${error}`);
}
}
initTransport(url);WebTransport: protocol property / notebook
WebTransport: protocol property
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.