at Peer._onConnectionStateChange (index.js:660) at RTCPeerConnection.Peer._pc.onconnectionstatechange (index.js:122)

Viewed 403

I am making a simple peer to peer system from this YouTube video https://www.youtube.com/watch?v=ieBtXwHvoNk I have got the following code

var Peer = require('simple-peer');
var peer = new Peer({
    initiator: location.hash === "#init",
    trickle: false
})

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)
})

document.getElementById('send').addEventListener("click", function(){
    var yourMessage = document.getElementById('yourMessage').value 
    peer.send(yourMessage);
})

peer.on('data', function (data){
    document.getElementById('messages').textContent += data + '\n';
})

in my javascript file. However I am getting the error connection failed when attempting to send a message. Unfortunately my code does not seem be able to find the peer ID for a non initiator window, so I am running this between two #init windows. Could this be the error, if so how to fix it?

0 Answers
Related