<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Guilherme Alves</title>
    <description>The latest articles on DEV Community by Guilherme Alves (@srdevgui).</description>
    <link>https://dev.to/srdevgui</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3613859%2F735d3524-435d-484e-b689-de8460cb17fb.jpeg</url>
      <title>DEV Community: Guilherme Alves</title>
      <link>https://dev.to/srdevgui</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/srdevgui"/>
    <language>en</language>
    <item>
      <title>WebRTC - onicecandidate curiosity</title>
      <dc:creator>Guilherme Alves</dc:creator>
      <pubDate>Tue, 30 Dec 2025 17:03:31 +0000</pubDate>
      <link>https://dev.to/srdevgui/webrtc-onicecandidate-curiosity-439m</link>
      <guid>https://dev.to/srdevgui/webrtc-onicecandidate-curiosity-439m</guid>
      <description>&lt;p&gt;If you start to work with WebRTC you'll notice that &lt;code&gt;onicecandidate&lt;/code&gt; returns many types of candidates, I was wondering what are they, because in my case the connection involves only 2 phones, but I receive many other candidates.&lt;br&gt;
If you work with this event you'll probably code something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkrjw59usbr4s0qok1esl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkrjw59usbr4s0qok1esl.png" alt="my code that represents the onicecandidate event" width="800" height="134"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Which represents the phase that you see other candidates in the server. &lt;br&gt;
According to &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/icecandidate_event" rel="noopener noreferrer"&gt;MDN It does&lt;/a&gt; : &lt;em&gt;"fired to indicate that a new candidate has been gathered. This candidate needs to be delivered to the remote peer over the signaling channel your code manages."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Okay, now if we look to the logs, we'll see something like this : &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnbsrbhneoya7727sw3ej.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnbsrbhneoya7727sw3ej.png" alt="console.log() showing the prints of the event" width="800" height="539"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here comes my questions. What I discover after reading the docs is that this other candidates are simply other routes from the same phone (or any device) to ensure that the connection will occur.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why do several appear :&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The device has multiple interfaces (Wi-Fi, phone, IPv4, and IPv6), and each interface generates a "host" candidate.&lt;/li&gt;
&lt;li&gt;The STUN server map uses the public IP/NAT and generates "srflx" (server-reflexive) type candidates.&lt;/li&gt;
&lt;li&gt;If there is a TURN, "relay" candidates appear.&lt;/li&gt;
&lt;li&gt;ICE can also generate "prflx" candidates during P2P checks.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Expected behavior :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;ICE will try all options and choose the one that works best; manual filtering is not necessary in most cases.&lt;/p&gt;

&lt;p&gt;In this phase you must send this candidate (which will be picked automatically) to your backend server (probably a WebSocket). MDN docs also said the same:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F03fwlb3xa9wh2jylgo4u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F03fwlb3xa9wh2jylgo4u.png" alt="The official documents of MDN showing the instructions" width="800" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my case I'm sending a &lt;em&gt;webrtc_ice_candidate&lt;/em&gt; type message to indicate that a new candidate has gathered.&lt;/p&gt;

</description>
      <category>webrtc</category>
      <category>programming</category>
      <category>webdev</category>
      <category>rtcpeerconnection</category>
    </item>
  </channel>
</rss>
