RTCIceCandidate
Signature
const candidate = new RTCIceCandidate(candidateInit);
// candidateInit: { candidate, sdpMid, sdpMLineIndex, usernameFragment }
What it does
Describes one candidate transport address discovered during ICE gathering. Candidates are exchanged over signaling and added to the connection until a working pair is found.
Key members
| Member | Kind | Purpose |
|---|---|---|
candidate |
property | The raw SDP candidate attribute string. |
sdpMid |
property | The media stream identification this candidate applies to. |
sdpMLineIndex |
property | Index of the m-line in the SDP. |
usernameFragment |
property | The ICE ufrag the candidate belongs to. |
foundation |
property | Identifier shared by candidates of the same type and base. |
protocol |
property | Transport protocol: udp or tcp. |
type |
property | Candidate type: host, srflx, prflx, or relay. |
address / port |
property | The candidate's IP address and port. |
Behaviour & constraints
- Most read-only members are
nulluntil thecandidatestring is parsed by the browser. - Pass the object received from the remote
icecandidateevent straight toaddIceCandidate(). - An empty
candidatestring signals end-of-candidates for that generation. typerelaymeans a TURN server is in the path; STUN-only setups never produce relay candidates.- Candidates are useless without their
sdpMidorsdpMLineIndexto bind them to a media section.
Example
pc.onicecandidate = ({ candidate }) => {
if (candidate) signalingSend(candidate.toJSON());
};
// remote side
signalingOn('candidate', (init) => {
pc.addIceCandidate(new RTCIceCandidate(init));
});