P2P Video Chat - Stream not working

173 views
Skip to first unread message

Manan Chaturvedi

unread,
Nov 3, 2019, 11:11:44 PM11/3/19
to PeerJS
User connection works, messages through '.send' is working, however i am unable to get it to show Webcam stream from 2peers

HTML
<div class="Container">
<video height="400px" width="500px" autoplay class="Opp"></video>
<video height="400px" width="500px" muted="false" autoplay class="Own"></video>
</div>

<p class="PeerId">Your ID : </p>

<input required type="text" class="Conn-Field"><a href="#" class="Conn-Now">Connect</a>

JavaScript
const Own = document.querySelector('.Own')
const Opp = document.querySelector('.Opp')
const ConnBtn = document.querySelector('.Conn-Now')
const Field = document.querySelector('.Conn-Field')
const PeerId = document.querySelector('.PeerId')
let PiD;

var peer = new Peer({debug: 3,
 config: {'iceServers': [
{url: 'turn:numb.viagenie.ca', username: 'manancha...@gmail.com', credential: 'somerandompass'}
]}
});

peer.on('open', function(id) {
 PeerId.innerText = 'Your ID : ' + peer.id;
});

ConnBtn.addEventListener('click', () => {
const conn = peer.connect(Field.value);

 conn.on('open', function(){

  var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
  getUserMedia({video: true, audio: true}, function(stream) {
  var call = peer.call(Field.value, stream);
  call.on('stream', function(remoteStream) {
   Own.srcObject = remoteStream
   Own.play()
  });
}, function(err) {
 console.log('Failed to get local stream' ,err);
});
});
})

peer.on('connection', function(conn) {
 var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
  peer.on('call', function(call) {
  getUserMedia({video: true, audio: true}, function(stream) {
  call.answer(stream); // Answer the call with an A/V stream.
  call.on('stream', function(remoteStream) {
   Opp.srcObject = remoteStream
   Opp.play()
   });
 }, function(err) {
   console.log('Failed to get local stream' ,err);
 });
});
});




Reply all
Reply to author
Forward
0 new messages