I am trying out webrtc using the library, simple-peer. I am following this tutorial linked here on opera browser. I am facing this error when sending a small string of 'hello':
Uncaught DOMException: Failed to execute 'send' on 'RTCDataChannel': RTCDataChannel.readyState is not 'open' at Peer.send (http://127.0.0.1:9966/bundle.js:7011:19) at HTMLButtonElement.<anonymous> (http://127.0.0.1:9966/bundle.js:22:14) send @ index.js:241 (anonymous) @ index.js:21
Here is my index.js:
var Peer = require('simple-peer')
if (Peer.WEBRTC_SUPPORT) {
console.log("Support");
peer = new Peer({
initiator: location.hash === '#1',
trickle:true
})
peer.on('signal', function (data) {
document.getElementById('yourId').value = JSON.stringify(data)
})
document.getElementById("connect").addEventListener('click', function () {
var otherId = JSON.parse(document.getElementById('otherId').value)
peer.signal(otherId)
})
peer.on('connect', function () {
console.log("CONNECTED");
})
document.getElementById("send").addEventListener('click', function () {
var message = document.getElementById("message_to_send").value
peer.write(message)
})
peer.on("data", function (data) {
console.log(data)
document.getElementById("messages").textContent += data + "\n"
})
} else {
console.log("No Support, Sorry");
}
Changing
peer.send(data)
to
peer.write(data)
does to give any error, but nor does it send the data to the other browser
What am I doing wrong? Thanks in advance
I got it to work. If useful to anybody: I was using the opera browser, which blocked my IP address from "leaking". Switching to Chrome worked like a charm See if your browser is blocking your IP address using this link: https://diafygi.github.io/webrtc-ips/