jeudi 5 février 2015

WebRTC: Unable to successfully complete signalling process using DataChannel


I've been having trouble establishing a WebRTC session and am trying to simplify the issue as much as possible. So I've written up a simple copy & paste example, where you just paste the offer/answer into webforms and click submit.


The HTML+JS, all in one file, can be found here: http://ift.tt/1Awr7XX


I'm on a local network, and am therefore removing the ICE server initialisation process to make this example as bare-bones as possible.


Here are the steps I'm carrying out in the example:


Page 1




  1. Page 1 (loads page), enters a channel name (e.g. test) and clicks create.




  2. A new Host object is created, new PeerConnection() and createDataChannel are called.




  3. createOffer is called, and the resulting offerSDP is pasted into the offer textarea.




Page 2




  1. Copy offerSDP from Page 1 and paste into offer textarea on Page 2, click join.




  2. New Guest object is created, PeerConnection and an ondatachannel handler is set.




  3. setRemoteDescription is called for the Guest object, with the offerSDP data.




  4. createAnswer is called and the result is pasted into the answer textarea box.




Page 1




  1. The answerSDP is copied from Page 2 and pasted into the answer textarea of Page 1, submit answer is clicked.




  2. Host.setRemoteDescription is called with the answerSDP data. This creates a SessionDescription, then peer.setRemoteDescription is called with the resulting data.




Those are the steps carried out in the example, but it seems I'm missing something critical. After the offerer's remoteDescription is set with the answerSDP, I try to send a test message on the dataChannel:


Chrome 40



"-- complete"
> host.dataChannel.send('hello world');
VM1387:2 Uncaught DOMException: Failed to execute 'send' on 'RTCDataChannel': RTCDataChannel.readyState is not 'open'


Firefox 35



"-- complete"
ICE failed, see about:webrtc for more details
> host.dataChannel.send('hello world');
InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable


I also had a more complicated demo operating, with a WebSocket signalling server, and ICE candidates listed, but was getting the same error. So I hope this simplification can help to track down the issue.


Again, the single-file code link: http://ift.tt/1Awr7XX





Aucun commentaire:

Enregistrer un commentaire