RTCIceCandidate. toJSON()
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
toJSON()
Return value
A JSON object with the following properties, which have been set to the corresponding values in the RTCIceCandidate object:
-
candidateOptional -
A
DOMStringdescribing the network connectivity information for the candidate. Additional information can be found inRTCIceCandidate.candidate. -
sdpMidOptional -
A
DOMStringcontaining the identification tag of the media stream with which the candidate is associated, ornullif there is no associated media stream. Additional information can be found inRTCIceCandidate.sdpMid. -
sdpMLineIndexOptional -
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
nullif no such associated exists. Additional information can be found inRTCIceCandidate.sdpMLineIndex. -
usernameFragmentOptional -
A
DOMStringcontaining 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 inRTCIceCandidate.usernameFragment.
Note: The returned JSON object has the the same form/properties as the candidateInfo object that can optionally be passed to the RTCIceCandidate() constructor to configure the candidate.
Example
This simple example obtains a JSON string representing an RTCIceCandidate found in the variable candidate.
let jsonString = candidate.toJSON().stringify();
Specifications
| Specification |
|---|
| WebRTC 1.0: Real-Time Communication Between Browsers (WebRTC 1.0) # dom-rtcicecandidate-tojson |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
toJSON |
45 |
15 |
27 |
No |
32 |
11 |
45 |
45 |
27 |
32 |
11 |
5.0 |
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidate/toJSON