openvidu-server: protect LocalSDP retrieval from KMS. Gathered candidates

pull/469/head
pabloFuente 2020-05-14 13:59:25 +02:00
parent f870cbdfa9
commit d58201d550
1 changed files with 27 additions and 4 deletions

View File

@ -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<IceCandidate> receivedCandidateList = new LinkedList<IceCandidate>();
private final List<IceCandidate> generatedCandidateList = new LinkedList<IceCandidate>();
private LinkedList<IceCandidate> candidates = new LinkedList<IceCandidate>();
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<IceCandidate> 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);