feross/simple-peer

simple-peer won't connect when clients are not in the same network

omidshakeri opened this issue ยท 16 comments

simple-peer won't connect when clients are not in the same network

It works perfectly if both clients are in the same network (connected to the same modem/WiFi)
but even after setting iceServers, the connection is not working

one of many iceServers configs that I have tested:

config: { iceServers: [ { urls: 'stun:stun.l.google.com:19302' }, { urls: 'stun:stun1.l.google.com:19302' }, { urls: 'stun:stun2.l.google.com:19302' }, { urls: 'stun:stun3.l.google.com:19302' }, { urls: 'stun:stun4.l.google.com:19302' }, { url: 'turn:turn.bistri.com:80', credential: 'homeo', username: 'homeo', }, { url: 'turn:turn.anyfirewall.com:443?transport=tcp', credential: 'webrtc', username: 'webrtc', } ] },

am I doing anything wrong?
is there any other configurations that someone is using without problems, so can help me?

sample OFFER:
{"type":"offer","sdp":"v=0\r\no=- 1632205230773522520 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0 1\r\na=extmap-allow-mixed\r\na=msid-semantic: WMS a12bbe3d-0b80-484c-b475-10add8ae7d9e\r\nm=video 60132 UDP/TLS/RTP/SAVPF 96 97 102 103 104 105 106 107 108 109 127 125 39 40 45 46 98 99 100 101 112 113 116 117 118\r\nc=IN IP4 91.98.36.115\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=candidate:1374968337 1 udp 2113937151 855ce726-453d-493c-b485-c1b6362087a0.local 62119 typ host generation 0 network-cost 999\r\na=candidate:444479375 1 udp 1677729535 91.98.36.115 60132 typ srflx raddr 0.0.0.0 rport 0 generation 0 network-cost 999\r\na=ice-ufrag:SC4E\r\na=ice-pwd:9xuY1abEu4/rLr8oqgMMOFDE\r\na=fingerprint:sha-256 84:58:38:A3:AC:39:CC:82:E6:FC:FE:22:67:99:E9:75:79:D8:6E:C7:D2:C6:B9:27:31:70:41:E6:E8:0C:88:18\r\na=setup:actpass\r\na=mid:0\r\na=extmap:1 urn:ietf:params:rtp-hdrext:toffset\r\na=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:3 urn:3gpp:video-orientation\r\na=extmap:4 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\na=extmap:5 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay\r\na=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type\r\na=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-timing\r\na=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/color-space\r\na=extmap:9 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=extmap:10 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id\r\na=extmap:11 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id\r\na=sendrecv\r\na=msid:a12bbe3d-0b80-484c-b475-10add8ae7d9e 24a1b901-3bf7-43c1-9a9c-9bf0efcc1044\r\na=rtcp-mux\r\na=rtcp-rsize\r\na=rtpmap:96 VP8/90000\r\na=rtcp-fb:96 goog-remb\r\na=rtcp-fb:96 transport-cc\r\na=rtcp-fb:96 ccm fir\r\na=rtcp-fb:96 nack\r\na=rtcp-fb:96 nack pli\r\na=rtpmap:97 rtx/90000\r\na=fmtp:97 apt=96\r\na=rtpmap:102 H264/90000\r\na=rtcp-fb:102 goog-remb\r\na=rtcp-fb:102 transport-cc\r\na=rtcp-fb:102 ccm fir\r\na=rtcp-fb:102 nack\r\na=rtcp-fb:102 nack pli\r\na=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f\r\na=rtpmap:103 rtx/90000\r\na=fmtp:103 apt=102\r\na=rtpmap:104 H264/90000\r\na=rtcp-fb:104 goog-remb\r\na=rtcp-fb:104 transport-cc\r\na=rtcp-fb:104 ccm fir\r\na=rtcp-fb:104 nack\r\na=rtcp-fb:104 nack pli\r\na=fmtp:104 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42001f\r\na=rtpmap:105 rtx/90000\r\na=fmtp:105 apt=104\r\na=rtpmap:106 H264/90000\r\na=rtcp-fb:106 goog-remb\r\na=rtcp-fb:106 transport-cc\r\na=rtcp-fb:106 ccm fir\r\na=rtcp-fb:106 nack\r\na=rtcp-fb:106 nack pli\r\na=fmtp:106 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f\r\na=rtpmap:107 rtx/90000\r\na=fmtp:107 apt=106\r\na=rtpmap:108 H264/90000\r\na=rtcp-fb:108 goog-remb\r\na=rtcp-fb:108 transport-cc\r\na=rtcp-fb:108 ccm fir\r\na=rtcp-fb:108 nack\r\na=rtcp-fb:108 nack pli\r\na=fmtp:108 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f\r\na=rtpmap:109 rtx/90000\r\na=fmtp:109 apt=108\r\na=rtpmap:127 H264/90000\r\na=rtcp-fb:127 goog-remb\r\na=rtcp-fb:127 transport-cc\r\na=rtcp-fb:127 ccm fir\r\na=rtcp-fb:127 nack\r\na=rtcp-fb:127 nack pli\r\na=fmtp:127 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=4d001f\r\na=rtpmap:125 rtx/90000\r\na=fmtp:125 apt=127\r\na=rtpmap:39 H264/90000\r\na=rtcp-fb:39 goog-remb\r\na=rtcp-fb:39 transport-cc\r\na=rtcp-fb:39 ccm fir\r\na=rtcp-fb:39 nack\r\na=rtcp-fb:39 nack pli\r\na=fmtp:39 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=4d001f\r\na=rtpmap:40 rtx/90000\r\na=fmtp:40 apt=39\r\na=rtpmap:45 AV1/90000\r\na=rtcp-fb:45 goog-remb\r\na=rtcp-fb:45 transport-cc\r\na=rtcp-fb:45 ccm fir\r\na=rtcp-fb:45 nack\r\na=rtcp-fb:45 nack pli\r\na=rtpmap:46 rtx/90000\r\na=fmtp:46 apt=45\r\na=rtpmap:98 VP9/90000\r\na=rtcp-fb:98 goog-remb\r\na=rtcp-fb:98 transport-cc\r\na=rtcp-fb:98 ccm fir\r\na=rtcp-fb:98 nack\r\na=rtcp-fb:98 nack pli\r\na=fmtp:98 profile-id=0\r\na=rtpmap:99 rtx/90000\r\na=fmtp:99 apt=98\r\na=rtpmap:100 VP9/90000\r\na=rtcp-fb:100 goog-remb\r\na=rtcp-fb:100 transport-cc\r\na=rtcp-fb:100 ccm fir\r\na=rtcp-fb:100 nack\r\na=rtcp-fb:100 nack pli\r\na=fmtp:100 profile-id=2\r\na=rtpmap:101 rtx/90000\r\na=fmtp:101 apt=100\r\na=rtpmap:112 H264/90000\r\na=rtcp-fb:112 goog-remb\r\na=rtcp-fb:112 transport-cc\r\na=rtcp-fb:112 ccm fir\r\na=rtcp-fb:112 nack\r\na=rtcp-fb:112 nack pli\r\na=fmtp:112 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=64001f\r\na=rtpmap:113 rtx/90000\r\na=fmtp:113 apt=112\r\na=rtpmap:116 red/90000\r\na=rtpmap:117 rtx/90000\r\na=fmtp:117 apt=116\r\na=rtpmap:118 ulpfec/90000\r\na=ssrc-group:FID 722357843 1527080010\r\na=ssrc:722357843 cname:MYn6ZNV5Aywek9Bz\r\na=ssrc:722357843 msid:a12bbe3d-0b80-484c-b475-10add8ae7d9e 24a1b901-3bf7-43c1-9a9c-9bf0efcc1044\r\na=ssrc:1527080010 cname:MYn6ZNV5Aywek9Bz\r\na=ssrc:1527080010 msid:a12bbe3d-0b80-484c-b475-10add8ae7d9e 24a1b901-3bf7-43c1-9a9c-9bf0efcc1044\r\nm=application 28485 UDP/DTLS/SCTP webrtc-datachannel\r\nc=IN IP4 91.98.36.115\r\na=candidate:1374968337 1 udp 2113937151 855ce726-453d-493c-b485-c1b6362087a0.local 62121 typ host generation 0 network-cost 999\r\na=candidate:444479375 1 udp 1677729535 91.98.36.115 28485 typ srflx raddr 0.0.0.0 rport 0 generation 0 network-cost 999\r\na=ice-ufrag:SC4E\r\na=ice-pwd:9xuY1abEu4/rLr8oqgMMOFDE\r\na=fingerprint:sha-256 84:58:38:A3:AC:39:CC:82:E6:FC:FE:22:67:99:E9:75:79:D8:6E:C7:D2:C6:B9:27:31:70:41:E6:E8:0C:88:18\r\na=setup:actpass\r\na=mid:1\r\na=sctp-port:5000\r\na=max-message-size:262144\r\n"}

