From 4ea531a379388f2d0cd9a0178756ee449df0f2ac Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Wed, 2 Sep 2020 13:25:38 +0200 Subject: [PATCH] openvidu-server: support reconnection with mediasoup --- .../io/openvidu/client/internal/ProtocolElements.java | 1 + .../main/java/io/openvidu/server/core/SessionManager.java | 2 +- .../server/kurento/core/KurentoSessionManager.java | 8 ++++++-- .../src/main/java/io/openvidu/server/rpc/RpcHandler.java | 7 ++++--- 4 files changed, 12 insertions(+), 6 deletions(-) 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 af55da6e..9658dfac 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 681941ea..e9d4a63e 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 @@ -505,7 +505,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 { @@ -533,6 +534,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 '" @@ -1118,7 +1123,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 4e742517..42f5b57a 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; }