RTCDTMFSender: canInsertDTMF 属性

Baseline 2024
新推出

自 ⁨2024 年 8 月⁩起,此功能可在最新的设备和浏览器版本上使用。此功能可能无法在旧设备或浏览器上使用。

canInsertDTMFRTCDTMFSender 接口的一个只读属性,它返回一个布尔值,指示 RTCDTMFSender 是否能够通过 RTCPeerConnection 发送 DTMF 信号音。

如果 RTCDTMFSender 能够发送 DTMF 信号音,则返回 true;否则返回 false

示例

使用 canInsertDTMF 检查 DTMF 支持情况

此示例演示如何使用 canInsertDTMF 属性在 WebRTC 连接中检查 DTMF 支持情况,然后在支持的情况下发送信号音。

代码首先检查 canInsertDTMF 属性是否已定义,如果已定义,则使用它来检查是否支持插入 DTMF 信号音。如果支持该功能,则会调用 RTCDTMFSender.insertDTMF() 来插入信号音。

js
if (sender.dtmf.canInsertDTMF) {
  const duration = 500;
  sender.dtmf.insertDTMF("1234", duration);
} else {
  console.log("DTMF function not available");
}

规范

规范
WebRTC:浏览器中的实时通信
# dom-rtcdtmfsender-caninsertdtmf

浏览器兼容性

另见