diff --git a/openvidu-browser/src/OpenVidu/Session.ts b/openvidu-browser/src/OpenVidu/Session.ts index 61f50bc9..a02f8c1c 100644 --- a/openvidu-browser/src/OpenVidu/Session.ts +++ b/openvidu-browser/src/OpenVidu/Session.ts @@ -99,14 +99,6 @@ export class Session extends EventDispatcher { */ remoteStreamsCreated: ObjMap = {}; - /** - * @hidden - */ - isFirstIonicIosSubscriber = true; - /** - * @hidden - */ - countDownForIonicIosSubscribersActive = true; /** * @hidden */ @@ -724,11 +716,6 @@ export class Session extends EventDispatcher { streamEvent.callDefaultBehavior(); delete this.remoteStreamsCreated[stream.streamId]; - - if (Object.keys(this.remoteStreamsCreated).length === 0) { - this.isFirstIonicIosSubscriber = true; - this.countDownForIonicIosSubscribersActive = true; - } } delete this.remoteConnections[connection.connectionId]; 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 const streamId: string = connection.stream.streamId; delete this.remoteStreamsCreated[streamId]; - - if (Object.keys(this.remoteStreamsCreated).length === 0) { - this.isFirstIonicIosSubscriber = true; - this.countDownForIonicIosSubscribersActive = true; - } - connection.removeStream(streamId); }) .catch(openViduError => { diff --git a/openvidu-browser/src/OpenVidu/Stream.ts b/openvidu-browser/src/OpenVidu/Stream.ts index 9178f3af..832a03e1 100644 --- a/openvidu-browser/src/OpenVidu/Stream.ts +++ b/openvidu-browser/src/OpenVidu/Stream.ts @@ -913,7 +913,7 @@ export class Stream extends EventDispatcher { */ initWebRtcPeerReceive(reconnect: boolean): Promise { 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) { reject(new Error('Error on prepareReceiveVideFrom: ' + JSON.stringify(error))); } else { @@ -965,26 +965,6 @@ export class Stream extends EventDispatcher { reject(new Error('Error on receiveVideFrom: ' + JSON.stringify(error))); } else { 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); - // }); } }); }; diff --git a/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts b/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts index c4141973..b36488d2 100644 --- a/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts +++ b/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts @@ -232,8 +232,7 @@ export class WebRtcPeer { if (this.pc.signalingState === 'closed') { 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, false) + this.setRemoteDescription(offer) .then(() => { resolve(); }) @@ -272,7 +271,7 @@ export class WebRtcPeer { if (this.pc.signalingState === 'closed') { reject('RTCPeerConnection is closed when trying to set remote description'); } - this.setRemoteDescription(answer, false) + this.setRemoteDescription(answer) .then(() => resolve()) .catch(error => reject(error)); }); @@ -281,22 +280,8 @@ export class WebRtcPeer { /** * @hidden */ - async setRemoteDescription(sdp: RTCSessionDescriptionInit, needsTimeoutOnProcessAnswer: boolean): Promise { - // 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); - // } + async setRemoteDescription(sdp: RTCSessionDescriptionInit): Promise { + return this.pc.setRemoteDescription(sdp); } /** diff --git a/openvidu-client/src/main/java/io/openvidu/client/internal/ProtocolElements.java b/openvidu-client/src/main/java/io/openvidu/client/internal/ProtocolElements.java index 5e4d62c9..676489d8 100644 --- a/openvidu-client/src/main/java/io/openvidu/client/internal/ProtocolElements.java +++ b/openvidu-client/src/main/java/io/openvidu/client/internal/ProtocolElements.java @@ -72,6 +72,7 @@ public class ProtocolElements { public static final String PREPARERECEIVEVIDEO_METHOD = "prepareReceiveVideFrom"; 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_SDPOFFER_PARAM = "sdpOffer"; diff --git a/openvidu-server/src/main/java/io/openvidu/server/core/SessionManager.java b/openvidu-server/src/main/java/io/openvidu/server/core/SessionManager.java index a2e0411b..a72f1166 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/core/SessionManager.java +++ b/openvidu-server/src/main/java/io/openvidu/server/core/SessionManager.java @@ -106,7 +106,7 @@ public abstract class SessionManager { public abstract void unpublishVideo(Participant participant, Participant moderator, Integer transactionId, 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); diff --git a/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoSessionManager.java b/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoSessionManager.java index e546ff5e..fb4399b7 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoSessionManager.java +++ b/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoSessionManager.java @@ -524,7 +524,8 @@ public class KurentoSessionManager extends SessionManager { } @Override - public void prepareSubscription(Participant participant, String senderPublicId, Integer transactionId) { + public void prepareSubscription(Participant participant, String senderPublicId, boolean reconnect, + Integer transactionId) { String sdpOffer = null; Session session = null; try { @@ -552,6 +553,10 @@ public class KurentoSessionManager extends SessionManager { "User '" + senderPublicId + " not streaming media in session '" + session.getSessionId() + "'"); } + if (reconnect) { + kParticipant.cancelReceivingMedia(((KurentoParticipant) senderParticipant), null, true); + } + sdpOffer = kParticipant.prepareReceiveMediaFrom(senderParticipant); if (sdpOffer == null) { 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); if (senderPrivateId != null) { KurentoParticipant sender = (KurentoParticipant) kSession.getParticipantByPrivateId(senderPrivateId); - kParticipant.cancelReceivingMedia(sender, null, true); kParticipant.receiveMediaFrom(sender, sdpString, true); sessionEventsHandler.onSubscribe(participant, kSession, transactionId, null); } else { diff --git a/openvidu-server/src/main/java/io/openvidu/server/rpc/RpcHandler.java b/openvidu-server/src/main/java/io/openvidu/server/rpc/RpcHandler.java index f9cc6f00..b38a7d66 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/rpc/RpcHandler.java +++ b/openvidu-server/src/main/java/io/openvidu/server/rpc/RpcHandler.java @@ -339,21 +339,22 @@ public class RpcHandler extends DefaultJsonRpcHandler { private void prepareReceiveVideoFrom(RpcConnection rpcConnection, Request request) { Participant participant; try { - participant = sanityCheckOfSession(rpcConnection, "subscribe"); + participant = sanityCheckOfSession(rpcConnection, "prepareReceiveVideFrom"); } catch (OpenViduException e) { return; } String senderStreamId = getStringParam(request, ProtocolElements.RECEIVEVIDEO_SENDER_PARAM); 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 request) { Participant participant; try { - participant = sanityCheckOfSession(rpcConnection, "subscribe"); + participant = sanityCheckOfSession(rpcConnection, "receiveVideoFrom"); } catch (OpenViduException e) { return; }