Simple-peer: Explanation of this proposed fix to ICE failures?

Created on 19 Jan 2019  路  16Comments  路  Source: feross/simple-peer

I have the same problem, to solve this I've change locally simple-peer.js
change this
self._pc = new (self._wrtc.RTCPeerConnection)(self.config, self.constraints)
to this

let my_config = {
    iceTransportPolicy: 'relay',
    ...self.config,
}
self._pc = new (self._wrtc.RTCPeerConnection)(self.config, self.constraints)

problem is in pass only config of servers to RTCPeerConnection


const peer = new SimplePeer({
      iceTransportPolicy: 'relay', // this property will ignore 
      config: {
        iceServers: [...  ]
      }
    });

_Originally posted by @rubender in https://github.com/feross/simple-peer/issues/202#issuecomment-425838919_

question

Most helpful comment

Hi,
I opened a project in GitHub which include the basic example for simple peer
Plus IceServer, you can see it here:
https://github.com/yaniv-fink/WebRTC-All-Examples/

Also, I added a link to live example here.
https://www.videospeeddate.com/chat-simple-peer
(If you check the live example you might see the problem when connecting using firefox to chrome)

I created a video on youtube which demonstrates the use of simple-peer.
https://www.youtube.com/watch?v=JOQlo-D4ElU&feature=youtu.be

I hope you will find the time to see this material I uploaded and give your opinion about the code.

Thank you

All 16 comments

some guy (@rubender) wrote this in a closed post,
this post: https://github.com/feross/simple-peer/issues/202
I can't respond to the closed post, so I open a new one.
the reference is that the IceServers object is not working well, and he said he found a way to change the simplePeer.js file to fix the bug.

There are a few questions.

  1. I didn't understand the fix, because it is not clear at all the way he wrote it, if you can see that please add the full code.
  2. If there is a problem why does this fix is not embedded in the repository.
  3. why in 2019 you can't contact Github's users.. :)

It's not a fix. He just added iceTransportPolicy: 'relay', to his config object. This forces TURN relays instead of any kind of peer-to-peer connection. It's easy to avoid ICE failures when you just always use TURN.

If you want to only use TURN, add iceTransportPolicy: 'relay' to your config object, but know all data will be forwarded over your TURN server (that you must setup and add to iceServers). No changes need to be made in the code as that ice transport policy definitely shouldn't be hardcoded.

https://developer.mozilla.org/en-US/docs/Web/API/RTCConfiguration#RTCIceTransportPolicy_enum

Due to networks and the limitations of webrtc, you will ALWAYS have at least a few situations that result in an ICE failure if you don't use TURN. Doesn't mean you have to force TURN to be always used.

The reason the other issue is locked is because ICE failures aren't one issue: it's a catch-all for a multitude of network and application issues. Carefully go through the troubleshooting steps I've pinned on that issue - they work 90% of the time.

He could have also meant that when you use a custom config object, the default iceServers aren't used. I suppose we could carry them over?

