WebTransport: ready 属性
注意:此功能在 Web Workers 中可用。
ready 是 WebTransport 接口的一个只读属性,它返回一个 Promise,该 Promise 在传输准备好使用时解析。
此 Promise 在创建 WebTransport 对象时创建,并在建立连接时解析。访问或等待此 Promise 不会触发任何操作;它只允许在传输准备就绪时执行操作,类似于监听事件。
值
一个 Promise,解析为 undefined。
示例
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 |
浏览器兼容性
加载中…