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() {
|
public JSONObject toJSON() {
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put("connectionId", this.participantPublicId);
|
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;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,14 +62,5 @@ public class Token {
|
||||||
else
|
else
|
||||||
return this.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.ConcurrentMap;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
import org.json.simple.JSONArray;
|
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
|
@Override
|
||||||
public String getPublisherStremId() {
|
public String getPublisherStremId() {
|
||||||
return this.publisher.getEndpoint().getTag("name");
|
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.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.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
|
@ -360,52 +361,34 @@ public class KurentoSession implements Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public JSONObject toJSON() {
|
public JSONObject toJSON() {
|
||||||
JSONObject json = new JSONObject();
|
return this.sharedJSON(KurentoParticipant::toJSON);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public JSONObject withStatsToJSON() {
|
public JSONObject withStatsToJSON() {
|
||||||
|
return this.sharedJSON(KurentoParticipant::withStatsToJSON);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private JSONObject sharedJSON(Function<KurentoParticipant, JSONObject> toJsonFunction) {
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put("sessionId", this.sessionId);
|
json.put("sessionId", this.sessionId);
|
||||||
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());
|
|
||||||
if (this.sessionProperties.defaultCustomLayout() != null
|
if (this.sessionProperties.defaultCustomLayout() != null
|
||||||
&& !this.sessionProperties.defaultCustomLayout().isEmpty()) {
|
&& !this.sessionProperties.defaultCustomLayout().isEmpty()) {
|
||||||
json.put("defaultCustomLayout", this.sessionProperties.defaultCustomLayout());
|
json.put("defaultCustomLayout", this.sessionProperties.defaultCustomLayout());
|
||||||
}
|
}
|
||||||
|
json.put("defaultRecordingLayout", this.sessionProperties.defaultRecordingLayout().name());
|
||||||
|
JSONObject connections = new JSONObject();
|
||||||
JSONArray participants = new JSONArray();
|
JSONArray participants = new JSONArray();
|
||||||
this.participants.values().forEach(p -> {
|
this.participants.values().forEach(p -> {
|
||||||
participants.add(p.withStatsToJSON());
|
participants.add(toJsonFunction.apply(p));
|
||||||
});
|
});
|
||||||
|
connections.put("numberOfElements", participants.size());
|
||||||
JSONObject connections = new JSONObject();
|
connections.put("content", participants);
|
||||||
connections.put("count", participants.size());
|
|
||||||
connections.put("items", participants);
|
|
||||||
json.put("connections", connections);
|
json.put("connections", connections);
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,12 +135,14 @@ public class SessionRestController {
|
||||||
return new ResponseEntity<>(responseJson, HttpStatus.OK);
|
return new ResponseEntity<>(responseJson, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@RequestMapping(value = "/sessions/{sessionId}", method = RequestMethod.GET)
|
@RequestMapping(value = "/sessions/{sessionId}", method = RequestMethod.GET)
|
||||||
public ResponseEntity<JSONObject> getSession(@PathVariable("sessionId") String sessionId,
|
public ResponseEntity<JSONObject> getSession(@PathVariable("sessionId") String sessionId,
|
||||||
@RequestParam(value = "webRtcStats", defaultValue = "false", required = false) boolean webRtcStats) {
|
@RequestParam(value = "webRtcStats", defaultValue = "false", required = false) boolean webRtcStats) {
|
||||||
Session session = this.sessionManager.getSession(sessionId);
|
Session session = this.sessionManager.getSession(sessionId);
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
JSONObject response = (webRtcStats == true) ? session.withStatsToJSON() : session.toJSON();
|
JSONObject response = (webRtcStats == true) ? session.withStatsToJSON() : session.toJSON();
|
||||||
|
response.put("recording", this.recordingService.sessionIsBeingRecorded(sessionId));
|
||||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||||
} else {
|
} else {
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
@ -156,10 +158,11 @@ public class SessionRestController {
|
||||||
JSONArray jsonArray = new JSONArray();
|
JSONArray jsonArray = new JSONArray();
|
||||||
sessions.forEach(s -> {
|
sessions.forEach(s -> {
|
||||||
JSONObject sessionJson = (webRtcStats == true) ? s.withStatsToJSON() : s.toJSON();
|
JSONObject sessionJson = (webRtcStats == true) ? s.withStatsToJSON() : s.toJSON();
|
||||||
|
sessionJson.put("recording", this.recordingService.sessionIsBeingRecorded(s.getSessionId()));
|
||||||
jsonArray.add(sessionJson);
|
jsonArray.add(sessionJson);
|
||||||
});
|
});
|
||||||
json.put("count", sessions.size());
|
json.put("numberOfElements", sessions.size());
|
||||||
json.put("items", jsonArray);
|
json.put("content", jsonArray);
|
||||||
return new ResponseEntity<>(json, HttpStatus.OK);
|
return new ResponseEntity<>(json, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue