mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: GET sessions (?webRtcStats)
parent
492c10ea42
commit
366d616d4f
|
@ -47,4 +47,6 @@ public interface Session {
|
|||
|
||||
JSONObject toJSON();
|
||||
|
||||
JSONObject withStatsToJSON();
|
||||
|
||||
}
|
||||
|
|
|
@ -368,4 +368,23 @@ public class KurentoSession implements Session {
|
|||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public JSONObject withStatsToJSON() {
|
||||
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.withStatsToJSON());
|
||||
});
|
||||
json.put("connections", participants);
|
||||
return json;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -506,6 +506,14 @@ public abstract class MediaEndpoint {
|
|||
@SuppressWarnings("unchecked")
|
||||
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("localCandidate", this.selectedLocalIceCandidate);
|
||||
json.put("remoteCandidate", this.selectedRemoteIceCandidate);
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.openvidu.client.OpenViduException;
|
||||
|
@ -135,10 +136,12 @@ public class SessionRestController {
|
|||
}
|
||||
|
||||
@RequestMapping(value = "/sessions/{sessionId}", method = RequestMethod.GET)
|
||||
public ResponseEntity<JSONObject> getSession(@PathVariable("sessionId") String sessionId) {
|
||||
public ResponseEntity<JSONObject> getSession(@PathVariable("sessionId") String sessionId,
|
||||
@RequestParam("webRtcStats") boolean webRtcStats) {
|
||||
Session session = this.sessionManager.getSession(sessionId);
|
||||
if (session != null) {
|
||||
return new ResponseEntity<>(session.toJSON(), HttpStatus.OK);
|
||||
JSONObject response = (webRtcStats == true) ? session.withStatsToJSON() : session.toJSON();
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
} else {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
@ -146,12 +149,13 @@ public class SessionRestController {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@RequestMapping(value = "/sessions", method = RequestMethod.GET)
|
||||
public ResponseEntity<JSONObject> listSessions() {
|
||||
public ResponseEntity<JSONObject> listSessions(@RequestParam("webRtcStats") boolean webRtcStats) {
|
||||
Collection<Session> sessions = this.sessionManager.getSessionObjects();
|
||||
JSONObject json = new JSONObject();
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
sessions.forEach(s -> {
|
||||
jsonArray.add(s.toJSON());
|
||||
JSONObject sessionJson = (webRtcStats == true) ? s.withStatsToJSON() : s.toJSON();
|
||||
jsonArray.add(sessionJson);
|
||||
});
|
||||
json.put("count", sessions.size());
|
||||
json.put("items", jsonArray);
|
||||
|
|
Loading…
Reference in New Issue