keep a reference to the datachannel to avoid buggy garbage collection

This commit is contained in:
Philipp Hancke 2014-08-21 17:04:27 +02:00
parent fe311cce58
commit 310e36d128
1 changed files with 10 additions and 0 deletions

View File

@ -1,9 +1,15 @@
/* global connection, Strophe, updateLargeVideo, focusedVideoSrc*/ /* global connection, Strophe, updateLargeVideo, focusedVideoSrc*/
// cache datachannels to avoid garbage collection
// https://code.google.com/p/chromium/issues/detail?id=405545
var _dataChannels = [];
/** /**
* Callback triggered by PeerConnection when new data channel is opened * Callback triggered by PeerConnection when new data channel is opened
* on the bridge. * on the bridge.
* @param event the event info object. * @param event the event info object.
*/ */
function onDataChannel(event) function onDataChannel(event)
{ {
var dataChannel = event.channel; var dataChannel = event.channel;
@ -82,7 +88,11 @@ function onDataChannel(event)
dataChannel.onclose = function () dataChannel.onclose = function ()
{ {
console.info("The Data Channel closed", dataChannel); console.info("The Data Channel closed", dataChannel);
var idx = _dataChannels.indexOf(dataChannel);
if (idx > -1)
_dataChannels = _dataChannels.splice(idx, 1);
}; };
_dataChannels.push(dataChannel);
} }
/** /**