diff --git a/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/MediaEndpoint.java b/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/MediaEndpoint.java index 919237c2..ebf25cb6 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/MediaEndpoint.java +++ b/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/MediaEndpoint.java @@ -17,6 +17,7 @@ package io.openvidu.server.kurento.endpoint; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Queue; @@ -42,6 +43,7 @@ import org.kurento.client.internal.server.KurentoServerException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonNull; @@ -90,6 +92,7 @@ public abstract class MediaEndpoint { private ListenerSubscription endpointSubscription = null; private final List receivedCandidateList = new LinkedList(); + private final List generatedCandidateList = new LinkedList(); private LinkedList candidates = new LinkedList(); public String selectedLocalIceCandidate; @@ -529,8 +532,10 @@ public abstract class MediaEndpoint { throw new OpenViduException(Code.MEDIA_WEBRTC_ENDPOINT_ERROR_CODE, "Can't register event listener for null WebRtcEndpoint (ep: " + endpointName + ")"); } - webEndpoint.addOnIceCandidateListener(event -> { - owner.sendIceCandidate(senderPublicId, endpointName, event.getCandidate()); + webEndpoint.addIceCandidateFoundListener(event -> { + final IceCandidate candidate = event.getCandidate(); + generatedCandidateList.add(candidate); + owner.sendIceCandidate(senderPublicId, endpointName, candidate); }); } @@ -597,9 +602,27 @@ public abstract class MediaEndpoint { this.streamId, e.getMessage()); json.add("remoteSdp", JsonNull.INSTANCE); } - json.addProperty("localSdp", ((SdpEndpoint) this.getEndpoint()).getLocalSessionDescriptor()); + try { + json.addProperty("localSdp", ((SdpEndpoint) this.getEndpoint()).getLocalSessionDescriptor()); + } catch (KurentoServerException e) { + log.error("Error retrieving local SDP for endpoint {} of stream {}: {}", this.endpointName, + this.streamId, e.getMessage()); + json.add("localSdp", JsonNull.INSTANCE); + } } - json.add("receivedCandidates", new GsonBuilder().create().toJsonTree(this.receivedCandidateList)); + Gson gson = new GsonBuilder().create(); + JsonArray receivedCandidates = new JsonArray(); + Iterator it = this.receivedCandidateList.iterator(); + while (it.hasNext()) { + receivedCandidates.add(gson.toJsonTree(it.next())); + } + json.add("receivedCandidates", receivedCandidates); + JsonArray generatedCandidates = new JsonArray(); + it = this.receivedCandidateList.iterator(); + while (it.hasNext()) { + generatedCandidates.add(gson.toJsonTree(it.next())); + } + json.add("generatedCandidates", generatedCandidates); json.addProperty("localCandidate", this.selectedLocalIceCandidate); json.addProperty("remoteCandidate", this.selectedRemoteIceCandidate);