<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>186302</bug_id>
          
          <creation_ts>2018-06-04 23:08:05 -0700</creation_ts>
          <short_desc>iOS does not call onIceCandidate</short_desc>
          <delta_ts>2018-06-07 14:47:42 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebRTC</component>
          <version>Safari 11</version>
          <rep_platform>iPhone / iPad</rep_platform>
          <op_sys>iOS 11</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>174500</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>philipp.kuederli</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>youennf</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1430048</commentid>
    <comment_count>0</comment_count>
    <who name="">philipp.kuederli</who>
    <bug_when>2018-06-04 23:08:05 -0700</bug_when>
    <thetext>I can create a data channels for the following:
- MacOS Safari 11.1.1 (on older it did not work)
- Chrome (always worked)
- Android (always worked)

However onIceCandidate is never called on iOS. 

The latest try was with iOS 11.3.1. 

The following offer was created without candidates: 

v=0
o=- 1552489341325168126 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE data
a=msid-semantic: WMS
m=application 9 DTLS/SCTP 5000
c=IN IP4 0.0.0.0
a=ice-ufrag:QqDF
a=ice-pwd:X9yzupGuGY8xQ6NbGWMHZtVD
a=ice-options:trickle
a=fingerprint:sha-256 0A:DE:0F:E5:C4:3B:BC:34:93:CF:91:CE:12:9A:D1:B7:39:79:3B:B7:F5:CD:BE:F0:A4:2D:D5:49:D8:82:29:9F
a=setup:actpass
a=mid:data
a=sctpmap:5000 webrtc-datachannel 1024</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1430050</commentid>
    <comment_count>1</comment_count>
    <who name="youenn fablet">youennf</who>
    <bug_when>2018-06-04 23:15:53 -0700</bug_when>
    <thetext>Can you provide a test case?
https://youennf.github.io/webrtc-tests/src/content/peerconnection/trickle-ice/ is doing just that and is supposed to be working on iOS.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1430196</commentid>
    <comment_count>2</comment_count>
    <who name="">philipp.kuederli</who>
    <bug_when>2018-06-05 13:21:34 -0700</bug_when>
    <thetext>Your link neither worked on iOS Safari. I reduced the whole example to the simple gathering. The project example file is here: 
https://github.com/kudi82/webrtc-ios/blob/master/static/webrtc.js

The code should actually be the same as in your link, but also does not work (no candidates):

##################################################################

var config = {
  &apos;iceServers&apos;: [
    {
      urls: [
        &apos;stun:stun.l.google.com:19302&apos;
      ]
    }
  ],
  &apos;iceTransportPolicy&apos;: &apos;all&apos;,
  &apos;rtcpMuxPolicy&apos;: &apos;negotiate&apos;
};

var constraints = {
  optional: [
    { &apos;RtpDataChannels&apos;: false }
  ]
}

var constraints = {
  optional: [
    { &apos;googIPv6&apos;: true }
  ]
}

var offerOptions = {
  offerToReceiveAudio: 1
}


var connection = new RTCPeerConnection(config, constraints);

connection.createDataChannel(&apos;channel&apos;);

connection.onicecandidate = function(event) {
  appendCandidate(event.candidate)
};

connection.createOffer(offerOptions)
.then(function(offer) {
  return connection.setLocalDescription(offer);
})
.then(function() {
  appendOffer(connection.localDescription)
  appendOfferDetail(connection.localDescription)
})
.catch(function(error) {
  appendError(error)
})

##################################################################</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1430214</commentid>
    <comment_count>3</comment_count>
    <who name="">philipp.kuederli</who>
    <bug_when>2018-06-05 13:58:09 -0700</bug_when>
    <thetext>In the meantime I tried to simplify more on master, so the code from above is here:

https://github.com/kudi82/webrtc-ios/blob/4ddaaae6fca17898efad4ecb02c4834a5f22c158/static/webrtc.js

