UPDATE
It seems I can do myPeerConnection.getStats() as described here I can measure the bytes sent or recieved. If they increase that means we are connected and the disconnected ICE state will be treated as temporary. otherwise, it is permanent.
But now I am confused about which byte I should measure. There inbound-rtp, outbound-rtp, remote-inbound-rtp and remote-outbound-rtp.
I want to make sure that both sides are actually receiving data from each other. So what should I measure from the above four?
ORIGINAL
Sometimes on unstable networks ICE state can change to 'Disconnected' and will normally try to recover on its own. 'Failed' state will need ICE renegotiated. But there will be cases when the other peer has just lost connection or died and in that case I will get 'Disconnected' and then after sometime 'Failed' states. I need to know when the peer connection is still alive and when it is dead so that I can take appropriate action.
function handleICEConnectionStateChangeEvent(event) {
log("*** ICE connection state changed to " + myPeerConnection.iceConnectionState);
switch(myPeerConnection.iceConnectionState) {
case "closed": // This means connection is shut down and no longer handling requests.
hangUpCall(); //Hangup instead of closevideo() because we want to record call end in db
break;
case "failed": // This will not restart ICE negotiation on its own and must be restarted/
myPeerConnection.restartIce();
break;
case "disconnected":
//This will resolve on its own. No need to close connection.
//But in case the other peer connection is dead we want to call the below function.
//hangUpCall(); //Hangup instead of closevideo() because we want to record call end in db
//break;
}
}
I would like something like
case "disconnected":
if(!otherPeerConnected){
hangUpCall();
}
Is there anyway to do this?
Thank you