File tree 1 file changed +9
-2
lines changed
1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -32,9 +32,12 @@ var EVENTS_DECOUPLE_AC = [
32
32
33
33
**/
34
34
module . exports = function ( pc ) {
35
+ if ( ! pc ) return ;
36
+
35
37
// see if we can close the connection
36
38
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 ;
38
41
39
42
function decouple ( events ) {
40
43
events . forEach ( function ( evtName ) {
@@ -49,7 +52,11 @@ module.exports = function(pc) {
49
52
50
53
if ( canClose ) {
51
54
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
+ }
53
60
}
54
61
55
62
// remove the event listeners
You can’t perform that action at this time.
0 commit comments