Still not working. On Android I get a list of audio, video and data candidates. On iOS nothing but null after about a minute.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1430379</commentid>
    <comment_count>4</comment_count>
    <who name="">philipp.kuederli</who>
    <bug_when>2018-06-06 00:35:30 -0700</bug_when>
    <thetext>I have now read so many stuff about WebRtc on iOS that I have no idea anymore what should work and what not and in which version. So to clarify what I try to do: 

I have a car game running in the Mac OS Safari where you can steer the cars with your iPhone in the iOS Safari. I need just a data channel, no video no sound to send the commands directly to the game. The game sends also data to the phone (which however is a bit less important). Of course I dont want the user to accept the camera just for data.

So what I need is a direct connection between the phone and the browser on the Mac. I read that depending on the location (I am in Europe) the gathering of the candidates could fail. However I cannot imagine why this should be the case, so I guess rather not.

I found the workaround which Adapter uses (not yet tried out), however I dont know if this is needed for data channel, so I have not yet tried out:
https://github.com/webrtc/adapter/commit/ee197f1b07ae502f48026d832dd0cd952846a78b

I have read this, however this did not help so far:
https://webkit.org/blog/7763/a-closer-look-into-webrtc/

Some say the example you posted is already outdated:
https://youennf.github.io/webrtc-tests/src/content/peerconnection/trickle-ice/

