JSFiddle - React, Tailwind, and code Playground
by xdumaine
JavaScript
pc = new window.RTCPeerConnection();
pc2 = new window.RTCPeerConnection();
config = {
iceServers: [{
urls: 'stun:stun1.l.google.com:19302?transport=udp'
},
{
urls: 'stun:stun2.l.google.com:19302?transport=udp'
}
]
};
pc.setConfiguration(config);
pc2.setConfiguration(config);
pc.createDataChannel('test');
pc.onicecandidate = e => {
console.log('candidate pc1', e.candidate)
setTimeout(function() {
if (e.candidate)
pc2.addIceCandidate(e.candidate);
}, 4000);
};
pc2.onicecandidate = e => {
console.log('candidate pc2', e.candidate);
setTimeout(function() {
if (e.candidate)
pc.addIceCandidate(e.candidate);
}, 4000);
}
pc.createOffer().then(o => {
pc.setLocalDescription(o);
return new Promise(resolve => {
pc2.setRemoteDescription(o);
setTimeout(() => pc2.createAnswer().then(a => resolve(a)), 4000)
})
return pc2.createAnswer();
}).then(a => {
pc2.setLocalDescription(a);
pc.setRemoteDescription(a);
});