WebTransport:ready 属性
注意:此功能在Web Workers中可用。
ready
是 WebTransport
接口的只读属性,它返回一个 Promise,当传输准备就绪可以使用时解析。
值
一个解析为 undefined
的Promise
。
示例
js
const url = "https://example.com:4999/wt";
async function initTransport(url) {
// Initialize transport connection
const transport = new WebTransport(url);
// The connection can be used once ready fulfills
await transport.ready;
// ...
}
// ...
async function closeTransport(transport) {
// Respond to connection closing
try {
await transport.closed;
console.log(`The HTTP/3 connection to ${url} closed gracefully.`);
} catch (error) {
console.error(`The HTTP/3 connection to ${url} closed due to ${error}.`);
}
}
规范
规范 |
---|
WebTransport # dom-webtransport-ready |
浏览器兼容性
BCD 表格仅在启用 JavaScript 的浏览器中加载。