WebTransport:reliability 属性

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

实验性: 这是一项实验性技术
在生产中使用此技术之前,请仔细检查浏览器兼容性表格

安全上下文: 此功能仅在安全上下文(HTTPS)中可用,且支持此功能的浏览器数量有限。

注意:此功能在 Web Workers 中可用。

reliabilityWebTransport 接口的一个只读属性,它指示连接是仅支持可靠传输,还是也支持不可靠传输(例如 UDP)。

一个字符串,其值可能为以下之一:

pending

连接尚未建立。可靠性尚不确定。

reliable-only

连接仅支持可靠传输。

supports-unreliable

连接同时支持不可靠传输和可靠传输。

示例

js
const url = "https://example.com:4999/wt";

async function initTransport(url) {
  // Initialize transport connection
  const transport = new WebTransport(url);

  // Once ready fulfils the connection can be used
  // Prior to this the reliability is "pending"
  await transport.ready;

  if (transport.reliability === "reliable-only") {
    // Use connection only with reliable transports
  } else {
    // Use connection with either reliable or unreliable transports.
  }
  // …
}

规范

规范
WebTransport
# dom-webtransport-reliability

浏览器兼容性