@@ -47,6 +47,7 @@ export class ConferencePeerConnectionChannel extends EventDispatcher {
47
47
// Timer for PeerConnection disconnected. Will stop connection after timer.
48
48
this . _disconnectTimer = null ;
49
49
this . _ended = false ;
50
+ this . _stopped = false ;
50
51
}
51
52
52
53
/**
@@ -367,24 +368,30 @@ export class ConferencePeerConnectionChannel extends EventDispatcher {
367
368
}
368
369
369
370
_unpublish ( ) {
370
- this . _signaling . sendSignalingMessage ( 'unpublish' , { id : this . _internalId } )
371
- . catch ( ( e ) => {
372
- Logger . warning ( 'MCU returns negative ack for unpublishing, ' + e ) ;
373
- } ) ;
374
- if ( this . _pc && this . _pc . signalingState !== 'closed' ) {
375
- this . _pc . close ( ) ;
371
+ if ( ! this . _stopped ) {
372
+ this . _stopped = true ;
373
+ this . _signaling . sendSignalingMessage ( 'unpublish' , { id : this . _internalId } )
374
+ . catch ( ( e ) => {
375
+ Logger . warning ( 'MCU returns negative ack for unpublishing, ' + e ) ;
376
+ } ) ;
377
+ if ( this . _pc && this . _pc . signalingState !== 'closed' ) {
378
+ this . _pc . close ( ) ;
379
+ }
376
380
}
377
381
}
378
382
379
383
_unsubscribe ( ) {
380
- this . _signaling . sendSignalingMessage ( 'unsubscribe' , {
381
- id : this . _internalId ,
382
- } )
383
- . catch ( ( e ) => {
384
- Logger . warning ( 'MCU returns negative ack for unsubscribing, ' + e ) ;
385
- } ) ;
386
- if ( this . _pc && this . _pc . signalingState !== 'closed' ) {
387
- this . _pc . close ( ) ;
384
+ if ( ! this . _stopped ) {
385
+ this . _stopped = true ;
386
+ this . _signaling . sendSignalingMessage ( 'unsubscribe' , {
387
+ id : this . _internalId ,
388
+ } )
389
+ . catch ( ( e ) => {
390
+ Logger . warning ( 'MCU returns negative ack for unsubscribing, ' + e ) ;
391
+ } ) ;
392
+ if ( this . _pc && this . _pc . signalingState !== 'closed' ) {
393
+ this . _pc . close ( ) ;
394
+ }
388
395
}
389
396
}
390
397
@@ -483,12 +490,18 @@ export class ConferencePeerConnectionChannel extends EventDispatcher {
483
490
return ;
484
491
}
485
492
486
- Logger . debug ( 'ICE connection state changed to '
487
- + event . currentTarget . iceConnectionState ) ;
488
- if ( event . currentTarget . iceConnectionState === 'closed'
489
- || event . currentTarget . iceConnectionState === 'failed' ) {
490
- this . _rejectPromise (
491
- new ConferenceError ( 'ICE connection failed or closed.' ) ) ;
493
+ Logger . debug ( 'ICE connection state changed to ' +
494
+ event . currentTarget . iceConnectionState ) ;
495
+ if ( event . currentTarget . iceConnectionState === 'closed' ||
496
+ event . currentTarget . iceConnectionState === 'failed' ) {
497
+ // Fire ended event if publication or subscription exists.
498
+ this . _fireEndedEventOnPublicationOrSubscription ( ) ;
499
+ }
500
+ }
501
+
502
+ _onConnectionStateChange ( event ) {
503
+ if ( this . _pc . connectionState === 'closed' ||
504
+ this . _pc . connectionState === 'failed' ) {
492
505
// Fire ended event if publication or subscription exists.
493
506
this . _fireEndedEventOnPublicationOrSubscription ( ) ;
494
507
}
@@ -523,6 +536,9 @@ export class ConferencePeerConnectionChannel extends EventDispatcher {
523
536
this . _pc . oniceconnectionstatechange = ( event ) => {
524
537
this . _onIceConnectionStateChange . apply ( this , [ event ] ) ;
525
538
} ;
539
+ this . _pc . onconnectionstatechange = ( event ) => {
540
+ this . _onConnectionStateChange . apply ( this , [ event ] ) ;
541
+ } ;
526
542
}
527
543
528
544
_getStats ( ) {
@@ -598,6 +614,8 @@ export class ConferencePeerConnectionChannel extends EventDispatcher {
598
614
error : error ,
599
615
} ) ;
600
616
dispatcher . dispatchEvent ( errorEvent ) ;
617
+ // Fire ended event when error occured
618
+ this . _fireEndedEventOnPublicationOrSubscription ( ) ;
601
619
}
602
620
603
621
_setCodecOrder ( sdp , options ) {
0 commit comments