openvidu-server: GET /sessions simple response

pull/88/merge
pabloFuente 2018-07-04 14:58:05 +02:00
parent a0e50d1022
commit fa52c1e76a
6 changed files with 190 additions and 118 deletions

View File

@ -40,23 +40,6 @@ public class MediaOptions {
this.videoDimensions = videoDimensions; this.videoDimensions = videoDimensions;
} }
@SuppressWarnings("unchecked")
public JSONObject toJson() {
JSONObject json = new JSONObject();
json.put("hasAudio", this.hasAudio);
if (hasAudio)
json.put("audioActive", this.audioActive);
json.put("hasVideo", this.hasVideo);
if (hasVideo)
json.put("videoActive", this.videoActive);
if (this.hasVideo && this.videoActive) {
json.put("typeOfVideo", this.typeOfVideo);
json.put("frameRate", this.frameRate);
json.put("videoDimensions", this.videoDimensions);
}
return json;
}
public boolean hasAudio() { public boolean hasAudio() {
return this.hasAudio; return this.hasAudio;
} }
@ -85,4 +68,20 @@ public class MediaOptions {
return this.videoDimensions; return this.videoDimensions;
} }
@SuppressWarnings("unchecked")
public JSONObject toJSON() {
JSONObject json = new JSONObject();
json.put("hasAudio", this.hasAudio);
if (hasAudio)
json.put("audioActive", this.audioActive);
json.put("hasVideo", this.hasVideo);
if (hasVideo) {
json.put("videoActive", this.videoActive);
json.put("typeOfVideo", this.typeOfVideo);
json.put("frameRate", this.frameRate);
json.put("videoDimensions", this.videoDimensions);
}
return json;
}
} }

View File

