WebRTC, ice candidates connection

2019-01-26 23:13发布

问题:

I'm trying to learn how to use webRTC in applications so I wrote a code sample available in the following link: http://wklej.org/hash/fd599a32e8e/

At the beginning I need to say that I don't care about browsers compatibility, All I need is to support Chromium web engine without any external adapters/other libraries.

The web application should allow me to establish a connection between two browser tabs running on the same host — by manually exchange of appropriate data (SDP and ICE candidates).

Steps to follow:

  1. Click on "create offer button", copy local SDP;
  2. Go to other tab and insert previously copied SDP into "remote SDP" area, then press "create answer";
  3. Copy generated local SDP, go to first tab, insert into "remote SDP" area and click on "set remote sdp" button (not create answer button);
  4. Exchange ice candidates — copy them from one tab, insert to the second one and press "addCandidates" button. Do the same in the other way.

The main problem is that this function:

peer.iceconnectionstatechange = function(event) {
    console.log("ice connection state: " + peer.iceConnectionState)
}

won't be triggered. I tried to play with STUN/TURN servers without success. The remote video won't run. If somebody could point out where I made mistake?

回答1:

Try mine (cut'n'paste): https://jsfiddle.net/7vv2vxtt/

Or automatic (localStorage): https://jsfiddle.net/2v1Lnpmx/

This code intentionally left blank.

ICE candidates get added to the local offer/answer over time, so it simply waits for end-of-candidates before producing SDP with all candidates embedded.

Should work in all browsers.



标签: webrtc