sample ANSWER:
{"type":"answer","sdp":"v=0\r\no=- 933737413889430186 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0 1\r\na=extmap-allow-mixed\r\na=msid-semantic: WMS d4475b51-48bc-4144-9907-c98463dae070\r\nm=video 36921 UDP/TLS/RTP/SAVPF 96 97 106 107 127 125 98 99 100 101 112 113 116 117 118\r\nc=IN IP4 5.215.179.17\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=candidate:4198611527 1 udp 2122260223 21.67.126.221 36921 typ host generation 0 network-id 1 network-cost 900\r\na=candidate:505637015 1 udp 2122194687 30.67.34.188 51838 typ host generation 0 network-id 2 network-cost 900\r\na=candidate:3774369014 1 udp 2122129151 26.26.26.1 54930 typ host generation 0 network-id 3 network-cost 50\r\na=candidate:82538195 1 tcp 1518280447 21.67.126.221 9 typ host tcptype active generation 0 network-id 1 network-cost 900\r\na=candidate:3767122947 1 tcp 1518214911 30.67.34.188 9 typ host tcptype active generation 0 network-id 2 network-cost 900\r\na=candidate:508729442 1 tcp 1518149375 26.26.26.1 9 typ host tcptype active generation 0 network-id 3 network-cost 50\r\na=candidate:676151240 1 udp 1686052607 5.215.179.17 36921 typ srflx raddr 21.67.126.221 rport 36921 generation 0 network-id 1 network-cost 900\r\na=ice-ufrag:7wrY\r\na=ice-pwd:FIUpUUhvIgNQ8iW7lbPmvxrP\r\na=fingerprint:sha-256 B6:FA:AD:CC:79:4C:FF:6A:3B:02:D0:EA:AD:E4:92:FB:FB:10:A9:EF:8C:9E:F0:CB:E5:B9:69:AB:B6:D6:55:01\r\na=setup:active\r\na=mid:0\r\na=extmap:1 urn:ietf:params:rtp-hdrext:toffset\r\na=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:3 urn:3gpp:video-orientation\r\na=extmap:4 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\na=extmap:5 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay\r\na=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type\r\na=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-timing\r\na=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/color-space\r\na=extmap:9 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=extmap:10 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id\r\na=extmap:11 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id\r\na=sendrecv\r\na=msid:d4475b51-48bc-4144-9907-c98463dae070 d85f2abf-4e4c-4cf3-9094-10959b8610f0\r\na=rtcp-mux\r\na=rtcp-rsize\r\na=rtpmap:96 VP8/90000\r\na=rtcp-fb:96 goog-remb\r\na=rtcp-fb:96 transport-cc\r\na=rtcp-fb:96 ccm fir\r\na=rtcp-fb:96 nack\r\na=rtcp-fb:96 nack pli\r\na=rtpmap:97 rtx/90000\r\na=fmtp:97 apt=96\r\na=rtpmap:106 H264/90000\r\na=rtcp-fb:106 goog-remb\r\na=rtcp-fb:106 transport-cc\r\na=rtcp-fb:106 ccm fir\r\na=rtcp-fb:106 nack\r\na=rtcp-fb:106 nack pli\r\na=fmtp:106 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f\r\na=rtpmap:107 rtx/90000\r\na=fmtp:107 apt=106\r\na=rtpmap:127 H264/90000\r\na=rtcp-fb:127 goog-remb\r\na=rtcp-fb:127 transport-cc\r\na=rtcp-fb:127 ccm fir\r\na=rtcp-fb:127 nack\r\na=rtcp-fb:127 nack pli\r\na=fmtp:127 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=4d001f\r\na=rtpmap:125 rtx/90000\r\na=fmtp:125 apt=127\r\na=rtpmap:98 VP9/90000\r\na=rtcp-fb:98 goog-remb\r\na=rtcp-fb:98 transport-cc\r\na=rtcp-fb:98 ccm fir\r\na=rtcp-fb:98 nack\r\na=rtcp-fb:98 nack pli\r\na=fmtp:98 profile-id=0\r\na=rtpmap:99 rtx/90000\r\na=fmtp:99 apt=98\r\na=rtpmap:100 VP9/90000\r\na=rtcp-fb:100 goog-remb\r\na=rtcp-fb:100 transport-cc\r\na=rtcp-fb:100 ccm fir\r\na=rtcp-fb:100 nack\r\na=rtcp-fb:100 nack pli\r\na=fmtp:100 profile-id=2\r\na=rtpmap:101 rtx/90000\r\na=fmtp:101 apt=100\r\na=rtpmap:112 H264/90000\r\na=rtcp-fb:112 goog-remb\r\na=rtcp-fb:112 transport-cc\r\na=rtcp-fb:112 ccm fir\r\na=rtcp-fb:112 nack\r\na=rtcp-fb:112 nack pli\r\na=fmtp:112 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=64001f\r\na=rtpmap:113 rtx/90000\r\na=fmtp:113 apt=112\r\na=rtpmap:116 red/90000\r\na=rtpmap:117 rtx/90000\r\na=fmtp:117 apt=116\r\na=rtpmap:118 ulpfec/90000\r\na=ssrc-group:FID 1653626987 3612846935\r\na=ssrc:1653626987 cname:8UHT9IbIUvzznB0T\r\na=ssrc:3612846935 cname:8UHT9IbIUvzznB0T\r\nm=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\nc=IN IP4 0.0.0.0\r\na=ice-ufrag:7wrY\r\na=ice-pwd:FIUpUUhvIgNQ8iW7lbPmvxrP\r\na=fingerprint:sha-256 B6:FA:AD:CC:79:4C:FF:6A:3B:02:D0:EA:AD:E4:92:FB:FB:10:A9:EF:8C:9E:F0:CB:E5:B9:69:AB:B6:D6:55:01\r\na=setup:active\r\na=mid:1\r\na=sctp-port:5000\r\na=max-message-size:262144\r\n"}

Your ice-server credentials seem to be the issue. I am using the turn server from open-relay. It works on different networks as well. This is not the issue with the simple-peer library.

Your ice-server credentials seem to be the issue. I am using the turn server from open-relay. It works on different networks as well. This is not the issue with the simple-peer library.

thanks
but even with TURN Servers from (metered.ca) and (freeturn.net)
this method is not being fired when clients are in different networks
_Peer.on('connect', () => {
but it works if they are in the same network
I know the problem is NAT / TURN ...
but I can not find any solutions

This error occurs when clients are in different networks:
Uncaught (in promise) DOMException: The play() request was interrupted by a new load request

in this method:
_Peer.on('stream', stream => { _OtherStream = stream; var PartnerVideo = document.querySelector('#PartnerVideo'); try { if ('srcObject' in PartnerVideo) { PartnerVideo.srcObject = stream } else { PartnerVideo.src = window.URL.createObjectURL(stream) // for older browsers } PartnerVideo.play(); } catch (e) { console.log('ERROR', e); } })

Can you share the code with me? I can check with my credentials and test the issue?

Can you share the code with me? I can check with my credentials and test the issue?

Sure

this a simplified version, without any Server
so you should copy textbox values to other device

URL for initaiator:
https://omidtest.ir/VC/VideoCall.html#init

URL for other peer:
https://omidtest.ir/VC/VideoCall.html

Steps:

  1. after a few seconds, "MyID" in initaiator peer page will be filled
  2. copy that to "ClinetID" textbox in other peer device and press "Connect"
  3. after a few seconds, "MyID" in other peer page will be filled
  4. copy that to "ClinetID" textbox in initaiator peer device and press "Connect"

TURN Server urls are from free plan of "metered.ca"

Thanks a lot

Can you share the code with me? I can check with my credentials and test the issue?

link to the sample html file:

https://github.com/omidshakeri/simple-peer-videocall

You can give https://github.com/matallui/artico a try! The @rtco/peer package is pretty similar to simple-peer

You can give https://github.com/matallui/artico a try! The @rtco/peer package is pretty similar to simple-peer

Thanks
I switched to PeerJS and it works perfectly with the same configurations
the problem with simple-peer is not solved yet

@omidshakeri gotcha! I believe neither this nor peerJS are actively maintained anymore. Hence why I started Artico in the first place, to try to expand on these projects. If you give Artico a try let me know. Iโ€™d love to get some feedback on how to improve.

It will be OK if you add a available STUN server address in iceServers.

It will be OK if you add a available STUN server address in iceServers.

Thanks
I switched to PeerJS and it works perfectly with the same configurations and iceServers
the problem with simple-peer is not solved yet

Hi @omidshakeri, I'm getting into your trouble! Can you give me your solution?
When user B receive a video call, I can see the camera of user B. But I still get the streaming data, and I don't know how...

Thanks for replay !

image
image

I switched to PeerJS and it works perfectly with the same configurations and iceServers
the problem with simple-peer is not solved yet

I switched to PeerJS and it works perfectly with the same configurations and iceServers
My problem with simple-peer is not solved yet

I switched to PeerJS and it works perfectly with the same configurations and iceServers
the problem with simple-peer is not solved yet

I switched to PeerJS and it works perfectly with the same configurations and iceServers My problem with simple-peer is not solved yet

Oh, can you share me your repo ?