@@ -48,6 +48,7 @@ export class ConferencePeerConnectionChannel extends EventDispatcher {
48
48
// Timer for PeerConnection disconnected. Will stop connection after timer.
49
49
this . _disconnectTimer = null ;
50
50
this . _ended = false ;
51
+ this . _stopped = false ;
51
52
}
52
53
53
54
/**
@@ -407,24 +408,30 @@ export class ConferencePeerConnectionChannel extends EventDispatcher {
407
408
}
408
409
409
410
_unpublish ( ) {
410
- this . _signaling . sendSignalingMessage ( 'unpublish' , { id : this . _internalId } )
411
- . catch ( ( e ) => {
412
- Logger . warning ( 'MCU returns negative ack for unpublishing, ' + e ) ;
413
- } ) ;
414
- if ( this . _pc && this . _pc . signalingState !== 'closed' ) {
415
- this . _pc . close ( ) ;
411
+ if ( ! this . _stopped ) {
412
+ this . _stopped = true ;
413
+ this . _signaling . sendSignalingMessage ( 'unpublish' , { id : this . _internalId } )
414
+ . catch ( ( e ) => {
415
+ Logger . warning ( 'MCU returns negative ack for unpublishing, ' + e ) ;
416
+ } ) ;
417
+ if ( this . _pc && this . _pc . signalingState !== 'closed' ) {
418
+ this . _pc . close ( ) ;
419
+ }
416
420
}
417
421
}
418
422
419
423
_unsubscribe ( ) {
420
- this . _signaling . sendSignalingMessage ( 'unsubscribe' , {
421
- id : this . _internalId ,
422
- } )
423
- . catch ( ( e ) => {
424
- Logger . warning ( 'MCU returns negative ack for unsubscribing, ' + e ) ;
425
- } ) ;
426
- if ( this . _pc && this . _pc . signalingState !== 'closed' ) {
427
- this . _pc . close ( ) ;
424
+ if ( ! this . _stopped ) {
425
+ this . _stopped = true ;
426
+ this . _signaling . sendSignalingMessage ( 'unsubscribe' , {
427
+ id : this . _internalId ,
428
+ } )
429
+ . catch ( ( e ) => {
430
+ Logger . warning ( 'MCU returns negative ack for unsubscribing, ' + e ) ;
431
+ } ) ;
432
+ if ( this . _pc && this . _pc . signalingState !== 'closed' ) {
433
+ this . _pc . close ( ) ;
434
+ }
428
435
}
429
436
}
430
437
@@ -528,10 +535,23 @@ export class ConferencePeerConnectionChannel extends EventDispatcher {
528
535
if ( event . currentTarget . iceConnectionState === 'closed' ||
529
536
event . currentTarget . iceConnectionState === 'failed' ) {
530
537
if ( event . currentTarget . iceConnectionState === 'failed' ) {
531
- this . _handleError ( 'ICE connection failed.' ) ;
538
+ this . _handleError ( 'connection failed.' ) ;
539
+ } else {
540
+ // Fire ended event if publication or subscription exists.
541
+ this . _fireEndedEventOnPublicationOrSubscription ( ) ;
542
+ }
543
+ }
544
+ }
545
+
546
+ _onConnectionStateChange ( event ) {
547
+ if ( this . _pc . connectionState === 'closed' ||
548
+ this . _pc . connectionState === 'failed' ) {
549
+ if ( this . _pc . connectionState === 'failed' ) {
550
+ this . _handleError ( 'connection failed.' ) ;
551
+ } else {
552
+ // Fire ended event if publication or subscription exists.
553
+ this . _fireEndedEventOnPublicationOrSubscription ( ) ;
532
554
}
533
- // Fire ended event if publication or subscription exists.
534
- this . _fireEndedEventOnPublicationOrSubscription ( ) ;
535
555
}
536
556
}
537
557
@@ -564,6 +584,9 @@ export class ConferencePeerConnectionChannel extends EventDispatcher {
564
584
this . _pc . oniceconnectionstatechange = ( event ) => {
565
585
this . _onIceConnectionStateChange . apply ( this , [ event ] ) ;
566
586
} ;
587
+ this . _pc . onconnectionstatechange = ( event ) => {
588
+ this . _onConnectionStateChange . apply ( this , [ event ] ) ;
589
+ } ;
567
590
}
568
591
569
592
_getStats ( ) {
@@ -645,6 +668,8 @@ export class ConferencePeerConnectionChannel extends EventDispatcher {
645
668
error : error ,
646
669
} ) ;
647
670
dispatcher . dispatchEvent ( errorEvent ) ;
671
+ // Fire ended event when error occured
672
+ this . _fireEndedEventOnPublicationOrSubscription ( ) ;
648
673
}
649
674
650
675
_setCodecOrder ( sdp , options ) {
0 commit comments