I am quite lost so far, should it work at all to make a data channel on iOS? I spend so much time with testing and trying out.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1430461</commentid>
    <comment_count>5</comment_count>
    <who name="">philipp.kuederli</who>
    <bug_when>2018-06-06 09:18:16 -0700</bug_when>
    <thetext>It seems that without calling getUserMedia it is not possible to create a data channel because of security reasons, is this correct? I actually dont understand what the connection between video/audio and a data channel is about security reasons. If a data channel could be insecure, why should a user be aware of this just because of accepting a camera. The whole thing makes WebRtc useless as data channel, which would be a pity :-(

So the question is: Do I have to try at all to make it working, or is WebRTC on Safari useless for data channels and I can forget it?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1430484</commentid>
    <comment_count>6</comment_count>
    <who name="youenn fablet">youennf</who>
    <bug_when>2018-06-06 09:56:27 -0700</bug_when>
    <thetext>(In reply to philipp.kuederli from comment #5)
&gt; It seems that without calling getUserMedia it is not possible to create a
&gt; data channel because of security reasons, is this correct? I actually dont
&gt; understand what the connection between video/audio and a data channel is
&gt; about security reasons. If a data channel could be insecure, why should a
&gt; user be aware of this just because of accepting a camera. The whole thing
&gt; makes WebRtc useless as data channel, which would be a pity :-(
&gt; 
&gt; So the question is: Do I have to try at all to make it working, or is WebRTC
&gt; on Safari useless for data channels and I can forget it?

I understand your frustration here.
We are limiting private IP addresses for privacy reasons as this is used by many many web sites to track users.

https://youennf.github.io/webrtc-tests/src/content/peerconnection/trickle-ice/ should work and provide srflx candidates.
I do not know why Safari 11.1.1 is working for you but not iOS11.3.1 since they should have the same behavior.

We are working to enable this kind of data-channel-only scenarios, using MDNS ICE candidates.
This is covered in https://bugs.webkit.org/show_bug.cgi?id=174500 and is behind a runtime flag, off by default.

In Safari Tech Preview, go to &quot;Develop -&gt; Experimental Features -&gt; ...MDNS....&quot;
The latest iOS 12 seed might have this switch as well in &quot;Settings -&gt; Safari -&gt; Advanced -&gt; Experimental Features -&gt; ...MDNS...&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1430998</commentid>
    <comment_count>7</comment_count>
    <who name="">philipp.kuederli</who>
    <bug_when>2018-06-07 12:55:59 -0700</bug_when>
    <thetext>(In reply to youenn fablet from comment #6)

&gt; (In reply to philipp.kuederli from comment #5)
&gt; &gt; It seems that without calling getUserMedia it is not possible to create a
&gt; &gt; data channel because of security reasons, is this correct? I actually dont
&gt; &gt; understand what the connection between video/audio and a data channel is
&gt; &gt; about security reasons. If a data channel could be insecure, why should a
&gt; &gt; user be aware of this just because of accepting a camera. The whole thing
&gt; &gt; makes WebRtc useless as data channel, which would be a pity :-(
&gt; &gt; 
&gt; &gt; So the question is: Do I have to try at all to make it working, or is WebRTC
&gt; &gt; on Safari useless for data channels and I can forget it?
&gt; 
&gt; I understand your frustration here.
&gt; We are limiting private IP addresses for privacy reasons as this is used by
&gt; many many web sites to track users.


Hello Youenn, 

sorry for my frustration, somtimes this happens when things dont want to work. I am actually very happy that iOS supports WebRTC :-)


&gt; https://youennf.github.io/webrtc-tests/src/content/peerconnection/trickle-
&gt; ice/ should work and provide srflx candidates.
&gt; I do not know why Safari 11.1.1 is working for you but not iOS11.3.1 since
&gt; they should have the same behavior.


I think they behave the same. It was a confusion by me. In Safari Web Developer I chose &quot;Disable Local ICE Candidate Restrictions&quot;, but I did not realize that the change does only take effect when opening a new window (most likely I just refreshed). So when I deactivated it still worked and I did not realize that I am still running in this &quot;special&quot; mode.


&gt; We are working to enable this kind of data-channel-only scenarios, using
&gt; MDNS ICE candidates.
&gt; This is covered in https://bugs.webkit.org/show_bug.cgi?id=174500 and is
&gt; behind a runtime flag, off by default.
&gt; 
&gt; In Safari Tech Preview, go to &quot;Develop -&gt; Experimental Features -&gt;
&gt; ...MDNS....&quot;
&gt; The latest iOS 12 seed might have this switch as well in &quot;Settings -&gt; Safari
&gt; -&gt; Advanced -&gt; Experimental Features -&gt; ...MDNS...&quot;

Yes at least in my case a better data channel support woud be great, so it would be nice if this will come.

For the moment I installed &quot;coturn&quot; on my server as a TURN server and it works quite good. I can make a data channel over this and it seems to be more efficient than using WebSockets. So this was a really positive experience without having to implement something additional, just by installing a server.

For completeness, I use the following configuration:

- For connection (my IP and passwords hidden):

    new RTCPeerConnection{
      &quot;iceServers&quot;: [
        {
          urls: [
            &quot;turn:xxx.xxx.xxx.xxx:3478&quot;
          ],
          username: &quot;myuser&quot;,
          credential: &quot;mypassword&quot;
        }
      ],
      &quot;iceTransportPolicy&quot;: &quot;all&quot;,
      &quot;iceCandidatePoolSize&quot;: &quot;0&quot;
    };

- For Data Channel I did not configure something additional so far:

    connection.createDataChannel(&quot;sendDataChannel&quot;)

- For Offer i used the legacy option, just because of the examples (most likely it has no effect in my case):

    connection.createOffer({offerToReceiveAudio: 1}) 



With this configurationI get the following two candidates where I choose the &quot;relay&quot; candidate, for the srflx I did not get a data channel onopen event (my IP hidden again):

   candidate: &quot;candidate:842163049 1 udp 1677729535 188.62.109.27 63248 typ srflx raddr 0.0.0.0 rport 0 generation 0 ufrag 6K3E network-cost 50&quot;
   sdpMLineIndex: 0
   sdpMid: &quot;data&quot;

   candidate: &quot;candidate:2468224366 1 udp 33562367 xxx.xxx.xxx.xxx 52606 typ relay raddr 0.0.0.0 rport 0 generation 0 ufrag 6K3E network-cost 50&quot;
   sdpMLineIndex: 0
   sdpMid: &quot;data&quot;


So thank you so far for your great support, I think this ticket can be closed. The answer was most likely, that I had to call getUserMedia to get the candidates.

Philipp</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1431027</commentid>
    <comment_count>8</comment_count>
    <who name="youenn fablet">youennf</who>
    <bug_when>2018-06-07 14:47:42 -0700</bug_when>
    <thetext>Thanks for reporting back all this information, that might be useful to somebody else.

*** This bug has been marked as a duplicate of bug 174500 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>