GentleMan
GentleMan

Reputation: 87

Failed to execute 'send' on 'RTCDataChannel': RTCDataChannel.readyState is not 'open'

I am trying to learn WebRTC . I copied some codes and i get this error:

Failed to execute 'send' on 'RTCDataChannel': RTCDataChannel.readyState is not 'open'

Any one can help?

code score: http://www.tutorialspoint.com/webrtc/webrtc_text_demo.htm

Upvotes: 7

Views: 7896

Answers (2)

Sachin Negi
Sachin Negi

Reputation: 51

The same error was thrown to me .This is because your peers are not connected and you are sending data.This was solved by this:

peer.on('connect', () => {
    console.log('I am connected now')
    peer.send('sending data blah blah')
  })

Upvotes: 0

bronyuk
bronyuk

Reputation: 121

Add ondatachannel handling after removing {optional: [{RtpDataChannels: true}]}:

  myConnection.onicecandidate = function (event) { 

     if (event.candidate) { 
        send({ 
           type: "candidate", 
           candidate: event.candidate 
        });
     } 
  }; 

  myConnection.ondatachannel = function(event) {
     var receiveChannel = event.channel;
     receiveChannel.onmessage = function(event) {
        console.log("ondatachannel message:", event.data);
     };
  };

  openDataChannel();

Upvotes: 12

Related Questions