RTCIceCandidate: toJSON() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2017.

The RTCIceCandidate method toJSON() converts the RTCIceCandidate on which it's called into JSON.

A stringified version of the object can then be obtained by calling stringify() on the returned object.

Syntax

js
toJSON()

Parameters

None.

Return value

A JSON object with the following properties, which have been set to the corresponding values in the RTCIceCandidate object:

candidate Optional

A string describing the network connectivity information for the candidate. Additional information can be found in RTCIceCandidate.candidate.

sdpMid Optional

A string containing the identification tag of the media stream with which the candidate is associated, or null if there is no associated media stream. Additional information can be found in RTCIceCandidate.sdpMid.

sdpMLineIndex Optional

A number property containing the zero-based index of the m-line with which the candidate is associated, within the SDP of the media description, or null if no such associated exists. Additional information can be found in RTCIceCandidate.sdpMLineIndex.

usernameFragment Optional

A string containing the username fragment (usually referred to in shorthand as "ufrag" or "ice-ufrag"). This fragment, along with the ICE password ("ice-pwd"), uniquely identifies a single ongoing ICE interaction (including for any communication with the STUN server). Additional information can be found in RTCIceCandidate.usernameFragment.

Note: The returned JSON object has the same form/properties as the candidateInfo object that can optionally be passed to the RTCIceCandidate() constructor to configure the candidate.

Examples

This simple example obtains a JSON string representing an RTCIceCandidate found in the variable candidate.

js
let jsonString = candidate.toJSON().stringify();

Specifications

Specification
WebRTC: Real-Time Communication in Browsers
# dom-rtcicecandidate-tojson

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
toJSON
Chrome – Full support
Chrome 43 (Release date: 2015-05-19)
footnote Full support
Edge – Full support
Edge 15 (Release date: 2017-04-05)
footnote Full support
Firefox – Full support
Firefox 27 (Release date: 2014-02-04)
footnote Full support
Opera – Full support
Opera 30 (Release date: 2015-06-09)
footnote Full support
Safari – Full support
Safari 11 (Release date: 2017-09-19)
footnote Full support
Chrome Android – Full support
Chrome Android 43 (Release date: 2015-05-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 27 (Release date: 2014-02-04)
footnote Full support
Opera Android – Full support
Opera Android 30 (Release date: 2015-06-10)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11 (Release date: 2017-09-19)
footnote Full support
Samsung Internet – Full support
Samsung Internet 4 (Release date: 2016-03-11)
footnote Full support
WebView Android – Full support
WebView Android 43 (Release date: 2015-05-27)
footnote Full support
WebView on iOS – Full support
WebView on iOS 11 (Release date: 2017-09-19)
footnote Full support

Legend

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

Full support
Full support