Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ending WebRTC video call between two peers

I've set up a video chat between two peers using WebRTC. I would like to allow a peer to end the chat and for the other peer to know that the chat was ended. Once the chat ends, some code needs to be executed for both peers. The PeerConnection object has a removeStream() method which should trigger the onremovestream() listener. This would be perfect for my use case, however, before onremovestream() is called there needs to be a re-negotiation (offer/answer) between the peers. For my case this seems odd. Why would I re-negotiate only to disconnect? Shouldn't the PeerConnection object realize no stream is coming from the other user? My question: how can I end a PeerConnection and alert the other user?

like image 225
chRyNaN Avatar asked Oct 21 '22 00:10

chRyNaN


1 Answers

You can simply close the connection. The other peer can listen for the signal oniceconnectionstatechange and the state of disconnected means that your peer has closed the connection/is no longer available. If I were you, I would do a timeout before closing as this state could be because of a flaky network connection. MDN has some good info

Or, you could keep track of connections with your signalling server and signal the peers when somebody leaves. Either way should work.

like image 129
Benjamin Trent Avatar answered Oct 27 '22 10:10

Benjamin Trent