openvidu-server: GET sessions (?webRtcStats)

pull/88/merge
pabloFuente 2018-07-03 15:54:10 +02:00
parent 492c10ea42
commit 366d616d4f
4 changed files with 39 additions and 6 deletions

View File

@ -47,4 +47,6 @@ public interface Session {
JSONObject toJSON(); JSONObject toJSON();
JSONObject withStatsToJSON();
} }

View File

@ -368,4 +368,23 @@ public class KurentoSession implements Session {
return json; 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;
}
} }

View File

@ -506,6 +506,14 @@ public abstract class MediaEndpoint {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public JSONObject toJSON() { public JSONObject toJSON() {
JSONObject json = new JSONObject(); 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("webrtcTagName", this.getEndpoint().getTag("name"));
json.put("localCandidate", this.selectedLocalIceCandidate); json.put("localCandidate", this.selectedLocalIceCandidate);
json.put("remoteCandidate", this.selectedRemoteIceCandidate); json.put("remoteCandidate", this.selectedRemoteIceCandidate);

View File

@ -32,6 +32,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import io.openvidu.client.OpenViduException; import io.openvidu.client.OpenViduException;
@ -135,10 +136,12 @@ public class SessionRestController {
} }
@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("webRtcStats") boolean webRtcStats) {
Session session = this.sessionManager.getSession(sessionId); Session session = this.sessionManager.getSession(sessionId);
if (session != null) { 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 { } else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND); return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} }
@ -146,12 +149,13 @@ public class SessionRestController {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@RequestMapping(value = "/sessions", method = RequestMethod.GET) @RequestMapping(value = "/sessions", method = RequestMethod.GET)
public ResponseEntity<JSONObject> listSessions() { public ResponseEntity<JSONObject> listSessions(@RequestParam("webRtcStats") boolean webRtcStats) {
Collection<Session> sessions = this.sessionManager.getSessionObjects(); Collection<Session> sessions = this.sessionManager.getSessionObjects();
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
JSONArray jsonArray = new JSONArray(); JSONArray jsonArray = new JSONArray();
sessions.forEach(s -> { 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("count", sessions.size());
json.put("items", jsonArray); json.put("items", jsonArray);