I am trying to get a hello worlds WebRTC sample working over internet connection not same local machine I am using this code
<html>
<head>
<title>WebRTC Tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="./simplepeer.min.js"></script>
</head>
<body>
<style>
#outgoing {
width: 600px;
word-wrap: break-word;
white-space: normal;
}
</style>
<form>
<textarea id="incoming"></textarea>
<button type="submit">submit</button>
</form>
<pre id="outgoing"></pre>
<script src="simplepeer.min.js"></script>
<script>
const p = new SimplePeer({
initiator: location.hash === "#1",
config: {
sdpSemantics: "unified-plan",
iceTransportPolicy: "relay",
reconnectTimer: 100,
iceServers: [
{ urls: ["stun:eu-turn8.xirsys.com"] },
{
username:"my_username",
credential: "my_password",
urls: [
"turn:eu-turn8.xirsys.com:80?transport=udp",
"turn:eu-turn8.xirsys.com:3478?transport=udp",
"turn:eu-turn8.xirsys.com:80?transport=tcp",
"turn:eu-turn8.xirsys.com:3478?transport=tcp",
"turns:eu-turn8.xirsys.com:443?transport=tcp",
"turns:eu-turn8.xirsys.com:5349?transport=tcp",
],
},
],
},
trickle: false,
});
p.on("error", (err) => console.log("error", err));
p.on("signal", (data) => {
console.log("SIGNAL", JSON.stringify(data));
document.querySelector("#outgoing").textContent = JSON.stringify(data);
});
document.querySelector("form").addEventListener("submit", (ev) => {
ev.preventDefault();
p.signal(JSON.parse(document.querySelector("#incoming").value));
});
p.on("connect", () => {
console.log("CONNECT");
p.send("whatever" + Math.random());
});
p.on("data", (data) => {
console.log("data: " + data);
});
</script>
</body>
</html>
I think peers connects successfully to the ice server
I get something like this
{"type":"offer","sdp":"v=0\r\no=- 2164965454299906991 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0\r\na=msid-semantic: WMS\r\nm=application 58912 UDP/DTLS/SCTP webrtc-datachannel\r\nc=IN IP4 178.128.172.237\r\na=candidate:4213592065 1 udp 33563647 178.128.172.237 58912 typ relay raddr 0.0.0.0 rport 0 generation 0 network-cost 999\r\na=candidate:4213592065 1 udp 33563391 178.128.172.237 65469 typ relay raddr 0.0.0.0 rport 0 generation 0 network-cost 999\r\na=candidate:3716587576 1 udp 16785919 159.89.29.206 61355 typ relay raddr 0.0.0.0 rport 0 generation 0 network-cost 999\r\na=candidate:3716587576 1 udp 16785663 159.89.29.206 64585 typ relay raddr 0.0.0.0 rport 0 generation 0 network-cost 999\r\na=candidate:3273125197 1 udp 7935 159.89.29.206 61649 typ relay raddr 0.0.0.0 rport 0 generation 0 network-cost 999\r\na=ice-ufrag:l/P6\r\na=ice-pwd:o44fq+dTPwzTMqdJyepGYS9C\r\na=fingerprint:sha-256 98:DA:31:33:23:0D:D3:BD:9B:4A:C5:89:79:0D:99:E4:38:45:45:84:67:CB:FC:31:31:7C:6B:C2:D8:C2:72:D8\r\na=setup:actpass\r\na=mid:0\r\na=sctp-port:5000\r\na=max-message-size:262144\r\n"}
but peers fail to connect to each others
error Error: Connection failed.
at a (VM70468 simplepeer.min.js:6)
at p._onConnectionStateChange (VM70468 simplepeer.min.js:6)
at RTCPeerConnection._pc.onconnectionstatechange (VM70468 simplepeer.min.js:6)
my chrome://webrtc-internals/ log looks like this
https://www.riseofbots.com/webrtc/index.html#1, { iceServers: [stun:eu-turn8.xirsys.com, turn:eu-turn8.xirsys.com:80?transport=udp, turn:eu-turn8.xirsys.com:3478?transport=udp, turn:eu-turn8.xirsys.com:80?transport=tcp, turn:eu-turn8.xirsys.com:3478?transport=tcp, turns:eu-turn8.xirsys.com:443?transport=tcp, turns:eu-turn8.xirsys.com:5349?transport=tcp], iceTransportPolicy: relay, bundlePolicy: balanced, rtcpMuxPolicy: require, iceCandidatePoolSize: 0, sdpSemantics: "unified-plan" },
Time Event
8/29/2020, 7:41:24 PM
createLocalDataChannel
8/29/2020, 7:41:24 PM negotiationneeded
8/29/2020, 7:41:24 PM
createOffer
8/29/2020, 7:41:24 PM
createOfferOnSuccess
8/29/2020, 7:41:24 PM
setLocalDescription (munged)
8/29/2020, 7:41:24 PM
signalingstatechange
8/29/2020, 7:41:24 PM setLocalDescriptionOnSuccess
8/29/2020, 7:41:24 PM
icegatheringstatechange
8/29/2020, 7:41:24 PM
icecandidateerror
8/29/2020, 7:41:24 PM
icecandidateerror
8/29/2020, 7:41:24 PM
icecandidateerror
8/29/2020, 7:41:24 PM
icecandidateerror
8/29/2020, 7:41:24 PM
icecandidateerror
8/29/2020, 7:41:24 PM
icecandidateerror
8/29/2020, 7:41:24 PM
icecandidateerror
8/29/2020, 7:41:24 PM
icecandidateerror
8/29/2020, 7:41:25 PM
icecandidate (relay)
8/29/2020, 7:41:25 PM
icecandidate (relay)
8/29/2020, 7:41:25 PM
icecandidate (relay)
8/29/2020, 7:41:25 PM
icecandidate (relay)
8/29/2020, 7:41:25 PM
icecandidate (relay)
8/29/2020, 7:41:25 PM
icecandidate (relay)
8/29/2020, 7:41:25 PM
icegatheringstatechange
8/29/2020, 7:42:50 PM
setRemoteDescription
8/29/2020, 7:42:50 PM
signalingstatechange
8/29/2020, 7:42:50 PM
signalingstatechange
8/29/2020, 7:42:50 PM setRemoteDescriptionOnSuccess
8/29/2020, 7:42:50 PM
createAnswer
8/29/2020, 7:42:50 PM
createAnswerOnSuccess
8/29/2020, 7:42:50 PM
setLocalDescription (munged)
8/29/2020, 7:42:50 PM
signalingstatechange
8/29/2020, 7:42:50 PM setLocalDescriptionOnSuccess
8/29/2020, 7:42:50 PM
icegatheringstatechange
8/29/2020, 7:42:50 PM
icecandidateerror
8/29/2020, 7:42:50 PM
icecandidateerror
8/29/2020, 7:42:50 PM
icecandidateerror
8/29/2020, 7:42:50 PM
icecandidateerror
8/29/2020, 7:42:50 PM
icecandidateerror
8/29/2020, 7:42:50 PM
icecandidateerror
8/29/2020, 7:42:50 PM
icecandidateerror
8/29/2020, 7:42:50 PM
icecandidateerror
8/29/2020, 7:42:50 PM
iceconnectionstatechange
8/29/2020, 7:42:50 PM
iceconnectionstatechange (legacy)
8/29/2020, 7:42:50 PM
connectionstatechange
8/29/2020, 7:42:50 PM
icecandidate (relay)
8/29/2020, 7:42:50 PM
icecandidate (relay)
8/29/2020, 7:42:51 PM
icecandidate (relay)
8/29/2020, 7:42:51 PM
icecandidate (relay)
8/29/2020, 7:42:51 PM
icecandidate (relay)
8/29/2020, 7:42:51 PM
icecandidate (relay)
8/29/2020, 7:42:51 PM
icegatheringstatechange
8/29/2020, 7:43:07 PM
iceconnectionstatechange
8/29/2020, 7:43:07 PM
iceconnectionstatechange (legacy)
8/29/2020, 7:43:07 PM
connectionstatechange
8/29/2020, 7:43:07 PM close
8/29/2020, 7:43:07 PM
connectionstatechange
Stats Tables
RTCCertificate_90:CC:82:30:06:17:A9:46:56:60:C1:B9:3D:AE:F9:AD:20:5F:1B:7B:49:12:8B:5C:B0:82:9E:CA:5A:30:04:70 (certificate)
RTCDataChannel_6 (data-channel)
RTCPeerConnection (peer-connection)
RTCTransport_0_1 (transport)
RTCIceCandidatePair_A3CDTSBV_H+8IMlJN (candidate-pair)
RTCIceCandidatePair_A3CDTSBV_OeCFMKnA (candidate-pair)
RTCIceCandidatePair_A3CDTSBV_UybVjbsA (candidate-pair)
RTCIceCandidatePair_A3CDTSBV_aCTtFtgZ (candidate-pair)
RTCIceCandidatePair_A3CDTSBV_jNRqBEDa (candidate-pair)
RTCIceCandidatePair_A3CDTSBV_pPd2PFqR (candidate-pair)
RTCIceCandidatePair_UB759FSC_H+8IMlJN (candidate-pair)
RTCIceCandidatePair_UB759FSC_OeCFMKnA (candidate-pair)
RTCIceCandidatePair_UB759FSC_UybVjbsA (candidate-pair)
RTCIceCandidatePair_UB759FSC_aCTtFtgZ (candidate-pair)
RTCIceCandidatePair_UB759FSC_jNRqBEDa (candidate-pair)
RTCIceCandidatePair_UB759FSC_pPd2PFqR (candidate-pair)
RTCIceCandidate_A3CDTSBV (local-candidate)
RTCIceCandidate_H+8IMlJN (remote-candidate)
RTCIceCandidate_OeCFMKnA (remote-candidate)
RTCIceCandidate_UB759FSC (local-candidate)
RTCIceCandidate_UybVjbsA (remote-candidate)
RTCIceCandidate_aCTtFtgZ (remote-candidate)
RTCIceCandidate_jNRqBEDa (remote-candidate)
RTCIceCandidate_pPd2PFqR (remote-candidate)
RTCIceCandidatePair_+D71hhQo_H+8IMlJN (candidate-pair)
RTCIceCandidatePair_+D71hhQo_OeCFMKnA (candidate-pair)
RTCIceCandidatePair_+D71hhQo_UybVjbsA (candidate-pair)
RTCIceCandidatePair_+D71hhQo_aCTtFtgZ (candidate-pair)
RTCIceCandidatePair_+D71hhQo_jNRqBEDa (candidate-pair)
RTCIceCandidatePair_+D71hhQo_pPd2PFqR (candidate-pair)
RTCIceCandidatePair_FtqjTR78_H+8IMlJN (candidate-pair)
RTCIceCandidatePair_FtqjTR78_OeCFMKnA (candidate-pair)
RTCIceCandidatePair_FtqjTR78_UybVjbsA (candidate-pair)
RTCIceCandidatePair_FtqjTR78_aCTtFtgZ (candidate-pair)
RTCIceCandidatePair_FtqjTR78_jNRqBEDa (candidate-pair)
RTCIceCandidatePair_FtqjTR78_pPd2PFqR (candidate-pair)
RTCIceCandidatePair_TyMs9u0h_H+8IMlJN (candidate-pair)
RTCIceCandidatePair_TyMs9u0h_OeCFMKnA (candidate-pair)
RTCIceCandidatePair_TyMs9u0h_UybVjbsA (candidate-pair)
RTCIceCandidatePair_TyMs9u0h_aCTtFtgZ (candidate-pair)
RTCIceCandidatePair_TyMs9u0h_jNRqBEDa (candidate-pair)
RTCIceCandidatePair_TyMs9u0h_pPd2PFqR (candidate-pair)
RTCIceCandidatePair_thN/4O23_H+8IMlJN (candidate-pair)
RTCIceCandidatePair_thN/4O23_OeCFMKnA (candidate-pair)
RTCIceCandidatePair_thN/4O23_UybVjbsA (candidate-pair)
RTCIceCandidatePair_thN/4O23_aCTtFtgZ (candidate-pair)
RTCIceCandidatePair_thN/4O23_jNRqBEDa (candidate-pair)
RTCIceCandidatePair_thN/4O23_pPd2PFqR (candidate-pair)
RTCIceCandidate_+D71hhQo (local-candidate)
RTCIceCandidate_FtqjTR78 (local-candidate)
RTCIceCandidate_TyMs9u0h (local-candidate)
RTCIceCandidate_thN/4O23 (local-candidate)
Stats graphs for RTCPeerConnection (peer-connection)
Stats graphs for RTCIceCandidatePair_A3CDTSBV_H+8IMlJN (candidate-pair)
Stats graphs for RTCIceCandidatePair_A3CDTSBV_OeCFMKnA (candidate-pair)
Stats graphs for RTCIceCandidatePair_A3CDTSBV_UybVjbsA (candidate-pair)
Stats graphs for RTCIceCandidatePair_A3CDTSBV_aCTtFtgZ (candidate-pair)
Stats graphs for RTCIceCandidatePair_A3CDTSBV_jNRqBEDa (candidate-pair)
Stats graphs for RTCIceCandidatePair_A3CDTSBV_pPd2PFqR (candidate-pair)
Stats graphs for RTCIceCandidatePair_UB759FSC_H+8IMlJN (candidate-pair)
Stats graphs for RTCIceCandidatePair_UB759FSC_OeCFMKnA (candidate-pair)
Stats graphs for RTCIceCandidatePair_UB759FSC_UybVjbsA (candidate-pair)
Stats graphs for RTCIceCandidatePair_UB759FSC_aCTtFtgZ (candidate-pair)
Stats graphs for RTCIceCandidatePair_UB759FSC_jNRqBEDa (candidate-pair)
Stats graphs for RTCIceCandidatePair_UB759FSC_pPd2PFqR (candidate-pair)
Stats graphs for RTCIceCandidatePair_+D71hhQo_H+8IMlJN (candidate-pair)
Stats graphs for RTCIceCandidatePair_+D71hhQo_OeCFMKnA (candidate-pair)
Stats graphs for RTCIceCandidatePair_+D71hhQo_UybVjbsA (candidate-pair)
Stats graphs for RTCIceCandidatePair_+D71hhQo_aCTtFtgZ (candidate-pair)
Stats graphs for RTCIceCandidatePair_+D71hhQo_jNRqBEDa (candidate-pair)
Stats graphs for RTCIceCandidatePair_+D71hhQo_pPd2PFqR (candidate-pair)
Stats graphs for RTCIceCandidatePair_FtqjTR78_H+8IMlJN (candidate-pair)
Stats graphs for RTCIceCandidatePair_FtqjTR78_OeCFMKnA (candidate-pair)
Stats graphs for RTCIceCandidatePair_FtqjTR78_UybVjbsA (candidate-pair)
Stats graphs for RTCIceCandidatePair_FtqjTR78_aCTtFtgZ (candidate-pair)
Stats graphs for RTCIceCandidatePair_FtqjTR78_jNRqBEDa (candidate-pair)
Stats graphs for RTCIceCandidatePair_FtqjTR78_pPd2PFqR (candidate-pair)
Stats graphs for RTCIceCandidatePair_TyMs9u0h_H+8IMlJN (candidate-pair)
Stats graphs for RTCIceCandidatePair_TyMs9u0h_OeCFMKnA (candidate-pair)
Stats graphs for RTCIceCandidatePair_TyMs9u0h_UybVjbsA (candidate-pair)
Stats graphs for RTCIceCandidatePair_TyMs9u0h_aCTtFtgZ (candidate-pair)
Stats graphs for RTCIceCandidatePair_TyMs9u0h_jNRqBEDa (candidate-pair)
Stats graphs for RTCIceCandidatePair_TyMs9u0h_pPd2PFqR (candidate-pair)
Stats graphs for RTCIceCandidatePair_thN/4O23_H+8IMlJN (candidate-pair)
Stats graphs for RTCIceCandidatePair_thN/4O23_OeCFMKnA (candidate-pair)
Stats graphs for RTCIceCandidatePair_thN/4O23_UybVjbsA (candidate-pair)
Stats graphs for RTCIceCandidatePair_thN/4O23_aCTtFtgZ (candidate-pair)
Stats graphs for RTCIceCandidatePair_thN/4O23_jNRqBEDa (candidate-pair)
Stats graphs for RTCIceCandidatePair_thN/4O23_pPd2PFqR (candidate-pair)
I really have no idea what I am doing wrong?
For me the following parameters for initialization worked:
You can also add your turn servers as, though stun and turn aren't necessary if it's in the same network. Also here is an example project you can use as reference. With DEMO