client/webrtc.js
// function to check if peer disconnected on iceconnectionstatechange event

function to check if peer disconnected on iceconnectionstatechange event
function to check if peer disconnected on iceconnectionstatechange event
function checkPeerDisconnect(event, peerUuid) {
  var state = peerConnections[peerUuid].pc.iceConnectionState; 
  console.log(`connection with peer ${peerUuid} ${state}`);
  if (state === "failed" || state === "closed" || state === "disconnected") { 
    serverConnection.send(JSON.stringify({ uuid: peerUuid , 'state': "disconnected" , "time": time })); 
    delete peerConnections[peerUuid];
    document.getElementById('videos').removeChild(document.getElementById('remoteVideo_' + peerUuid)); 
    updateLayout(); 
    if((flag!=0) && (raiseHandClient==0)){
      var stopped;
      if(time < tThreshold){
        for(var i=0;i<DHT.length;i++){
          if(String(peerUuid)==String(DHT[i])){
            stopped = i;
            break
          }
        }
        if(stopped<2){
          count=1;
          console.log("count is updated", DHT[0]);
          serverConnection.send(JSON.stringify({ 'displayName': localDisplayName, 'uuid': localUuid, 'dest1': String(DHT[0]), "time": time }));
          serverConnection.send(JSON.stringify({"reform": "3", "nextPeer": String(DHT[3]), "uuid" : String(DHT[0]), "time": time }));
          serverConnection.send(JSON.stringify({"reform": "1", "nextPeer": String(DHT[0]), "uuid" : localUuid, "time": time }));
        }
      }
    }else if(flag!=0){
        raiseHandClient==0;
      }
  }
}
function checkPeerDisconnect ( event , peerUuid ) { var state = peerConnections [ peerUuid ] . pc . iceConnectionState ; console . log ( ` ${ peerUuid } ${ state } ` ) ; if ( state === "failed" || state === "closed" || state === "disconnected" ) { serverConnection . send ( JSON . stringify ( { uuid : peerUuid , 'state' : "disconnected" , "time" : time } ) ) ; delete peerConnections [ peerUuid ] ; document . getElementById ( 'videos' ) . removeChild ( document . getElementById ( 'remoteVideo_' + peerUuid ) ) ; updateLayout ( ) ; if ( ( flag != 0 ) && ( raiseHandClient == 0 ) ) { var stopped ; if ( time < tThreshold ) { for ( var i = 0 ; i < DHT . length ; i ++ ) { if ( String ( peerUuid ) == String ( DHT [ i ] ) ) { stopped = i ; break } } if ( stopped < 2 ) { count = 1 ; console . log ( "count is updated" , DHT [ 0 ] ) ; serverConnection . send ( JSON . stringify ( { 'displayName' : localDisplayName , 'uuid' : localUuid , 'dest1' : String ( DHT [ 0 ] ) , "time" : time } ) ) ; serverConnection . send ( JSON . stringify ( { "reform" : "3" , "nextPeer" : String ( DHT [ 3 ] ) , "uuid" : String ( DHT [ 0 ] ) , "time" : time } ) ) ; serverConnection . send ( JSON . stringify ( { "reform" : "1" , "nextPeer" : String ( DHT [ 0 ] ) , "uuid" : localUuid , "time" : time } ) ) ; } } } else if ( flag != 0 ) { raiseHandClient == 0 ; } } }
function to check if peer disconnected on iceconnectionstatechange event
function to check if peer disconnected on iceconnectionstatechange event
//assign state the iceConnectionState of the specific peerUuid
 //check if the connection is failed, closed or disconnected
 //delete the peer details from the object peerConnections
 //remove the peer 
 //update the layout on deletion
 //identify the position of the disconnected peer in DHT
 //the peer succeeding the disconnected peer sends a message to the peer preceding the disconnected peer
