SHARE
TWEET

Untitled

a guest Jun 17th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function openStream(){
  2.    const config = {video: true, audio: true};
  3.    return navigator.mediaDevices.getUserMedia(config)
  4. }
  5.  
  6. function playStream(id,stream){
  7.    const video = document.getElementById(id);
  8.    video.srcObject = stream;
  9.    video.play()
  10. }
  11.  
  12. const peer = new Peer({key: 'lwjd5qra8257b9'})
  13.  
  14. peer.on('open', (id)=>{
  15.   console.log(id)
  16.   $('#myid').append(id)
  17. })
  18.  
  19. $('button').click(() => {
  20.   const id = $('#remoteid').val();
  21.   openStream()
  22.   .then(stream => {
  23.     playStream('localVideo', stream);
  24.     const call = peer.call(id, stream);
  25.     call.on('stream', remoteStream => playStream('remoteVideo',
  26.   remoteStream));
  27.   });
  28. });
  29.  
  30. //Callee
  31. peer.on('call', call => {
  32.     openStream()
  33.     .then(stream => {
  34.        call.answer(stream);
  35.        playStream('localVideo', stream);
  36.       call.on('stream', remoteStream => playStream('remoteVideo',
  37. remoteStream));
  38.     });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top