过时
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
RTCIceCandidateStats
dictionary's
networkType
property specifies the type of network used by a local candidate to communicate with a remote peer.
注意:
networkType
property is only included in
RTCIceCandidateStats
objects for local candidates (that is, candidates generated locally and included in an
SDP
offer or answer that has been sent to the remote peer).
networkType = rtcIceCandidateStats.networkType;
A
DOMString
whose value is taken from the
RTCNetworkType
enumerated type. The string indicates the type of network connection that the described candidate would use to communicate with the other peer.
The permitted values are:
bluetooth
A Bluetooth connection is used by the described connection.
cellular
The connection uses a cellular data service to connect. This includes all cellular data services including EDGE (2G), HSPA (3G), LTE (4G), and NR (5G).
ethernet
The described connection uses an Ethernet network.
wifi
The described connection uses WiFi.
wimax
vpn
The connection uses a Virtual Private Network (VPN). The VPN obscures the underlying network type, which is not discernible.
未知
注意:
Keep in mind that the specified value only reflects the initial connection between the local peer and the next hop along the network toward reaching the remote peer. For example, if the
networkType
is
wifi
but the user is connected using a cellular hotspot, the connection will be bottlenecked by the underlying cellular network (and any other networks between the two peers).
This example sets up a periodic function using
setInterval()
that outputs statistics reports for candidates that use or would use a cellular data network to a log view.
window.setInterval(function() {
myPeerConnection.getStats(null).then(stats => {
let statsOutput = "";
stats.forEach(report => {
if ((stats.type === "local-candidate" || stats.type === "remote.candidate") && stats.networkType === "cellular") {
statsOutput += `<h2>Report: ${report.type}</h3>\n<strong>ID:</strong> ${report.id}<br>\n` +
`<strong>Timestamp:</strong> ${report.timestamp}<br>\n`;
// Now the statistics for this report; we intentially drop the ones we
// sorted to the top above
Object.keys(report).forEach(statName => {
if (statName !== "id" && statName !== "timestamp" && statName !== "type") {
statsOutput += `<strong>${statName}:</strong> ${report[statName]}<br>\n`;
}
});
}
});
document.querySelector(".stats-box").innerHTML = statsOutput;
});
}, 1000);
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
networkType
弃用
非标
|
Chrome No | Edge No | Firefox No | IE No | Opera ? | Safari ? | WebView Android No | Chrome Android No | Firefox Android No | Opera Android ? | Safari iOS ? | Samsung Internet Android No |
不支持
兼容性未知
非标。预期跨浏览器支持较差。
弃用。不要用于新网站。
RTCIceCandidateStats
address
deleted
mozLocalTransport
networkType
port
协议
relayProtocol
transportId
url
MediaDevices.getUserMedia()
Navigator.mediaDevices
RTCCertificate
RTCDTMFSender
RTCDTMFToneChangeEvent
RTCDataChannel
RTCDataChannelEvent
RTCDtlsTransport
RTCErrorEvent
RTCIceCandidate
RTCIceTransport
RTCPeerConnection
RTCPeerConnectionIceErrorEvent
RTCPeerConnectionIceEvent
RTCRtpReceiver
RTCRtpSender
RTCRtpTransceiver
RTCSctpTransport
RTCSessionDescription
RTCStatsEvent
RTCStatsReport
RTCTrackEvent