mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: refactor RecordingProperties generator in SessionRestController
parent
4d909d64c6
commit
e308037d8b
|
@ -325,28 +325,10 @@ public class SessionRestController {
|
||||||
}
|
}
|
||||||
|
|
||||||
String sessionId;
|
String sessionId;
|
||||||
String name;
|
|
||||||
String outputModeString;
|
|
||||||
String resolution;
|
|
||||||
Boolean hasAudio;
|
|
||||||
Boolean hasVideo;
|
|
||||||
String recordingLayoutString;
|
|
||||||
String customLayout;
|
|
||||||
Long shmSize = null;
|
|
||||||
try {
|
try {
|
||||||
sessionId = (String) params.get("session");
|
sessionId = (String) params.get("session");
|
||||||
name = (String) params.get("name");
|
} catch (Exception e) {
|
||||||
outputModeString = (String) params.get("outputMode");
|
return this.generateErrorResponse("Type error in parameter \"session\"", "/recordings/start",
|
||||||
resolution = (String) params.get("resolution");
|
|
||||||
hasAudio = (Boolean) params.get("hasAudio");
|
|
||||||
hasVideo = (Boolean) params.get("hasVideo");
|
|
||||||
recordingLayoutString = (String) params.get("recordingLayout");
|
|
||||||
customLayout = (String) params.get("customLayout");
|
|
||||||
if (params.get("shmSize") != null) {
|
|
||||||
shmSize = new Long(params.get("shmSize").toString());
|
|
||||||
}
|
|
||||||
} catch (ClassCastException | NumberFormatException e) {
|
|
||||||
return this.generateErrorResponse("Type error in some parameter", "/recordings/start",
|
|
||||||
HttpStatus.BAD_REQUEST);
|
HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,46 +338,6 @@ public class SessionRestController {
|
||||||
HttpStatus.BAD_REQUEST);
|
HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name != null && !name.isEmpty()) {
|
|
||||||
if (!sessionManager.formatChecker.isValidRecordingName(name)) {
|
|
||||||
return this.generateErrorResponse(
|
|
||||||
"Parameter 'name' is wrong. Must be an alphanumeric string [a-zA-Z0-9_-]", "/sessions",
|
|
||||||
HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
OutputMode finalOutputMode = OutputMode.COMPOSED;
|
|
||||||
RecordingLayout recordingLayout = null;
|
|
||||||
if (outputModeString != null && !outputModeString.isEmpty()) {
|
|
||||||
try {
|
|
||||||
finalOutputMode = OutputMode.valueOf(outputModeString);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return this.generateErrorResponse("Type error in parameter 'outputMode'", "/recordings/start",
|
|
||||||
HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (RecordingUtils.IS_COMPOSED(finalOutputMode)) {
|
|
||||||
if (resolution != null && !sessionManager.formatChecker.isAcceptableRecordingResolution(resolution)) {
|
|
||||||
return this.generateErrorResponse(
|
|
||||||
"Wrong 'resolution' parameter. Acceptable values from 100 to 1999 for both width and height",
|
|
||||||
"/recordings/start", HttpStatus.UNPROCESSABLE_ENTITY);
|
|
||||||
}
|
|
||||||
if (recordingLayoutString != null && !recordingLayoutString.isEmpty()) {
|
|
||||||
try {
|
|
||||||
recordingLayout = RecordingLayout.valueOf(recordingLayoutString);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return this.generateErrorResponse("Type error in parameter 'recordingLayout'", "/recordings/start",
|
|
||||||
HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ((hasAudio != null && hasVideo != null) && !hasAudio && !hasVideo) {
|
|
||||||
// Cannot start a recording with both "hasAudio" and "hasVideo" to false
|
|
||||||
return this.generateErrorResponse(
|
|
||||||
"Cannot start a recording with both \"hasAudio\" and \"hasVideo\" set to false",
|
|
||||||
"/recordings/start", HttpStatus.UNPROCESSABLE_ENTITY);
|
|
||||||
}
|
|
||||||
|
|
||||||
Session session = sessionManager.getSession(sessionId);
|
Session session = sessionManager.getSession(sessionId);
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
session = sessionManager.getSessionNotActive(sessionId);
|
session = sessionManager.getSessionNotActive(sessionId);
|
||||||
|
@ -422,41 +364,17 @@ public class SessionRestController {
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
|
return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If outputMode is COMPOSED when defaultOutputMode is COMPOSED_QUICK_START,
|
RecordingProperties recordingProperties;
|
||||||
// change outputMode to COMPOSED_QUICK_START (and vice versa)
|
try {
|
||||||
OutputMode defaultOutputMode = session.getSessionProperties().defaultOutputMode();
|
recordingProperties = getRecordingPropertiesFromParams(params, session.getSessionProperties()).build();
|
||||||
if (OutputMode.COMPOSED_QUICK_START.equals(defaultOutputMode) && OutputMode.COMPOSED.equals(finalOutputMode)) {
|
} catch (RuntimeException e) {
|
||||||
finalOutputMode = OutputMode.COMPOSED_QUICK_START;
|
return this.generateErrorResponse(e.getMessage(), "/sessions", HttpStatus.UNPROCESSABLE_ENTITY);
|
||||||
} else if (OutputMode.COMPOSED.equals(defaultOutputMode)
|
} catch (Exception e) {
|
||||||
&& OutputMode.COMPOSED_QUICK_START.equals(finalOutputMode)) {
|
return this.generateErrorResponse(e.getMessage(), "/sessions", HttpStatus.BAD_REQUEST);
|
||||||
finalOutputMode = OutputMode.COMPOSED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RecordingProperties.Builder builder = new RecordingProperties.Builder();
|
|
||||||
builder.outputMode(
|
|
||||||
finalOutputMode == null ? session.getSessionProperties().defaultOutputMode() : finalOutputMode);
|
|
||||||
if (RecordingUtils.IS_COMPOSED(finalOutputMode)) {
|
|
||||||
if (resolution != null) {
|
|
||||||
builder.resolution(resolution);
|
|
||||||
}
|
|
||||||
builder.recordingLayout(recordingLayout == null ? session.getSessionProperties().defaultRecordingLayout()
|
|
||||||
: recordingLayout);
|
|
||||||
if (RecordingLayout.CUSTOM.equals(recordingLayout)) {
|
|
||||||
builder.customLayout(
|
|
||||||
customLayout == null ? session.getSessionProperties().defaultCustomLayout() : customLayout);
|
|
||||||
}
|
|
||||||
if (shmSize != null) {
|
|
||||||
if (shmSize < 134217728L) {
|
|
||||||
return this.generateErrorResponse("Wrong \"shmSize\" parameter. Must be 134217728 (128 MB) minimum",
|
|
||||||
"/recordings/start", HttpStatus.UNPROCESSABLE_ENTITY);
|
|
||||||
}
|
|
||||||
builder.shmSize(shmSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
builder.name(name).hasAudio(hasAudio != null ? hasAudio : true).hasVideo(hasVideo != null ? hasVideo : true);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Recording startedRecording = this.recordingManager.startRecording(session, builder.build());
|
Recording startedRecording = this.recordingManager.startRecording(session, recordingProperties);
|
||||||
return new ResponseEntity<>(startedRecording.toJson().toString(), RestUtils.getResponseHeaders(),
|
return new ResponseEntity<>(startedRecording.toJson().toString(), RestUtils.getResponseHeaders(),
|
||||||
HttpStatus.OK);
|
HttpStatus.OK);
|
||||||
} catch (OpenViduException e) {
|
} catch (OpenViduException e) {
|
||||||
|
@ -973,6 +891,95 @@ public class SessionRestController {
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected RecordingProperties.Builder getRecordingPropertiesFromParams(Map<?, ?> params,
|
||||||
|
SessionProperties sessionProperties) throws Exception {
|
||||||
|
|
||||||
|
RecordingProperties.Builder builder = new RecordingProperties.Builder();
|
||||||
|
|
||||||
|
String sessionId;
|
||||||
|
String name;
|
||||||
|
String outputModeString;
|
||||||
|
String resolution;
|
||||||
|
Boolean hasAudio;
|
||||||
|
Boolean hasVideo;
|
||||||
|
String recordingLayoutString;
|
||||||
|
String customLayout;
|
||||||
|
Long shmSize = null;
|
||||||
|
try {
|
||||||
|
sessionId = (String) params.get("session");
|
||||||
|
name = (String) params.get("name");
|
||||||
|
outputModeString = (String) params.get("outputMode");
|
||||||
|
resolution = (String) params.get("resolution");
|
||||||
|
hasAudio = (Boolean) params.get("hasAudio");
|
||||||
|
hasVideo = (Boolean) params.get("hasVideo");
|
||||||
|
recordingLayoutString = (String) params.get("recordingLayout");
|
||||||
|
customLayout = (String) params.get("customLayout");
|
||||||
|
if (params.get("shmSize") != null) {
|
||||||
|
shmSize = Long.parseLong(params.get("shmSize").toString());
|
||||||
|
}
|
||||||
|
} catch (ClassCastException | NumberFormatException e) {
|
||||||
|
throw new Exception("Type error in some parameter: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sessionId == null) {
|
||||||
|
// "session" parameter not found
|
||||||
|
throw new Exception("\"session\" parameter is mandatory");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name != null && !name.isEmpty()) {
|
||||||
|
if (!sessionManager.formatChecker.isValidRecordingName(name)) {
|
||||||
|
throw new Exception("Parameter 'name' is wrong. Must be an alphanumeric string [a-zA-Z0-9_-]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
OutputMode finalOutputMode = OutputMode.COMPOSED;
|
||||||
|
RecordingLayout recordingLayout = null;
|
||||||
|
if (outputModeString != null && !outputModeString.isEmpty()) {
|
||||||
|
try {
|
||||||
|
finalOutputMode = OutputMode.valueOf(outputModeString);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new Exception("Type error in parameter 'outputMode'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (RecordingUtils.IS_COMPOSED(finalOutputMode)) {
|
||||||
|
if (resolution != null && !sessionManager.formatChecker.isAcceptableRecordingResolution(resolution)) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"Wrong 'resolution' parameter. Acceptable values from 100 to 1999 for both width and height");
|
||||||
|
}
|
||||||
|
if (recordingLayoutString != null && !recordingLayoutString.isEmpty()) {
|
||||||
|
try {
|
||||||
|
recordingLayout = RecordingLayout.valueOf(recordingLayoutString);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new Exception("Type error in parameter 'recordingLayout'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((hasAudio != null && hasVideo != null) && !hasAudio && !hasVideo) {
|
||||||
|
// Cannot start a recording with both "hasAudio" and "hasVideo" to false
|
||||||
|
throw new RuntimeException("Cannot start a recording with both \"hasAudio\" and \"hasVideo\" set to false");
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.outputMode(finalOutputMode == null ? sessionProperties.defaultOutputMode() : finalOutputMode);
|
||||||
|
if (RecordingUtils.IS_COMPOSED(finalOutputMode)) {
|
||||||
|
if (resolution != null) {
|
||||||
|
builder.resolution(resolution);
|
||||||
|
}
|
||||||
|
builder.recordingLayout(
|
||||||
|
recordingLayout == null ? sessionProperties.defaultRecordingLayout() : recordingLayout);
|
||||||
|
if (RecordingLayout.CUSTOM.equals(recordingLayout)) {
|
||||||
|
builder.customLayout(customLayout == null ? sessionProperties.defaultCustomLayout() : customLayout);
|
||||||
|
}
|
||||||
|
if (shmSize != null) {
|
||||||
|
if (shmSize < 134217728L) {
|
||||||
|
throw new RuntimeException("Wrong \"shmSize\" parameter. Must be 134217728 (128 MB) minimum");
|
||||||
|
}
|
||||||
|
builder.shmSize(shmSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
builder.name(name).hasAudio(hasAudio != null ? hasAudio : true).hasVideo(hasVideo != null ? hasVideo : true);
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
protected Token getTokenFromConnectionId(String connectionId, Iterator<Entry<String, Token>> iterator) {
|
protected Token getTokenFromConnectionId(String connectionId, Iterator<Entry<String, Token>> iterator) {
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
Token token = null;
|
Token token = null;
|
||||||
|
|
Loading…
Reference in New Issue