openvidu-server: gather all remote info from MediaEndpoint with Transaction

pull/469/head
pabloFuente 2020-05-14 17:41:22 +02:00
parent 19ff07cd9e
commit 50ab460f1d
1 changed files with 30 additions and 18 deletions

View File

@ -17,6 +17,7 @@
package io.openvidu.server.kurento.endpoint; package io.openvidu.server.kurento.endpoint;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -38,15 +39,15 @@ import org.kurento.client.MediaPipeline;
import org.kurento.client.PlayerEndpoint; import org.kurento.client.PlayerEndpoint;
import org.kurento.client.RtpEndpoint; import org.kurento.client.RtpEndpoint;
import org.kurento.client.SdpEndpoint; import org.kurento.client.SdpEndpoint;
import org.kurento.client.TFuture;
import org.kurento.client.Transaction;
import org.kurento.client.WebRtcEndpoint; import org.kurento.client.WebRtcEndpoint;
import org.kurento.client.internal.server.KurentoServerException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import io.openvidu.client.OpenViduException; import io.openvidu.client.OpenViduException;
@ -91,8 +92,8 @@ public abstract class MediaEndpoint {
private MediaPipeline pipeline = null; private MediaPipeline pipeline = null;
private ListenerSubscription endpointSubscription = null; private ListenerSubscription endpointSubscription = null;
private final List<IceCandidate> receivedCandidateList = new LinkedList<IceCandidate>(); private final List<IceCandidate> receivedCandidateList = new ArrayList<IceCandidate>();
private final List<IceCandidate> gatheredCandidateList = new LinkedList<IceCandidate>(); private final List<IceCandidate> gatheredCandidateList = new ArrayList<IceCandidate>();
private LinkedList<IceCandidate> candidates = new LinkedList<IceCandidate>(); private LinkedList<IceCandidate> candidates = new LinkedList<IceCandidate>();
public String selectedLocalIceCandidate; public String selectedLocalIceCandidate;
@ -596,30 +597,41 @@ public abstract class MediaEndpoint {
json.addProperty("webrtcEndpointName", this.getEndpointName()); json.addProperty("webrtcEndpointName", this.getEndpointName());
if (!this.isPlayerEndpoint()) { if (!this.isPlayerEndpoint()) {
try { try {
json.addProperty("remoteSdp", ((SdpEndpoint) this.getEndpoint()).getRemoteSessionDescriptor()); Transaction tx = this.getEndpoint().getMediaPipeline().beginTransaction();
} catch (KurentoServerException e) { TFuture<String> future1 = ((SdpEndpoint) this.getEndpoint()).getRemoteSessionDescriptor(tx);
log.error("Error retrieving remote SDP for endpoint {} of stream {}: {}", this.endpointName, TFuture<String> future2 = ((SdpEndpoint) this.getEndpoint()).getLocalSessionDescriptor(tx);
this.streamId, e.getMessage()); TFuture<String> future3 = this.getWebEndpoint().getExternalAddress(tx);
json.add("remoteSdp", JsonNull.INSTANCE); TFuture<String> future4 = this.getWebEndpoint().getNetworkInterfaces(tx);
} TFuture<String> future5 = this.getWebEndpoint().getStunServerAddress(tx);
try { TFuture<Integer> future6 = this.getWebEndpoint().getStunServerPort(tx);
json.addProperty("localSdp", ((SdpEndpoint) this.getEndpoint()).getLocalSessionDescriptor()); TFuture<String> future7 = this.getWebEndpoint().getTurnUrl(tx);
} catch (KurentoServerException e) { TFuture<String> future8 = this.getWebEndpoint().getId(tx);
log.error("Error retrieving local SDP for endpoint {} of stream {}: {}", this.endpointName, tx.commit();
this.streamId, e.getMessage());
json.add("localSdp", JsonNull.INSTANCE); json.addProperty("externalAddress", future3.get());
json.addProperty("networkInterfaces", future4.get());
json.addProperty("stunServerAddress", future5.get());
json.addProperty("stunServerPort", future6.get());
json.addProperty("turnUrl", future7.get());
json.addProperty("mediaObjectId", future8.get());
json.addProperty("remoteSdp", future1.get());
json.addProperty("localSdp", future2.get());
} catch (Exception e) {
log.error("Exception while getting remote information of WebRtcEndpoint {}: {} - {}", this.streamId,
e.getClass().getName(), e.getMessage());
} }
} }
Gson gson = new GsonBuilder().create(); Gson gson = new GsonBuilder().create();
JsonArray receivedCandidates = new JsonArray(); JsonArray receivedCandidates = new JsonArray();
Iterator<IceCandidate> it1 = this.receivedCandidateList.iterator(); Iterator<IceCandidate> it1 = this.receivedCandidateList.iterator();
while (it1.hasNext()) { while (it1 != null && it1.hasNext()) {
receivedCandidates.add(gson.toJsonTree(it1.next())); receivedCandidates.add(gson.toJsonTree(it1.next()));
} }
json.add("receivedCandidates", receivedCandidates); json.add("receivedCandidates", receivedCandidates);
JsonArray gatheredCandidates = new JsonArray(); JsonArray gatheredCandidates = new JsonArray();
Iterator<IceCandidate> it2 = this.gatheredCandidateList.iterator(); Iterator<IceCandidate> it2 = this.gatheredCandidateList.iterator();
while (it2.hasNext()) { while (it2 != null && it2.hasNext()) {
gatheredCandidates.add(gson.toJsonTree(it2.next())); gatheredCandidates.add(gson.toJsonTree(it2.next()));
} }
json.add("gatheredCandidates", gatheredCandidates); json.add("gatheredCandidates", gatheredCandidates);