RTCIceCandidate.relatedPort - Web APIs 编辑

The RTCIceCandidate interface's read-only relatedPort property indicates the port number of reflexive or relay candidates. If the candidate is a host candidate (that is, its ip is in fact the real IP address of the remote peer), relatedPort is null.

The relatedPort field's value is set when the RTCIceCandidate() constructor is used. You can't specify the value of relatedPort in the options object, but the address is automatically extracted from the candidate a-line, if it's formatted properly, being taken from its rel-port field.

The related address (relatedAddress) and port are not used at all by ICE itself; they are provided for analysis and diagnostic purposes only, and their inclusion may be blocked by security systems, so do not rely on them having non-null values.

Syntax

var relPort = RTCIceCandidate.relatedPort;

Value

An unsigned 16-bit value containing the candidate's related port number, if any. For both peer and server reflexive candidates, the related address and port describe the base for that candidate. For relay candidates, the related address and port provide the mapped address selected by the TURN server.

For host candidates, relatedPort is null, meaning the field is not included in the candidate's a-line.

Usage notes

The related address and port are not used by ICE itself, and are only present for diagnostic and Quality-of-Service purposes. They may in fact be omitted for security reasons, but if present can be a useful tool during debugging. See the example, which shows a bit of this.

Here's an SDP attribute line (a-line) describing an ICE candidate discovered by the STUN server:

a=candidate:4234997325 1 udp 2043278322 192.168.0.56 6502 typ srflx raddr 192.168.2.77 rport 32768 generation 0

The remote port, relatedPort, is the number immediately following the "rport" label on the a-line, or 32768.

Example

In this example, the candidate's type is checked, and then debugging output is presented, based on the candidate type, including the candidate's type, address (ip and port), and related address (relatedAddress and relatedPort).

var ip = candidate.ip;
var port = candidate.port;
var relIP = candidate.relatedAddress;
var relPort = candidate.relatedPort;

if (relIP && relPort) {
  console.log("Candidate type '" + type + "' -- contact address: " + ip + " " + port + ", related address: " + relIP + " " + relPort);
} else {
  console.log("Host candidate address is " + ip + " " + port);
}

Specifications

SpecificationStatusComment
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCIceCandidate.relatedPort' in that specification.
Candidate RecommendationInitial definition.

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:51 次

字数:5884

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文