Skip to content

Commit c7c011a

Browse files
committed
Checks the signaling state of the pc for close ability, as well as catching pc.close exceptions
1 parent 3ab676e commit c7c011a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

cleanup.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ var EVENTS_DECOUPLE_AC = [
3232
3333
**/
3434
module.exports = function(pc) {
35+
if (!pc) return;
36+
3537
// see if we can close the connection
3638
var currentState = pc.iceConnectionState;
37-
var canClose = CANNOT_CLOSE_STATES.indexOf(currentState) < 0;
39+
var currentSignaling = pc.signalingState;
40+
var canClose = CANNOT_CLOSE_STATES.indexOf(currentState) < 0 && CANNOT_CLOSE_STATES.indexOf(currentSignaling) < 0;
3841

3942
function decouple(events) {
4043
events.forEach(function(evtName) {
@@ -49,7 +52,11 @@ module.exports = function(pc) {
4952

5053
if (canClose) {
5154
debug('attempting connection close, current state: '+ pc.iceConnectionState);
52-
pc.close();
55+
try {
56+
pc.close();
57+
} catch (e) {
58+
console.warn('Could not close connection', e);
59+
}
5360
}
5461

5562
// remove the event listeners

0 commit comments

Comments
 (0)