Thank you for answering so quickly I really appreciate that!
before I will try the relay as you suggest
I am a bit confused about what is the best way to configure the Ice servers, here are some examples, from around the internet, I want to know what is the best practice, for simplepeer.
code example in the internent for IceServer: https://developer.mozilla.org/en-US/docs/Web/API/RTCIceServer/urls
iceServers: [ { urls: 'stun:global.stun.twilio.com:3478?transport=udp' }, { urls: 'turn:global.turn.twilio.com:3478?transport=udp', username: 'myUsername, credential: 'myPassword' }, { urls: 'turn:global.turn.twilio.com:3478?transport=tcp', username: 'myUsername, credential: 'myPassword' }, { urls: 'turn:global.turn.twilio.com:443?transport=tcp', username: 'myUsername, credential: 'myPassword' }]

or this one:

iceServers: [ { urls: 'stun:global.stun.twilio.com:3478?transport=udp' }, { urls: ['turn:global.turn.twilio.com:3478?transport=udp','turn:global.turn.twilio.com:3478?transport=tcp', 'turn:global.turn.twilio.com:443?transport=tcp'], username: 'myUsername, credential: 'myPassword' }]

or this one:

iceServers: [ { urls: ['stun:global.stun.twilio.com:3478?transport=udp','turn:global.turn.twilio.com:3478?transport=udp','turn:global.turn.twilio.com:3478?transport=tcp', 'turn:global.turn.twilio.com:443?transport=tcp'], username: 'myUsername, credential: 'myPassword' }]

or maybe with url, instead of urls:

iceServers: [ { url: 'stun:global.stun.twilio.com:3478?transport=udp' }, { url: 'turn:global.turn.twilio.com:3478?transport=udp', username: 'myUsername, credential: 'myPassword' }, { url: 'turn:global.turn.twilio.com:3478?transport=tcp', username: 'myUsername, credential: 'myPassword' }, { url: 'turn:global.turn.twilio.com:443?transport=tcp', username: 'myUsername, credential: 'myPassword' }]

Thank you

3rd one is correct.

Your fast, thanks!
Chekcing it now.
I will update soon.
Thank you.

By the way,
here: https://developer.mozilla.org/en-US/docs/Web/API/RTCIceServer/urls
In the last example of Multiple ICE servers
they seperate the IceServers to 2 items.
stun, and turn
Here is there code
iceServers: [ { urls: ["turns:turnserver.example.org", "turn:turnserver.example.org"], username: "webrtc", credential: "turnpassword" }, { urls: "stun: stunserver.example.org" } ]

Why didn't they combine it to one big urls array? like example 3, which you said was the correct one.?

@yaniv-fink because one is STUN without any credentials and another is TURN and requires authentication

You can have multiple servers, each server can have multiple urls.

Also, my bad: your config should actually look like this (need to split up the stun and turn urls since they are different servers):
````
iceServers: [
{
urls: ['stun:global.stun.twilio.com:3478?transport=udp']
},
{ urls: ['turn:global.turn.twilio.com:3478?transport=udp','turn:global.turn.twilio.com:3478?transport=tcp', 'turn:global.turn.twilio.com:443?transport=tcp'],
username: 'myUsername,
credential: 'myPassword'
}]

Great,
but I think you have open bracket [ in the first stun server, maybe you need to remove it?.

Hi,
I opened a project in GitHub which include the basic example for simple peer
Plus IceServer, you can see it here:
https://github.com/yaniv-fink/WebRTC-All-Examples/

Also, I added a link to live example here.
https://www.videospeeddate.com/chat-simple-peer
(If you check the live example you might see the problem when connecting using firefox to chrome)

I created a video on youtube which demonstrates the use of simple-peer.
https://www.youtube.com/watch?v=JOQlo-D4ElU&feature=youtu.be

I hope you will find the time to see this material I uploaded and give your opinion about the code.

Thank you

Looks great! We should probably include more examples like this.

Thank you.
@t-mullen , can you look at this?

https://stackoverflow.com/questions/54437895/invalidaccesserror-failed-to-set-remote-offer-sdp-failed-to-set-remote-video-d

might be another codec issue that prevents from people to use simple-peer and need to be addressed.
thank you.

3rd one is correct.

@t-mullen how can I keep my iceservers credentials secret? I'm using Xirsys.

@changeweb https://docs.xirsys.com/?pg=api-turn#managing-expiring-credentials

@t-mullen Thank you for your time and quick response. Actually I didn't have any idea about the concept of _turn endpoints. I've found this article How to Build Video Chat with Xirsys, WebRTC, and PubNub which works with this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jimmywarting picture jimmywarting  路  3Comments

sahil-devzila picture sahil-devzila  路  3Comments

lroellin picture lroellin  路  3Comments

measwel picture measwel  路  4Comments

alexmarion picture alexmarion  路  4Comments