mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: GET /sessions simple response
parent
a0e50d1022
commit
fa52c1e76a
|
@ -40,23 +40,6 @@ public class MediaOptions {
|
|||
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() {
|
||||
return this.hasAudio;
|
||||
}
|
||||
|
@ -85,4 +68,20 @@ public class MediaOptions {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -193,20 +193,21 @@ public class KurentoParticipant extends Participant {
|
|||
return session;
|
||||
}
|
||||
|
||||
public boolean isSubscribed() {
|
||||
public Set<SubscriberEndpoint> getAllConnectedSubscribedEndpoints() {
|
||||
Set<SubscriberEndpoint> subscribedToSet = new HashSet<>();
|
||||
for (SubscriberEndpoint se : subscribers.values()) {
|
||||
if (se.isConnectedToPublisher()) {
|
||||
return true;
|
||||
subscribedToSet.add(se);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return subscribedToSet;
|
||||
}
|
||||
|
||||
public Set<String> getConnectedSubscribedEndpoints() {
|
||||
Set<String> subscribedToSet = new HashSet<String>();
|
||||
public Set<SubscriberEndpoint> getConnectedSubscribedEndpoints(PublisherEndpoint publisher) {
|
||||
Set<SubscriberEndpoint> subscribedToSet = new HashSet<>();
|
||||
for (SubscriberEndpoint se : subscribers.values()) {
|
||||
if (se.isConnectedToPublisher()) {
|
||||
subscribedToSet.add(se.getEndpointName());
|
||||
if (se.isConnectedToPublisher() && se.getPublisher().equals(publisher)) {
|
||||
subscribedToSet.add(se);
|
||||
}
|
||||
}
|
||||
return subscribedToSet;
|
||||
|
@ -431,7 +432,6 @@ public class KurentoParticipant extends Participant {
|
|||
*/
|
||||
public SubscriberEndpoint getNewOrExistingSubscriber(String senderPublicId) {
|
||||
|
||||
KurentoParticipant kSender = (KurentoParticipant) this.session.getParticipantByPublicId(senderPublicId);
|
||||
SubscriberEndpoint sendingEndpoint = new SubscriberEndpoint(webParticipant, this, senderPublicId, pipeline);
|
||||
|
||||
SubscriberEndpoint existingSendingEndpoint = this.subscribers.putIfAbsent(senderPublicId, sendingEndpoint);
|
||||
|
@ -444,8 +444,6 @@ public class KurentoParticipant extends Participant {
|
|||
senderPublicId);
|
||||
}
|
||||
|
||||
sendingEndpoint.setMediaOptions(kSender.getPublisherMediaOptions());
|
||||
|
||||
return sendingEndpoint;
|
||||
}
|
||||
|
||||
|
@ -645,7 +643,8 @@ public class KurentoParticipant extends Participant {
|
|||
+ " | MEDIATYPE: " + event.getMediaType() + " | TIMESTAMP: " + System.currentTimeMillis();
|
||||
|
||||
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.kmsEvents.add(new KmsEvent(event));
|
||||
} else if (endpoint.flowInMedia.values().size() == 1) {
|
||||
|
@ -662,7 +661,8 @@ public class KurentoParticipant extends Participant {
|
|||
+ " | MEDIATYPE: " + event.getMediaType() + " | TIMESTAMP: " + System.currentTimeMillis();
|
||||
|
||||
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.kmsEvents.add(new KmsEvent(event));
|
||||
} else if (endpoint.flowOutMedia.values().size() == 1) {
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.concurrent.ConcurrentMap;
|
|||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
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.core.Participant;
|
||||
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)
|
||||
|
@ -74,8 +77,8 @@ public class KurentoSession implements Session {
|
|||
|
||||
private CallDetailRecord CDR;
|
||||
|
||||
public KurentoSession(String sessionId, SessionProperties sessionProperties, KurentoClient kurentoClient, KurentoSessionEventsHandler kurentoSessionHandler,
|
||||
boolean destroyKurentoClient, CallDetailRecord CDR) {
|
||||
public KurentoSession(String sessionId, SessionProperties sessionProperties, KurentoClient kurentoClient,
|
||||
KurentoSessionEventsHandler kurentoSessionHandler, boolean destroyKurentoClient, CallDetailRecord CDR) {
|
||||
this.sessionId = sessionId;
|
||||
this.sessionProperties = sessionProperties;
|
||||
this.kurentoClient = kurentoClient;
|
||||
|
@ -100,7 +103,8 @@ public class KurentoSession implements Session {
|
|||
checkClosed();
|
||||
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);
|
||||
|
||||
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(),
|
||||
participant.getParticipantPublicId());
|
||||
log.debug("SESSION {}: Unsubscribed other participants {} from the publisher {}", sessionId,
|
||||
participants.values(), participant.getParticipantPublicId());
|
||||
|
||||
}
|
||||
|
||||
|
@ -154,8 +158,8 @@ public class KurentoSession implements Session {
|
|||
|
||||
KurentoParticipant participant = participants.get(participantPrivateId);
|
||||
if (participant == null) {
|
||||
throw new OpenViduException(Code.USER_NOT_FOUND_ERROR_CODE,
|
||||
"Participant with private id " + participantPrivateId + " not found in session '" + sessionId + "'");
|
||||
throw new OpenViduException(Code.USER_NOT_FOUND_ERROR_CODE, "Participant with private id "
|
||||
+ participantPrivateId + " not found in session '" + sessionId + "'");
|
||||
}
|
||||
participant.releaseAllFilters();
|
||||
|
||||
|
@ -194,6 +198,11 @@ public class KurentoSession implements Session {
|
|||
return null;
|
||||
}
|
||||
|
||||
public Set<SubscriberEndpoint> getAllSubscribersForPublisher(PublisherEndpoint publisher) {
|
||||
return this.participants.values().stream().flatMap(kp -> kp.getConnectedSubscribedEndpoints(publisher).stream())
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean close(String reason) {
|
||||
if (!closed) {
|
||||
|
@ -246,7 +255,8 @@ public class KurentoSession implements Session {
|
|||
|
||||
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()) {
|
||||
other.cancelReceivingMedia(participant.getParticipantPublicId(), reason);
|
||||
}
|
||||
|
@ -357,14 +367,20 @@ public class KurentoSession implements Session {
|
|||
json.put("mediaMode", this.sessionProperties.mediaMode().name());
|
||||
json.put("recordingMode", this.sessionProperties.recordingMode().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());
|
||||
}
|
||||
JSONArray participants = new JSONArray();
|
||||
this.participants.values().forEach(p -> {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -376,14 +392,20 @@ public class KurentoSession implements Session {
|
|||
json.put("mediaMode", this.sessionProperties.mediaMode().name());
|
||||
json.put("recordingMode", this.sessionProperties.recordingMode().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());
|
||||
}
|
||||
JSONArray participants = new JSONArray();
|
||||
this.participants.values().forEach(p -> {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package io.openvidu.server.kurento.endpoint;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
@ -43,7 +44,6 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import io.openvidu.client.OpenViduException;
|
||||
import io.openvidu.client.OpenViduException.Code;
|
||||
import io.openvidu.server.core.MediaOptions;
|
||||
import io.openvidu.server.core.Participant;
|
||||
import io.openvidu.server.kurento.MutedMediaType;
|
||||
import io.openvidu.server.kurento.core.KurentoParticipant;
|
||||
|
@ -70,11 +70,11 @@ public abstract class MediaEndpoint {
|
|||
private MediaPipeline pipeline = null;
|
||||
private ListenerSubscription endpointSubscription = null;
|
||||
|
||||
private final List<IceCandidate> receivedCandidateList = new LinkedList<IceCandidate>();
|
||||
private LinkedList<IceCandidate> candidates = new LinkedList<IceCandidate>();
|
||||
|
||||
private MutedMediaType muteType;
|
||||
|
||||
private MediaOptions mediaOptions;
|
||||
public Map<String, MediaType> flowInMedia = new ConcurrentHashMap<>();
|
||||
public Map<String, MediaType> flowOutMedia = new ConcurrentHashMap<>();
|
||||
|
||||
|
@ -104,14 +104,6 @@ public abstract class MediaEndpoint {
|
|||
this.setMediaPipeline(pipeline);
|
||||
}
|
||||
|
||||
public MediaOptions getMediaOptions() {
|
||||
return mediaOptions;
|
||||
}
|
||||
|
||||
public void setMediaOptions(MediaOptions mediaOptions) {
|
||||
this.mediaOptions = mediaOptions;
|
||||
}
|
||||
|
||||
public boolean isWeb() {
|
||||
return web;
|
||||
}
|
||||
|
@ -490,6 +482,7 @@ public abstract class MediaEndpoint {
|
|||
throw new OpenViduException(Code.MEDIA_WEBRTC_ENDPOINT_ERROR_CODE,
|
||||
"Can't add existing ICE candidates to null WebRtcEndpoint (ep: " + endpointName + ")");
|
||||
}
|
||||
this.receivedCandidateList.add(candidate);
|
||||
this.webEndpoint.addIceCandidate(candidate, new Continuation<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void result) throws Exception {
|
||||
|
@ -503,18 +496,18 @@ public abstract class MediaEndpoint {
|
|||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public abstract PublisherEndpoint getPublisher();
|
||||
|
||||
public JSONObject toJSON() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("mediaOptions", this.mediaOptions);
|
||||
return json;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public JSONObject withStatsToJSON() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("mediaOptions", this.mediaOptions);
|
||||
json.put("webrtcTagName", this.getEndpoint().getTag("name"));
|
||||
json.put("receivedCandidates", this.receivedCandidateList);
|
||||
json.put("localCandidate", this.selectedLocalIceCandidate);
|
||||
json.put("remoteCandidate", this.selectedRemoteIceCandidate);
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.LinkedList;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.kurento.client.Continuation;
|
||||
import org.kurento.client.ListenerSubscription;
|
||||
import org.kurento.client.MediaElement;
|
||||
|
@ -35,6 +36,7 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import io.openvidu.client.OpenViduException;
|
||||
import io.openvidu.client.OpenViduException.Code;
|
||||
import io.openvidu.server.core.MediaOptions;
|
||||
import io.openvidu.server.kurento.MutedMediaType;
|
||||
import io.openvidu.server.kurento.core.KurentoParticipant;
|
||||
|
||||
|
@ -46,6 +48,8 @@ import io.openvidu.server.kurento.core.KurentoParticipant;
|
|||
public class PublisherEndpoint extends MediaEndpoint {
|
||||
private final static Logger log = LoggerFactory.getLogger(PublisherEndpoint.class);
|
||||
|
||||
protected MediaOptions mediaOptions;
|
||||
|
||||
private PassThrough passThru = 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package io.openvidu.server.kurento.endpoint;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.kurento.client.MediaPipeline;
|
||||
import org.kurento.client.MediaType;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -38,8 +39,7 @@ public class SubscriberEndpoint extends MediaEndpoint {
|
|||
|
||||
private PublisherEndpoint publisher = null;
|
||||
|
||||
public SubscriberEndpoint(boolean web, KurentoParticipant owner, String endpointName,
|
||||
MediaPipeline pipeline) {
|
||||
public SubscriberEndpoint(boolean web, KurentoParticipant owner, String endpointName, MediaPipeline pipeline) {
|
||||
super(web, owner, endpointName, pipeline, log);
|
||||
}
|
||||
|
||||
|
@ -61,8 +61,9 @@ public class SubscriberEndpoint extends MediaEndpoint {
|
|||
this.connectedToPublisher = connectedToPublisher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PublisherEndpoint getPublisher() {
|
||||
return publisher;
|
||||
return this.publisher;
|
||||
}
|
||||
|
||||
public void setPublisher(PublisherEndpoint publisher) {
|
||||
|
@ -93,4 +94,24 @@ public class SubscriberEndpoint extends MediaEndpoint {
|
|||
this.publisher.connect(this.getEndpoint());
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue