client/webrtc.js
//function to create video element and set its attributes once got the remote stream from peer

function to create video element and set its attributes once got the remote stream from peer
function to create video element and set its attributes once got the remote stream from peer
function gotRemoteStream(event, peerUuid) {
  console.log(`got remote stream, peer ${peerUuid}`);
  if(count==1){
    console.log("count is one here")
    count=0;
    var vidContainer = document.createElement('div');
    var vidElement1 = document.createElement('video');
    vidElement1.setAttribute('autoplay', '');
    vidElement1.srcObject = event.streams[0]; 
    peerStream=event.streams[0]
    vidContainer.setAttribute('id', 'remoteVideo_' + peerUuid);
    window.setTimeout(function(){
      var elements = document.getElementsByClassName("videoContainer");
      while(elements.length != 1){
          elements[1].parentNode.removeChild(elements[1]);
      }
      deleteVideoElement(peerUuid)
      updateLayout();
    }, 1000);
    vidContainer.setAttribute('class', 'videoContainer1');
    vidContainer.appendChild(vidElement1);
    vidContainer.appendChild(makeLabel(peerConnections[peerUuid].displayName));
    document.getElementById('videos').appendChild(vidContainer);
    serverConnection.send(JSON.stringify({"churn": true, "uuid": String(DHT[3]), "time": time }));  
    deleteVideoElement(peerUuid)
    updateLayout();
    }
    else{
    var vidContainer = document.createElement('div'); 
    vidElement = document.createElement('video'); 
    vidElement.setAttribute('autoplay', '');
    if(first==0){ 
      vidElement.srcObject = event.streams[0]; 
      remoteStream = event.streams[0]; 
      peerStream=remoteStream;
      first++;
    } 
    if(renewFeed==1){
      vidElement.srcObject = event.streams[0]
      renewFeed=0;
    }
    if(raiseHand == 1){
      vidElement.srcObject = event.streams[0]
      raiseHand=0;
    }
    vidContainer.setAttribute('id', 'remoteVideo_' + peerUuid); 
    arr.push('remoteVideo_' + peerUuid) 
    if(arr[0] != arr[1]){   
      vidContainer.setAttribute('class', 'videoContainer');
      if(vidContainer.childNodes.length === 0){
        vidContainer.appendChild(vidElement); 
        vidContainer.appendChild(makeLabel(peerConnections[peerUuid].displayName));
        document.getElementById('videos').appendChild(vidContainer);
        deleteVideoElement(peerUuid);
        updateLayout();
      } 
    }else if(arr[0] == arr[1]){
      arr=[]
    }
  }
}
function gotRemoteStream ( event , peerUuid ) { console . log ( ` ${ peerUuid } ` ) ; if ( count == 1 ) { console . log ( "count is one here" ) count = 0 ; var vidContainer = document . createElement ( 'div' ) ; var vidElement1 = document . createElement ( 'video' ) ; vidElement1 . setAttribute ( 'autoplay' , '' ) ; vidElement1 . srcObject = event . streams [ 0 ] ; peerStream = event . streams [ 0 ] vidContainer . setAttribute ( 'id' , 'remoteVideo_' + peerUuid ) ; window . setTimeout ( function ( ) { var elements = document . getElementsByClassName ( "videoContainer" ) ; while ( elements . length != 1 ) { elements [ 1 ] . parentNode . removeChild ( elements [ 1 ] ) ; } deleteVideoElement ( peerUuid ) updateLayout ( ) ; } , 1000 ) ; vidContainer . setAttribute ( 'class' , 'videoContainer1' ) ; vidContainer . appendChild ( vidElement1 ) ; vidContainer . appendChild ( makeLabel ( peerConnections [ peerUuid ] . displayName ) ) ; document . getElementById ( 'videos' ) . appendChild ( vidContainer ) ; serverConnection . send ( JSON . stringify ( { "churn" : true , "uuid" : String ( DHT [ 3 ] ) , "time" : time } ) ) ; deleteVideoElement ( peerUuid ) updateLayout ( ) ; } else { var vidContainer = document . createElement ( 'div' ) ; vidElement = document . createElement ( 'video' ) ; vidElement . setAttribute ( 'autoplay' , '' ) ; if ( first == 0 ) { vidElement . srcObject = event . streams [ 0 ] ; remoteStream = event . streams [ 0 ] ; peerStream = remoteStream ; first ++ ; } if ( renewFeed == 1 ) { vidElement . srcObject = event . streams [ 0 ] renewFeed = 0 ; } if ( raiseHand == 1 ) { vidElement . srcObject = event . streams [ 0 ] raiseHand = 0 ; } vidContainer . setAttribute ( 'id' , 'remoteVideo_' + peerUuid ) ; arr . push ( 'remoteVideo_' + peerUuid ) if ( arr [ 0 ] != arr [ 1 ] ) { vidContainer . setAttribute ( 'class' , 'videoContainer' ) ; if ( vidContainer . childNodes . length === 0 ) { vidContainer . appendChild ( vidElement ) ; vidContainer . appendChild ( makeLabel ( peerConnections [ peerUuid ] . displayName ) ) ; document . getElementById ( 'videos' ) . appendChild ( vidContainer ) ; deleteVideoElement ( peerUuid ) ; updateLayout ( ) ; } } else if ( arr [ 0 ] == arr [ 1 ] ) { arr = [ ] } } }
function to create video element and set its attributes once got the remote stream from peer
function to create video element and set its attributes once got the remote stream from peer
//for peers reconnecting after churn
 //create a HTMLDivElement
 //create a video element
 //enable autoplay
 //sets vidElement1 as event stream
 //sets peerStream as event stream
 //a new attribute is added with the specified name and value
 //In case of peer churn delete all elements with videocntainer class except the first stream (own localstream) and only show elements with videocontainer1 class
 //append the video elements to the vidContainer
 //append the label containing display name of the peer to vidContainer
 //send a message to the next peer prompting it to reconnect
 //create a button on the video feed itself providing an option to delete it
 //create a HTMLDivElement
 //create a video element
 //enable autoplay
 /* defines source object for video element in different cases */ //if new client
 //sets vidElement as event stream
 //sets remoteStream as event stream
 //if client requests to renew feed
 //enables master to view the feed of client requesting raise hand
 //a new attribute is added with the specified name and value
 // append the two concurrent streams onto the empty array
 //adds a new peer only if the peer is not already present in the meeting
 //to ensure that one client gets only one feed
 //append the video element to the vidContainer
 //append the label containing display name of the peer to vidContainer
 //create a button on the video feed itself providing an option to delete it
