diff --git a/src/sdk/conference/channel.js b/src/sdk/conference/channel.js index 0084b882..43090f75 100644 --- a/src/sdk/conference/channel.js +++ b/src/sdk/conference/channel.js @@ -47,6 +47,7 @@ export class ConferencePeerConnectionChannel extends EventDispatcher { // Timer for PeerConnection disconnected. Will stop connection after timer. this._disconnectTimer = null; this._ended = false; + this._stopped = false; } /** @@ -367,24 +368,30 @@ export class ConferencePeerConnectionChannel extends EventDispatcher { } _unpublish() { - this._signaling.sendSignalingMessage('unpublish', {id: this._internalId}) - .catch((e) => { - Logger.warning('MCU returns negative ack for unpublishing, ' + e); - }); - if (this._pc && this._pc.signalingState !== 'closed') { - this._pc.close(); + if (!this._stopped) { + this._stopped = true; + this._signaling.sendSignalingMessage('unpublish', {id: this._internalId}) + .catch((e) => { + Logger.warning('MCU returns negative ack for unpublishing, ' + e); + }); + if (this._pc && this._pc.signalingState !== 'closed') { + this._pc.close(); + } } } _unsubscribe() { - this._signaling.sendSignalingMessage('unsubscribe', { - id: this._internalId, - }) - .catch((e) => { - Logger.warning('MCU returns negative ack for unsubscribing, ' + e); - }); - if (this._pc && this._pc.signalingState !== 'closed') { - this._pc.close(); + if (!this._stopped) { + this._stopped = true; + this._signaling.sendSignalingMessage('unsubscribe', { + id: this._internalId, + }) + .catch((e) => { + Logger.warning('MCU returns negative ack for unsubscribing, ' + e); + }); + if (this._pc && this._pc.signalingState !== 'closed') { + this._pc.close(); + } } } @@ -483,12 +490,18 @@ export class ConferencePeerConnectionChannel extends EventDispatcher { return; } - Logger.debug('ICE connection state changed to ' - + event.currentTarget.iceConnectionState); - if (event.currentTarget.iceConnectionState === 'closed' - || event.currentTarget.iceConnectionState === 'failed') { - this._rejectPromise( - new ConferenceError('ICE connection failed or closed.')); + Logger.debug('ICE connection state changed to ' + + event.currentTarget.iceConnectionState); + if (event.currentTarget.iceConnectionState === 'closed' || + event.currentTarget.iceConnectionState === 'failed') { + // Fire ended event if publication or subscription exists. + this._fireEndedEventOnPublicationOrSubscription(); + } + } + + _onConnectionStateChange(event) { + if (this._pc.connectionState === 'closed' || + this._pc.connectionState === 'failed') { // Fire ended event if publication or subscription exists. this._fireEndedEventOnPublicationOrSubscription(); } @@ -523,6 +536,9 @@ export class ConferencePeerConnectionChannel extends EventDispatcher { this._pc.oniceconnectionstatechange = (event) => { this._onIceConnectionStateChange.apply(this, [event]); }; + this._pc.onconnectionstatechange = (event) => { + this._onConnectionStateChange.apply(this, [event]); + }; } _getStats() { @@ -598,6 +614,8 @@ export class ConferencePeerConnectionChannel extends EventDispatcher { error: error, }); dispatcher.dispatchEvent(errorEvent); + // Fire ended event when error occured + this._fireEndedEventOnPublicationOrSubscription(); } _setCodecOrder(sdp, options) {