RTCIceTransport: selectedcandidatepairchange event

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

A selectedcandidatepairchange event is sent to an RTCIceTransport when the ICE agent selects a new pair of candidates that describe the endpoints of a viable connection.

The pair of candidates is in turn described by an RTCIceCandidatePair object which contains one RTCIceCandidate representing the local end of the connection, and another representing the remote end of the connection.

Together, the candidates can be used to establish a connection to be used by the RTCIceTransport, and, by extension, by an RTCPeerConnection.

This event is not cancelable and does not bubble.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

js
addEventListener("selectedcandidatepairchange", (event) => { })

onselectedcandidatepairchange = (event) => { }

Event type

A generic Event.

Examples

This example creates an event handler for selectedcandidatepairchange that updates a display providing the user information about the progress of the ICE negotiation for an RTCPeerConnection called pc.

js
let iceTransport = pc.getSenders()[0].transport.iceTransport;
let localProtoElem = document.getElementById("local-protocol");
let remoteProtoElem = document.getElementById("remote-protocol");

iceTransport.addEventListener("selectedcandidatepairchange", (ev) => {
  let pair = iceTransport.getSelectedCandidatePair();
  localProtoElem.innerText = pair.local.protocol.toUpperCase();
  remoteProtoElem.innerText = pair.remote.protocol.toUpperCase();
});

This can also be done by setting the onselectedcandidatepairchange event handler property directly.

js
let iceTransport = pc.getSenders()[0].transport.iceTransport;
let localProtoElem = document.getElementById("local-protocol");
let remoteProtoElem = document.getElementById("remote-protocol");

iceTransport.onselectedcandidatepairchange = (ev) => {
  let pair = iceTransport.getSelectedCandidatePair();
  localProtoElem.innerText = pair.local.protocol.toUpperCase();
  remoteProtoElem.innerText = pair.remote.protocol.toUpperCase();
};

Specifications

Specification
WebRTC: Real-Time Communication in Browsers
# event-icetransport-selectedcandidatepairchange
WebRTC: Real-Time Communication in Browsers
# dom-rtcicetransport-onselectedcandidatepairchange

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
selectedcandidatepairchange event
Chrome – Full support
Chrome 75 (Release date: 2019-06-04)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 62 (Release date: 2019-06-27)
footnote Full support
Safari – Full support
Safari 16.4 (Release date: 2023-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 75 (Release date: 2019-06-04)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 54 (Release date: 2019-10-18)
footnote Full support
Safari on iOS – Full support
Safari on iOS 16.4 (Release date: 2023-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 11 (Release date: 2019-12-05)
footnote Full support
WebView Android – Full support
WebView Android 75 (Release date: 2019-06-04)
footnote Full support
WebView on iOS – Full support
WebView on iOS 16.4 (Release date: 2023-03-27)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

See also