mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: GET sessions (?webRtcStats)
parent
492c10ea42
commit
366d616d4f
|
@ -46,5 +46,7 @@ public interface Session {
|
||||||
int getActivePublishers();
|
int getActivePublishers();
|
||||||
|
|
||||||
JSONObject toJSON();
|
JSONObject toJSON();
|
||||||
|
|
||||||
|
JSONObject withStatsToJSON();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -348,7 +348,7 @@ public class KurentoSession implements Session {
|
||||||
kurentoSessionHandler.updateFilter(this.sessionId, participant, filterId, newState);
|
kurentoSessionHandler.updateFilter(this.sessionId, participant, filterId, newState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public JSONObject toJSON() {
|
public JSONObject toJSON() {
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -502,10 +502,18 @@ 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);
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue