Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 38 additions & 20 deletions src/sdk/conference/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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();
}
}
}

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down