mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: GET sessions response updated (count, items -> numberOfElements, content)
parent
6b3e2df5a4
commit
05665f1068
|
@ -167,7 +167,10 @@ public class Participant {
|
|||
public JSONObject toJSON() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("connectionId", this.participantPublicId);
|
||||
json.put("token", this.token.toJSON());
|
||||
json.put("token", this.token.getToken());
|
||||
json.put("role", this.token.getRole().name());
|
||||
json.put("serverData", this.serverMetadata);
|
||||
json.put("clientData", this.clientMetadata);
|
||||
return json;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,13 +63,4 @@ public class Token {
|
|||
return this.token;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public JSONObject toJSON() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("token", this.token);
|
||||
json.put("role", this.role.name());
|
||||
json.put("data", this.serverMetadata);
|
||||
return json;
|
||||
}
|
||||
|
||||
}
|
|
@ -23,6 +23,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.json.simple.JSONArray;
|
||||
|
@ -693,46 +694,36 @@ public class KurentoParticipant extends Participant {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public JSONObject toJSON() {
|
||||
JSONObject json = super.toJSON();
|
||||
JSONArray publisherEnpoints = new JSONArray();
|
||||
if (this.streaming && this.publisher.getEndpoint() != null) {
|
||||
publisherEnpoints.add(this.publisher.toJSON());
|
||||
}
|
||||
JSONArray subscriberEndpoints = new JSONArray();
|
||||
for (MediaEndpoint sub : this.subscribers.values()) {
|
||||
if (sub.getEndpoint() != null) {
|
||||
subscriberEndpoints.add(sub.toJSON());
|
||||
}
|
||||
}
|
||||
json.put("publishers", publisherEnpoints);
|
||||
json.put("subscribers", subscriberEndpoints);
|
||||
return json;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public JSONObject withStatsToJSON() {
|
||||
JSONObject json = super.toJSON();
|
||||
JSONArray publisherEnpoints = new JSONArray();
|
||||
if (this.streaming && this.publisher.getEndpoint() != null) {
|
||||
publisherEnpoints.add(this.publisher.withStatsToJSON());
|
||||
}
|
||||
JSONArray subscriberEndpoints = new JSONArray();
|
||||
for (MediaEndpoint sub : this.subscribers.values()) {
|
||||
if (sub.getEndpoint() != null) {
|
||||
subscriberEndpoints.add(sub.withStatsToJSON());
|
||||
}
|
||||
}
|
||||
json.put("publishers", publisherEnpoints);
|
||||
json.put("subscribers", subscriberEndpoints);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPublisherStremId() {
|
||||
return this.publisher.getEndpoint().getTag("name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJSON() {
|
||||
return this.sharedJSON(MediaEndpoint::toJSON);
|
||||
}
|
||||
|
||||
public JSONObject withStatsToJSON() {
|
||||
return this.sharedJSON(MediaEndpoint::withStatsToJSON);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private JSONObject sharedJSON(Function<MediaEndpoint, JSONObject> toJsonFunction) {
|
||||
JSONObject json = super.toJSON();
|
||||
JSONArray publisherEnpoints = new JSONArray();
|
||||
if (this.streaming && this.publisher.getEndpoint() != null) {
|
||||
publisherEnpoints.add(toJsonFunction.apply(this.publisher));
|
||||
}
|
||||
JSONArray subscriberEndpoints = new JSONArray();
|
||||
for (MediaEndpoint sub : this.subscribers.values()) {
|
||||
if (sub.getEndpoint() != null) {
|
||||
subscriberEndpoints.add(toJsonFunction.apply(sub));
|
||||
}
|
||||
}
|
||||
json.put("publishers", publisherEnpoints);
|
||||
json.put("subscribers", subscriberEndpoints);
|
||||
return json;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
|
@ -360,52 +361,34 @@ public class KurentoSession implements Session {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public JSONObject toJSON() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("sessionId", this.sessionId);
|
||||
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()) {
|
||||
json.put("defaultCustomLayout", this.sessionProperties.defaultCustomLayout());
|
||||
}
|
||||
JSONArray participants = new JSONArray();
|
||||
this.participants.values().forEach(p -> {
|
||||
participants.add(p.toJSON());
|
||||
});
|
||||
|
||||
JSONObject connections = new JSONObject();
|
||||
connections.put("count", participants.size());
|
||||
connections.put("items", participants);
|
||||
json.put("connections", connections);
|
||||
|
||||
return json;
|
||||
return this.sharedJSON(KurentoParticipant::toJSON);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public JSONObject withStatsToJSON() {
|
||||
return this.sharedJSON(KurentoParticipant::withStatsToJSON);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private JSONObject sharedJSON(Function<KurentoParticipant, JSONObject> toJsonFunction) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("sessionId", this.sessionId);
|
||||
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()) {
|
||||
json.put("defaultCustomLayout", this.sessionProperties.defaultCustomLayout());
|
||||
}
|
||||
json.put("defaultRecordingLayout", this.sessionProperties.defaultRecordingLayout().name());
|
||||
JSONObject connections = new JSONObject();
|
||||
JSONArray participants = new JSONArray();
|
||||
this.participants.values().forEach(p -> {
|
||||
participants.add(p.withStatsToJSON());
|
||||
participants.add(toJsonFunction.apply(p));
|
||||
});
|
||||
|
||||
JSONObject connections = new JSONObject();
|
||||
connections.put("count", participants.size());
|
||||
connections.put("items", participants);
|
||||
connections.put("numberOfElements", participants.size());
|
||||
connections.put("content", participants);
|
||||
json.put("connections", connections);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
|
|
|
@ -135,12 +135,14 @@ public class SessionRestController {
|
|||
return new ResponseEntity<>(responseJson, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@RequestMapping(value = "/sessions/{sessionId}", method = RequestMethod.GET)
|
||||
public ResponseEntity<JSONObject> getSession(@PathVariable("sessionId") String sessionId,
|
||||
@RequestParam(value = "webRtcStats", defaultValue = "false", required = false) boolean webRtcStats) {
|
||||
Session session = this.sessionManager.getSession(sessionId);
|
||||
if (session != null) {
|
||||
JSONObject response = (webRtcStats == true) ? session.withStatsToJSON() : session.toJSON();
|
||||
response.put("recording", this.recordingService.sessionIsBeingRecorded(sessionId));
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
} else {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
|
@ -156,10 +158,11 @@ public class SessionRestController {
|
|||
JSONArray jsonArray = new JSONArray();
|
||||
sessions.forEach(s -> {
|
||||
JSONObject sessionJson = (webRtcStats == true) ? s.withStatsToJSON() : s.toJSON();
|
||||
sessionJson.put("recording", this.recordingService.sessionIsBeingRecorded(s.getSessionId()));
|
||||
jsonArray.add(sessionJson);
|
||||
});
|
||||
json.put("count", sessions.size());
|
||||
json.put("items", jsonArray);
|
||||
json.put("numberOfElements", sessions.size());
|
||||
json.put("content", jsonArray);
|
||||
return new ResponseEntity<>(json, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue