WebTransport:closed 属性
注意:此功能在Web Workers中可用。
closed
是 WebTransport
接口的只读属性,它返回一个 Promise,该 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-closed |
浏览器兼容性
BCD 表格仅在启用 JavaScript 的浏览器中加载。