@ -193,20 +193,21 @@ public class KurentoParticipant extends Participant {
return session; return session;
} }
public boolean isSubscribed() { public Set<SubscriberEndpoint> getAllConnectedSubscribedEndpoints() {
Set<SubscriberEndpoint> subscribedToSet = new HashSet<>();
for (SubscriberEndpoint se : subscribers.values()) { for (SubscriberEndpoint se : subscribers.values()) {
if (se.isConnectedToPublisher()) { if (se.isConnectedToPublisher()) {
return true; subscribedToSet.add(se);
} }
} }
return false; return subscribedToSet;
} }
public Set<String> getConnectedSubscribedEndpoints() { public Set<SubscriberEndpoint> getConnectedSubscribedEndpoints(PublisherEndpoint publisher) {
Set<String> subscribedToSet = new HashSet<String>(); Set<SubscriberEndpoint> subscribedToSet = new HashSet<>();
for (SubscriberEndpoint se : subscribers.values()) { for (SubscriberEndpoint se : subscribers.values()) {
if (se.isConnectedToPublisher()) { if (se.isConnectedToPublisher() && se.getPublisher().equals(publisher)) {
subscribedToSet.add(se.getEndpointName()); subscribedToSet.add(se);
} }
} }
return subscribedToSet; return subscribedToSet;
@ -431,7 +432,6 @@ public class KurentoParticipant extends Participant {
*/ */
public SubscriberEndpoint getNewOrExistingSubscriber(String senderPublicId) { public SubscriberEndpoint getNewOrExistingSubscriber(String senderPublicId) {
KurentoParticipant kSender = (KurentoParticipant) this.session.getParticipantByPublicId(senderPublicId);
SubscriberEndpoint sendingEndpoint = new SubscriberEndpoint(webParticipant, this, senderPublicId, pipeline); SubscriberEndpoint sendingEndpoint = new SubscriberEndpoint(webParticipant, this, senderPublicId, pipeline);
SubscriberEndpoint existingSendingEndpoint = this.subscribers.putIfAbsent(senderPublicId, sendingEndpoint); SubscriberEndpoint existingSendingEndpoint = this.subscribers.putIfAbsent(senderPublicId, sendingEndpoint);
@ -444,8 +444,6 @@ public class KurentoParticipant extends Participant {
senderPublicId); senderPublicId);
} }
sendingEndpoint.setMediaOptions(kSender.getPublisherMediaOptions());
return sendingEndpoint; return sendingEndpoint;
} }
@ -645,7 +643,8 @@ public class KurentoParticipant extends Participant {
+ " | MEDIATYPE: " + event.getMediaType() + " | TIMESTAMP: " + System.currentTimeMillis(); + " | MEDIATYPE: " + event.getMediaType() + " | TIMESTAMP: " + System.currentTimeMillis();
endpoint.flowInMedia.put(event.getSource().getName(), event.getMediaType()); endpoint.flowInMedia.put(event.getSource().getName(), event.getMediaType());
if (endpoint.getMediaOptions().hasAudio() && endpoint.getMediaOptions().hasVideo() if (endpoint.getPublisher().getMediaOptions().hasAudio()
&& endpoint.getPublisher().getMediaOptions().hasVideo()
&& endpoint.flowInMedia.values().size() == 2) { && endpoint.flowInMedia.values().size() == 2) {
endpoint.kmsEvents.add(new KmsEvent(event)); endpoint.kmsEvents.add(new KmsEvent(event));
} else if (endpoint.flowInMedia.values().size() == 1) { } else if (endpoint.flowInMedia.values().size() == 1) {
@ -662,7 +661,8 @@ public class KurentoParticipant extends Participant {
+ " | MEDIATYPE: " + event.getMediaType() + " | TIMESTAMP: " + System.currentTimeMillis(); + " | MEDIATYPE: " + event.getMediaType() + " | TIMESTAMP: " + System.currentTimeMillis();
endpoint.flowOutMedia.put(event.getSource().getName(), event.getMediaType()); endpoint.flowOutMedia.put(event.getSource().getName(), event.getMediaType());
if (endpoint.getMediaOptions().hasAudio() && endpoint.getMediaOptions().hasVideo() if (endpoint.getPublisher().getMediaOptions().hasAudio()
&& endpoint.getPublisher().getMediaOptions().hasVideo()
&& endpoint.flowOutMedia.values().size() == 2) { && endpoint.flowOutMedia.values().size() == 2) {
endpoint.kmsEvents.add(new KmsEvent(event)); endpoint.kmsEvents.add(new KmsEvent(event));
} else if (endpoint.flowOutMedia.values().size() == 1) { } else if (endpoint.flowOutMedia.values().size() == 1) {

View File

@ -24,6 +24,7 @@ import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
@ -43,6 +44,8 @@ import io.openvidu.java.client.SessionProperties;
import io.openvidu.server.cdr.CallDetailRecord; import io.openvidu.server.cdr.CallDetailRecord;
import io.openvidu.server.core.Participant; import io.openvidu.server.core.Participant;
import io.openvidu.server.core.Session; import io.openvidu.server.core.Session;
import io.openvidu.server.kurento.endpoint.PublisherEndpoint;
import io.openvidu.server.kurento.endpoint.SubscriberEndpoint;
/** /**
* @author Pablo Fuente (pablofuenteperez@gmail.com) * @author Pablo Fuente (pablofuenteperez@gmail.com)
@ -74,8 +77,8 @@ public class KurentoSession implements Session {
private CallDetailRecord CDR; private CallDetailRecord CDR;
public KurentoSession(String sessionId, SessionProperties sessionProperties, KurentoClient kurentoClient, KurentoSessionEventsHandler kurentoSessionHandler, public KurentoSession(String sessionId, SessionProperties sessionProperties, KurentoClient kurentoClient,
boolean destroyKurentoClient, CallDetailRecord CDR) { KurentoSessionEventsHandler kurentoSessionHandler, boolean destroyKurentoClient, CallDetailRecord CDR) {
this.sessionId = sessionId; this.sessionId = sessionId;
this.sessionProperties = sessionProperties; this.sessionProperties = sessionProperties;
this.kurentoClient = kurentoClient; this.kurentoClient = kurentoClient;
@ -100,7 +103,8 @@ public class KurentoSession implements Session {
checkClosed(); checkClosed();
createPipeline(); createPipeline();
KurentoParticipant kurentoParticipant = new KurentoParticipant(participant, this, getPipeline(), kurentoSessionHandler.getInfoHandler(), this.CDR); KurentoParticipant kurentoParticipant = new KurentoParticipant(participant, this, getPipeline(),
kurentoSessionHandler.getInfoHandler(), this.CDR);
participants.put(participant.getParticipantPrivateId(), kurentoParticipant); participants.put(participant.getParticipantPrivateId(), kurentoParticipant);
filterStates.forEach((filterId, state) -> { filterStates.forEach((filterId, state) -> {
@ -142,8 +146,8 @@ public class KurentoSession implements Session {
} }
log.debug("SESSION {}: Unsubscribed other participants {} from the publisher {}", sessionId, participants.values(), log.debug("SESSION {}: Unsubscribed other participants {} from the publisher {}", sessionId,
participant.getParticipantPublicId()); participants.values(), participant.getParticipantPublicId());
} }
@ -154,8 +158,8 @@ public class KurentoSession implements Session {
KurentoParticipant participant = participants.get(participantPrivateId); KurentoParticipant participant = participants.get(participantPrivateId);
if (participant == null) { if (participant == null) {
throw new OpenViduException(Code.USER_NOT_FOUND_ERROR_CODE, throw new OpenViduException(Code.USER_NOT_FOUND_ERROR_CODE, "Participant with private id "
"Participant with private id " + participantPrivateId + " not found in session '" + sessionId + "'"); + participantPrivateId + " not found in session '" + sessionId + "'");
} }
participant.releaseAllFilters(); participant.releaseAllFilters();
@ -194,6 +198,11 @@ public class KurentoSession implements Session {
return null; return null;
} }
public Set<SubscriberEndpoint> getAllSubscribersForPublisher(PublisherEndpoint publisher) {
return this.participants.values().stream().flatMap(kp -> kp.getConnectedSubscribedEndpoints(publisher).stream())
.collect(Collectors.toSet());
}
@Override @Override
public boolean close(String reason) { public boolean close(String reason) {
if (!closed) { if (!closed) {
@ -246,7 +255,8 @@ public class KurentoSession implements Session {
participants.remove(participant.getParticipantPrivateId()); participants.remove(participant.getParticipantPrivateId());
log.debug("SESSION {}: Cancel receiving media from participant '{}' for other participant", this.sessionId, participant.getParticipantPublicId()); log.debug("SESSION {}: Cancel receiving media from participant '{}' for other participant", this.sessionId,
participant.getParticipantPublicId());
for (KurentoParticipant other : participants.values()) { for (KurentoParticipant other : participants.values()) {
other.cancelReceivingMedia(participant.getParticipantPublicId(), reason); other.cancelReceivingMedia(participant.getParticipantPublicId(), reason);
} }
@ -357,14 +367,20 @@ public class KurentoSession implements Session {
json.put("mediaMode", this.sessionProperties.mediaMode().name()); json.put("mediaMode", this.sessionProperties.mediaMode().name());
json.put("recordingMode", this.sessionProperties.recordingMode().name()); json.put("recordingMode", this.sessionProperties.recordingMode().name());
json.put("defaultRecordingLayout", this.sessionProperties.defaultRecordingLayout().name()); json.put("defaultRecordingLayout", this.sessionProperties.defaultRecordingLayout().name());
if (this.sessionProperties.defaultCustomLayout() != null && !this.sessionProperties.defaultCustomLayout().isEmpty()) { if (this.sessionProperties.defaultCustomLayout() != null
&& !this.sessionProperties.defaultCustomLayout().isEmpty()) {
json.put("defaultCustomLayout", this.sessionProperties.defaultCustomLayout()); json.put("defaultCustomLayout", this.sessionProperties.defaultCustomLayout());
} }
JSONArray participants = new JSONArray(); JSONArray participants = new JSONArray();
this.participants.values().forEach(p -> { this.participants.values().forEach(p -> {
participants.add(p.toJSON()); participants.add(p.toJSON());
}); });
json.put("connections", participants);
JSONObject connections = new JSONObject();
connections.put("count", participants.size());
connections.put("items", participants);
json.put("connections", connections);
return json; return json;
} }
@ -376,14 +392,20 @@ public class KurentoSession implements Session {
json.put("mediaMode", this.sessionProperties.mediaMode().name()); json.put("mediaMode", this.sessionProperties.mediaMode().name());
json.put("recordingMode", this.sessionProperties.recordingMode().name()); json.put("recordingMode", this.sessionProperties.recordingMode().name());
json.put("defaultRecordingLayout", this.sessionProperties.defaultRecordingLayout().name()); json.put("defaultRecordingLayout", this.sessionProperties.defaultRecordingLayout().name());
if (this.sessionProperties.defaultCustomLayout() != null && !this.sessionProperties.defaultCustomLayout().isEmpty()) { if (this.sessionProperties.defaultCustomLayout() != null
&& !this.sessionProperties.defaultCustomLayout().isEmpty()) {
json.put("defaultCustomLayout", this.sessionProperties.defaultCustomLayout()); json.put("defaultCustomLayout", this.sessionProperties.defaultCustomLayout());
} }
JSONArray participants = new JSONArray(); JSONArray participants = new JSONArray();
this.participants.values().forEach(p -> { this.participants.values().forEach(p -> {
participants.add(p.withStatsToJSON()); participants.add(p.withStatsToJSON());
}); });
json.put("connections", participants);
JSONObject connections = new JSONObject();
connections.put("count", participants.size());
connections.put("items", participants);
json.put("connections", connections);
return json; return json;
} }

View File

@ -18,6 +18,7 @@
package io.openvidu.server.kurento.endpoint; package io.openvidu.server.kurento.endpoint;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -43,7 +44,6 @@ import org.slf4j.LoggerFactory;
import io.openvidu.client.OpenViduException; import io.openvidu.client.OpenViduException;
import io.openvidu.client.OpenViduException.Code; import io.openvidu.client.OpenViduException.Code;
import io.openvidu.server.core.MediaOptions;
import io.openvidu.server.core.Participant; import io.openvidu.server.core.Participant;
import io.openvidu.server.kurento.MutedMediaType; import io.openvidu.server.kurento.MutedMediaType;
import io.openvidu.server.kurento.core.KurentoParticipant; import io.openvidu.server.kurento.core.KurentoParticipant;
@ -70,11 +70,11 @@ 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 LinkedList<IceCandidate> candidates = new LinkedList<IceCandidate>(); private LinkedList<IceCandidate> candidates = new LinkedList<IceCandidate>();
private MutedMediaType muteType; private MutedMediaType muteType;
private MediaOptions mediaOptions;
public Map<String, MediaType> flowInMedia = new ConcurrentHashMap<>(); public Map<String, MediaType> flowInMedia = new ConcurrentHashMap<>();
public Map<String, MediaType> flowOutMedia = new ConcurrentHashMap<>(); public Map<String, MediaType> flowOutMedia = new ConcurrentHashMap<>();
@ -104,14 +104,6 @@ public abstract class MediaEndpoint {
this.setMediaPipeline(pipeline); this.setMediaPipeline(pipeline);
} }
public MediaOptions getMediaOptions() {
return mediaOptions;
}
public void setMediaOptions(MediaOptions mediaOptions) {
this.mediaOptions = mediaOptions;
}
public boolean isWeb() { public boolean isWeb() {
return web; return web;
} }
@ -490,6 +482,7 @@ public abstract class MediaEndpoint {
throw new OpenViduException(Code.MEDIA_WEBRTC_ENDPOINT_ERROR_CODE, throw new OpenViduException(Code.MEDIA_WEBRTC_ENDPOINT_ERROR_CODE,
"Can't add existing ICE candidates to null WebRtcEndpoint (ep: " + endpointName + ")"); "Can't add existing ICE candidates to null WebRtcEndpoint (ep: " + endpointName + ")");
} }
this.receivedCandidateList.add(candidate);
this.webEndpoint.addIceCandidate(candidate, new Continuation<Void>() { this.webEndpoint.addIceCandidate(candidate, new Continuation<Void>() {
@Override @Override
public void onSuccess(Void result) throws Exception { public void onSuccess(Void result) throws Exception {
@ -503,18 +496,18 @@ public abstract class MediaEndpoint {
}); });
} }
@SuppressWarnings("unchecked") public abstract PublisherEndpoint getPublisher();
public JSONObject toJSON() { public JSONObject toJSON() {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("mediaOptions", this.mediaOptions);
return json; return json;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public JSONObject withStatsToJSON() { public JSONObject withStatsToJSON() {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("mediaOptions", this.mediaOptions);
json.put("webrtcTagName", this.getEndpoint().getTag("name")); json.put("webrtcTagName", this.getEndpoint().getTag("name"));
json.put("receivedCandidates", this.receivedCandidateList);
json.put("localCandidate", this.selectedLocalIceCandidate); json.put("localCandidate", this.selectedLocalIceCandidate);
json.put("remoteCandidate", this.selectedRemoteIceCandidate); json.put("remoteCandidate", this.selectedRemoteIceCandidate);

View File

@ -23,6 +23,7 @@ import java.util.LinkedList;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import org.json.simple.JSONObject;
import org.kurento.client.Continuation; import org.kurento.client.Continuation;
import org.kurento.client.ListenerSubscription; import org.kurento.client.ListenerSubscription;
import org.kurento.client.MediaElement; import org.kurento.client.MediaElement;
@ -35,6 +36,7 @@ import org.slf4j.LoggerFactory;
import io.openvidu.client.OpenViduException; import io.openvidu.client.OpenViduException;
import io.openvidu.client.OpenViduException.Code; import io.openvidu.client.OpenViduException.Code;
import io.openvidu.server.core.MediaOptions;
import io.openvidu.server.kurento.MutedMediaType; import io.openvidu.server.kurento.MutedMediaType;
import io.openvidu.server.kurento.core.KurentoParticipant; import io.openvidu.server.kurento.core.KurentoParticipant;
@ -46,6 +48,8 @@ import io.openvidu.server.kurento.core.KurentoParticipant;
public class PublisherEndpoint extends MediaEndpoint { public class PublisherEndpoint extends MediaEndpoint {
private final static Logger log = LoggerFactory.getLogger(PublisherEndpoint.class); private final static Logger log = LoggerFactory.getLogger(PublisherEndpoint.class);
protected MediaOptions mediaOptions;
private PassThrough passThru = null; private PassThrough passThru = null;
private ListenerSubscription passThruSubscription = null; private ListenerSubscription passThruSubscription = null;
@ -462,4 +466,37 @@ public class PublisherEndpoint extends MediaEndpoint {
}); });
} }
} }
@Override
public PublisherEndpoint getPublisher() {
return this;
}
public MediaOptions getMediaOptions() {
return mediaOptions;
}
public void setMediaOptions(MediaOptions mediaOptions) {
this.mediaOptions = mediaOptions;
}
@SuppressWarnings("unchecked")
@Override
public JSONObject toJSON() {
JSONObject json = super.toJSON();
json.put("streamId", this.getEndpoint().getTag("name"));
json.put("mediaOptions", this.mediaOptions.toJSON());
return json;
}
@SuppressWarnings("unchecked")
@Override
public JSONObject withStatsToJSON() {
JSONObject json = super.withStatsToJSON();
JSONObject toJSON = this.toJSON();
for (Object key : toJSON.keySet()) {
json.put(key, toJSON.get(key));
}
return json;
}
} }

View File

@ -17,6 +17,7 @@
package io.openvidu.server.kurento.endpoint; package io.openvidu.server.kurento.endpoint;
import org.json.simple.JSONObject;
import org.kurento.client.MediaPipeline; import org.kurento.client.MediaPipeline;
import org.kurento.client.MediaType; import org.kurento.client.MediaType;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -38,8 +39,7 @@ public class SubscriberEndpoint extends MediaEndpoint {
private PublisherEndpoint publisher = null; private PublisherEndpoint publisher = null;
public SubscriberEndpoint(boolean web, KurentoParticipant owner, String endpointName, public SubscriberEndpoint(boolean web, KurentoParticipant owner, String endpointName, MediaPipeline pipeline) {
MediaPipeline pipeline) {
super(web, owner, endpointName, pipeline, log); super(web, owner, endpointName, pipeline, log);
} }
@ -61,8 +61,9 @@ public class SubscriberEndpoint extends MediaEndpoint {
this.connectedToPublisher = connectedToPublisher; this.connectedToPublisher = connectedToPublisher;
} }
@Override
public PublisherEndpoint getPublisher() { public PublisherEndpoint getPublisher() {
return publisher; return this.publisher;
} }
public void setPublisher(PublisherEndpoint publisher) { public void setPublisher(PublisherEndpoint publisher) {
@ -75,13 +76,13 @@ public class SubscriberEndpoint extends MediaEndpoint {
throw new OpenViduException(Code.MEDIA_MUTE_ERROR_CODE, "Publisher endpoint not found"); throw new OpenViduException(Code.MEDIA_MUTE_ERROR_CODE, "Publisher endpoint not found");
} }
switch (muteType) { switch (muteType) {
case ALL : case ALL:
this.publisher.disconnectFrom(this.getEndpoint()); this.publisher.disconnectFrom(this.getEndpoint());
break; break;
case AUDIO : case AUDIO:
this.publisher.disconnectFrom(this.getEndpoint(), MediaType.AUDIO); this.publisher.disconnectFrom(this.getEndpoint(), MediaType.AUDIO);
break; break;
case VIDEO : case VIDEO:
this.publisher.disconnectFrom(this.getEndpoint(), MediaType.VIDEO); this.publisher.disconnectFrom(this.getEndpoint(), MediaType.VIDEO);
break; break;
} }
@ -93,4 +94,24 @@ public class SubscriberEndpoint extends MediaEndpoint {
this.publisher.connect(this.getEndpoint()); this.publisher.connect(this.getEndpoint());
setMuteType(null); setMuteType(null);
} }
@SuppressWarnings("unchecked")
@Override
public JSONObject toJSON() {
JSONObject json = super.toJSON();
json.put("streamId", this.publisher.getEndpoint().getTag("name"));
json.put("publisher", this.publisher.getEndpointName());
return json;
}
@SuppressWarnings("unchecked")
@Override
public JSONObject withStatsToJSON() {
JSONObject json = super.withStatsToJSON();
JSONObject toJSON = this.toJSON();
for (Object key : toJSON.keySet()) {
json.put(key, toJSON.get(key));
}
return json;
}
} }