I can use the following code to create a new peer connection object:
var peer = new RTCPeerConnection();
When this happens, chrome shows it as new connection object in chrome://webrtc-internals/
I would like to destroy this object later. How to do it? I tried
peer.close();
but this does not seem to do anything, since the peer variable is still of type RTCPeerConnection and I can still see it active in chrome://webrtc-internals/.
If I unset the variable, like
peer=false;
it still shows it in chrome://webrtc-internals/. Yet if I close the webpage then it immediately disappears from chrome://webrtc-internals/.
What is the proper way to free the RTCPeerConnection object? I am asking because if I do not free them, I am occasionally getting refusal from web browser to create new RTCPeerConnection because there are too many of them in use.
Actually
peer.close();
is a right way to do it.
You can also do something like this:
peer.close();
peer = null;
Here is some snippets from original WebRTC code samples:
function hangup() {
console.log('Ending call');
pc1.close();
pc2.close();
pc1 = null;
pc2 = null;
hangupButton.disabled = true;
callButton.disabled = false;
}
https://github.com/webrtc/samples/blob/gh-pages/src/content/peerconnection/pc1/js/main.js#L175
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With