Merge branch 'mediasoup' of github.com:OpenVidu/openvidu into mediasoup

pull/600/head
cruizba 2020-09-03 19:41:03 +02:00
commit b399e686ed
7 changed files with 17 additions and 65 deletions

View File

@ -99,14 +99,6 @@ export class Session extends EventDispatcher {
*/ */
remoteStreamsCreated: ObjMap<boolean> = {}; remoteStreamsCreated: ObjMap<boolean> = {};
/**
* @hidden
*/
isFirstIonicIosSubscriber = true;
/**
* @hidden
*/
countDownForIonicIosSubscribersActive = true;
/** /**
* @hidden * @hidden
*/ */
@ -724,11 +716,6 @@ export class Session extends EventDispatcher {
streamEvent.callDefaultBehavior(); streamEvent.callDefaultBehavior();
delete this.remoteStreamsCreated[stream.streamId]; delete this.remoteStreamsCreated[stream.streamId];
if (Object.keys(this.remoteStreamsCreated).length === 0) {
this.isFirstIonicIosSubscriber = true;
this.countDownForIonicIosSubscribersActive = true;
}
} }
delete this.remoteConnections[connection.connectionId]; delete this.remoteConnections[connection.connectionId];
this.ee.emitEvent('connectionDestroyed', [new ConnectionEvent(false, this, 'connectionDestroyed', connection, msg.reason)]); this.ee.emitEvent('connectionDestroyed', [new ConnectionEvent(false, this, 'connectionDestroyed', connection, msg.reason)]);
@ -798,12 +785,6 @@ export class Session extends EventDispatcher {
// Deleting the remote stream // Deleting the remote stream
const streamId: string = connection.stream.streamId; const streamId: string = connection.stream.streamId;
delete this.remoteStreamsCreated[streamId]; delete this.remoteStreamsCreated[streamId];
if (Object.keys(this.remoteStreamsCreated).length === 0) {
this.isFirstIonicIosSubscriber = true;
this.countDownForIonicIosSubscribersActive = true;
}
connection.removeStream(streamId); connection.removeStream(streamId);
}) })
.catch(openViduError => { .catch(openViduError => {

View File

@ -913,7 +913,7 @@ export class Stream extends EventDispatcher {
*/ */
initWebRtcPeerReceive(reconnect: boolean): Promise<any> { initWebRtcPeerReceive(reconnect: boolean): Promise<any> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.session.openvidu.sendRequest('prepareReceiveVideFrom', { sender: this.streamId }, (error, response) => { this.session.openvidu.sendRequest('prepareReceiveVideFrom', { sender: this.streamId, reconnect }, (error, response) => {
if (error) { if (error) {
reject(new Error('Error on prepareReceiveVideFrom: ' + JSON.stringify(error))); reject(new Error('Error on prepareReceiveVideFrom: ' + JSON.stringify(error)));
} else { } else {
@ -965,26 +965,6 @@ export class Stream extends EventDispatcher {
reject(new Error('Error on receiveVideFrom: ' + JSON.stringify(error))); reject(new Error('Error on receiveVideFrom: ' + JSON.stringify(error)));
} else { } else {
resolve(); resolve();
// // Ios Ionic. Limitation: some bug in iosrtc cordova plugin makes it necessary
// // to add a timeout before calling PeerConnection#setRemoteDescription during
// // some time (400 ms) from the moment first subscriber stream is received
// if (this.session.isFirstIonicIosSubscriber) {
// this.session.isFirstIonicIosSubscriber = false;
// setTimeout(() => {
// // After 400 ms Ionic iOS subscribers won't need to run
// // PeerConnection#setRemoteDescription after 250 ms timeout anymore
// this.session.countDownForIonicIosSubscribersActive = false;
// }, 400);
// }
// const needsTimeoutOnProcessAnswer = this.session.countDownForIonicIosSubscribersActive;
// this.webRtcPeer.processAnswer(response.sdpAnswer, needsTimeoutOnProcessAnswer).then(() => {
// logger.info("'Subscriber' (" + this.streamId + ") successfully " + (reconnect ? "reconnected" : "subscribed"));
// this.remotePeerSuccessfullyEstablished();
// this.initWebRtcStats();
// resolve();
// }).catch(error => {
// reject(error);
// });
} }
}); });
}; };

View File

@ -232,8 +232,7 @@ export class WebRtcPeer {
if (this.pc.signalingState === 'closed') { if (this.pc.signalingState === 'closed') {
reject('RTCPeerConnection is closed when trying to set remote description'); reject('RTCPeerConnection is closed when trying to set remote description');
} }
// TODO: check if Ionic iOS still needs timeout on setting first remote description when subscribing this.setRemoteDescription(offer)
this.setRemoteDescription(offer, false)
.then(() => { .then(() => {
resolve(); resolve();
}) })
@ -272,7 +271,7 @@ export class WebRtcPeer {
if (this.pc.signalingState === 'closed') { if (this.pc.signalingState === 'closed') {
reject('RTCPeerConnection is closed when trying to set remote description'); reject('RTCPeerConnection is closed when trying to set remote description');
} }
this.setRemoteDescription(answer, false) this.setRemoteDescription(answer)
.then(() => resolve()) .then(() => resolve())
.catch(error => reject(error)); .catch(error => reject(error));
}); });
@ -281,22 +280,8 @@ export class WebRtcPeer {
/** /**
* @hidden * @hidden
*/ */
async setRemoteDescription(sdp: RTCSessionDescriptionInit, needsTimeoutOnProcessAnswer: boolean): Promise<void> { async setRemoteDescription(sdp: RTCSessionDescriptionInit): Promise<void> {
// if (platform['isIonicIos']) {
// // Ionic iOS platform
// if (needsTimeoutOnProcessAnswer) {
// // 400 ms have not elapsed yet since first remote stream triggered Stream#initWebRtcPeerReceive
// await new Promise(resolve => setTimeout(resolve, 250)); // Sleep for 250ms
// logger.info('setRemoteDescription run after timeout for Ionic iOS device');
// return this.pc.setRemoteDescription(sdp);
// } else {
// // 400 ms have elapsed
// return this.pc.setRemoteDescription(sdp);
// }
// } else {
// Rest of platforms
return this.pc.setRemoteDescription(sdp); return this.pc.setRemoteDescription(sdp);
// }
} }
/** /**

View File

@ -72,6 +72,7 @@ public class ProtocolElements {
public static final String PREPARERECEIVEVIDEO_METHOD = "prepareReceiveVideFrom"; public static final String PREPARERECEIVEVIDEO_METHOD = "prepareReceiveVideFrom";
public static final String PREPARERECEIVEVIDEO_SDPOFFER_PARAM = "sdpOffer"; public static final String PREPARERECEIVEVIDEO_SDPOFFER_PARAM = "sdpOffer";
public static final String PREPARERECEIVEVIDEO_RECONNECT_PARAM = "reconnect";
public static final String RECEIVEVIDEO_METHOD = "receiveVideoFrom"; public static final String RECEIVEVIDEO_METHOD = "receiveVideoFrom";
public static final String RECEIVEVIDEO_SDPOFFER_PARAM = "sdpOffer"; public static final String RECEIVEVIDEO_SDPOFFER_PARAM = "sdpOffer";

View File

@ -106,7 +106,7 @@ public abstract class SessionManager {
public abstract void unpublishVideo(Participant participant, Participant moderator, Integer transactionId, public abstract void unpublishVideo(Participant participant, Participant moderator, Integer transactionId,
EndReason reason); EndReason reason);
public abstract void prepareSubscription(Participant participant, String senderPublicId, Integer id); public abstract void prepareSubscription(Participant participant, String senderPublicId, boolean reconnect, Integer id);
public abstract void subscribe(Participant participant, String senderName, String sdpAnwser, Integer transactionId); public abstract void subscribe(Participant participant, String senderName, String sdpAnwser, Integer transactionId);

View File

@ -524,7 +524,8 @@ public class KurentoSessionManager extends SessionManager {
} }
@Override @Override
public void prepareSubscription(Participant participant, String senderPublicId, Integer transactionId) { public void prepareSubscription(Participant participant, String senderPublicId, boolean reconnect,
Integer transactionId) {
String sdpOffer = null; String sdpOffer = null;
Session session = null; Session session = null;
try { try {
@ -552,6 +553,10 @@ public class KurentoSessionManager extends SessionManager {
"User '" + senderPublicId + " not streaming media in session '" + session.getSessionId() + "'"); "User '" + senderPublicId + " not streaming media in session '" + session.getSessionId() + "'");
} }
if (reconnect) {
kParticipant.cancelReceivingMedia(((KurentoParticipant) senderParticipant), null, true);
}
sdpOffer = kParticipant.prepareReceiveMediaFrom(senderParticipant); sdpOffer = kParticipant.prepareReceiveMediaFrom(senderParticipant);
if (sdpOffer == null) { if (sdpOffer == null) {
throw new OpenViduException(Code.MEDIA_SDP_ERROR_CODE, "Unable to generate SDP offer when subscribing '" throw new OpenViduException(Code.MEDIA_SDP_ERROR_CODE, "Unable to generate SDP offer when subscribing '"
@ -1165,7 +1170,6 @@ public class KurentoSessionManager extends SessionManager {
String senderPrivateId = kSession.getParticipantPrivateIdFromStreamId(streamId); String senderPrivateId = kSession.getParticipantPrivateIdFromStreamId(streamId);
if (senderPrivateId != null) { if (senderPrivateId != null) {
KurentoParticipant sender = (KurentoParticipant) kSession.getParticipantByPrivateId(senderPrivateId); KurentoParticipant sender = (KurentoParticipant) kSession.getParticipantByPrivateId(senderPrivateId);
kParticipant.cancelReceivingMedia(sender, null, true);
kParticipant.receiveMediaFrom(sender, sdpString, true); kParticipant.receiveMediaFrom(sender, sdpString, true);
sessionEventsHandler.onSubscribe(participant, kSession, transactionId, null); sessionEventsHandler.onSubscribe(participant, kSession, transactionId, null);
} else { } else {

View File

@ -339,21 +339,22 @@ public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
private void prepareReceiveVideoFrom(RpcConnection rpcConnection, Request<JsonObject> request) { private void prepareReceiveVideoFrom(RpcConnection rpcConnection, Request<JsonObject> request) {
Participant participant; Participant participant;
try { try {
participant = sanityCheckOfSession(rpcConnection, "subscribe"); participant = sanityCheckOfSession(rpcConnection, "prepareReceiveVideFrom");
} catch (OpenViduException e) { } catch (OpenViduException e) {
return; return;
} }
String senderStreamId = getStringParam(request, ProtocolElements.RECEIVEVIDEO_SENDER_PARAM); String senderStreamId = getStringParam(request, ProtocolElements.RECEIVEVIDEO_SENDER_PARAM);
String senderPublicId = parseSenderPublicIdFromStreamId(senderStreamId); String senderPublicId = parseSenderPublicIdFromStreamId(senderStreamId);
boolean reconnect = getBooleanParam(request, ProtocolElements.PREPARERECEIVEVIDEO_RECONNECT_PARAM);
sessionManager.prepareSubscription(participant, senderPublicId, request.getId()); sessionManager.prepareSubscription(participant, senderPublicId, reconnect, request.getId());
} }
private void receiveVideoFrom(RpcConnection rpcConnection, Request<JsonObject> request) { private void receiveVideoFrom(RpcConnection rpcConnection, Request<JsonObject> request) {
Participant participant; Participant participant;
try { try {
participant = sanityCheckOfSession(rpcConnection, "subscribe"); participant = sanityCheckOfSession(rpcConnection, "receiveVideoFrom");
} catch (OpenViduException e) { } catch (OpenViduException e) {
return; return;
} }