openvidu-server: update SessionRestController#initializeConnection

pull/553/head
pabloFuente 2020-10-23 11:51:47 +02:00
parent c17265a9b0
commit cf5d1f7cdf
3 changed files with 20 additions and 14 deletions

View File

@ -56,7 +56,8 @@ public class ConnectionProperties {
* have effect: * have effect:
* <ul> * <ul>
* <li>{@link io.openvidu.java.client.ConnectionType#WEBRTC}: * <li>{@link io.openvidu.java.client.ConnectionType#WEBRTC}:
* {@link io.openvidu.java.client.ConnectionProperties.Builder#data(String) data}, * {@link io.openvidu.java.client.ConnectionProperties.Builder#data(String)
* data},
* {@link io.openvidu.java.client.ConnectionProperties.Builder#record(boolean) * {@link io.openvidu.java.client.ConnectionProperties.Builder#record(boolean)
* record}, * record},
* {@link io.openvidu.java.client.ConnectionProperties.Builder#role(OpenViduRole) * {@link io.openvidu.java.client.ConnectionProperties.Builder#role(OpenViduRole)
@ -64,7 +65,8 @@ public class ConnectionProperties {
* {@link io.openvidu.java.client.ConnectionProperties.Builder#kurentoOptions(KurentoOptions) * {@link io.openvidu.java.client.ConnectionProperties.Builder#kurentoOptions(KurentoOptions)
* kurentoOptions}</li> * kurentoOptions}</li>
* <li>{@link io.openvidu.java.client.ConnectionType#IPCAM}: * <li>{@link io.openvidu.java.client.ConnectionType#IPCAM}:
* {@link io.openvidu.java.client.ConnectionProperties.Builder#data(String) data}, * {@link io.openvidu.java.client.ConnectionProperties.Builder#data(String)
* data},
* {@link io.openvidu.java.client.ConnectionProperties.Builder#record(boolean) * {@link io.openvidu.java.client.ConnectionProperties.Builder#record(boolean)
* record}, * record},
* {@link io.openvidu.java.client.ConnectionProperties.Builder#rtspUri(String) * {@link io.openvidu.java.client.ConnectionProperties.Builder#rtspUri(String)
@ -248,8 +250,12 @@ public class ConnectionProperties {
} }
/** /**
* Whether the streams published by this Connection will be recorded or not. * <a href="https://docs.openvidu.io/en/stable/openvidu-pro/" target="_blank"
* This only affects <a href= * style="display: inline-block; background-color: rgb(0, 136, 170); color:
* white; font-weight: bold; padding: 0px 5px; margin-right: 5px; border-radius:
* 3px; font-size: 13px; line-height:21px; font-family: Montserrat,
* sans-serif">PRO</a> Whether the streams published by this Connection will be
* recorded or not. This only affects <a href=
* "https://docs.openvidu.io/en/stable/advanced-features/recording#selecting-streams-to-be-recorded" * "https://docs.openvidu.io/en/stable/advanced-features/recording#selecting-streams-to-be-recorded"
* target="_blank">INDIVIDUAL recording</a>. * target="_blank">INDIVIDUAL recording</a>.
*/ */

View File

@ -39,6 +39,8 @@ export interface ConnectionProperties {
data?: string; data?: string;
/** /**
* **This feature is part of OpenVidu Pro tier** <a href="https://docs.openvidu.io/en/stable/openvidu-pro/" target="_blank" style="display: inline-block; background-color: rgb(0, 136, 170); color: white; font-weight: bold; padding: 0px 5px; margin-right: 5px; border-radius: 3px; font-size: 13px; line-height:21px; font-family: Montserrat, sans-serif">PRO</a>
*
* Whether to record the streams published by this Connection or not. This only affects [INDIVIDUAL recording](/en/stable/advanced-features/recording#selecting-streams-to-be-recorded) * Whether to record the streams published by this Connection or not. This only affects [INDIVIDUAL recording](/en/stable/advanced-features/recording#selecting-streams-to-be-recorded)
* *
* @default true * @default true

View File

@ -284,7 +284,7 @@ public class SessionRestController {
ConnectionProperties connectionProperties; ConnectionProperties connectionProperties;
try { try {
connectionProperties = getConnectionPropertiesFromParams(params); connectionProperties = getConnectionPropertiesFromParams(params).build();
} catch (Exception e) { } catch (Exception e) {
return this.generateErrorResponse(e.getMessage(), "/sessions/" + sessionId + "/connection", return this.generateErrorResponse(e.getMessage(), "/sessions/" + sessionId + "/connection",
HttpStatus.BAD_REQUEST); HttpStatus.BAD_REQUEST);
@ -660,7 +660,7 @@ public class SessionRestController {
ConnectionProperties connectionProperties; ConnectionProperties connectionProperties;
params.remove("record"); params.remove("record");
try { try {
connectionProperties = getConnectionPropertiesFromParams(params); connectionProperties = getConnectionPropertiesFromParams(params).build();
} catch (Exception e) { } catch (Exception e) {
return this.generateErrorResponse(e.getMessage(), "/sessions/" + sessionId + "/connection", return this.generateErrorResponse(e.getMessage(), "/sessions/" + sessionId + "/connection",
HttpStatus.BAD_REQUEST); HttpStatus.BAD_REQUEST);
@ -787,8 +787,9 @@ public class SessionRestController {
// While closing a session tokens can't be generated // While closing a session tokens can't be generated
if (session.closingLock.readLock().tryLock()) { if (session.closingLock.readLock().tryLock()) {
try { try {
Token token = sessionManager.newToken(session, connectionProperties.getRole(), connectionProperties.getData(), Token token = sessionManager.newToken(session, connectionProperties.getRole(),
connectionProperties.record(), connectionProperties.getKurentoOptions()); connectionProperties.getData(), connectionProperties.record(),
connectionProperties.getKurentoOptions());
return new ResponseEntity<>(token.toJsonAsParticipant().toString(), RestUtils.getResponseHeaders(), return new ResponseEntity<>(token.toJsonAsParticipant().toString(), RestUtils.getResponseHeaders(),
HttpStatus.OK); HttpStatus.OK);
} catch (Exception e) { } catch (Exception e) {
@ -858,17 +859,15 @@ public class SessionRestController {
return token; return token;
} }
protected ConnectionProperties getConnectionPropertiesFromParams(Map<?, ?> params) throws Exception { protected ConnectionProperties.Builder getConnectionPropertiesFromParams(Map<?, ?> params) throws Exception {
ConnectionProperties.Builder builder = new ConnectionProperties.Builder(); ConnectionProperties.Builder builder = new ConnectionProperties.Builder();
String typeString; String typeString;
String data; String data;
Boolean record;
try { try {
typeString = (String) params.get("type"); typeString = (String) params.get("type");
data = (String) params.get("data"); data = (String) params.get("data");
record = (Boolean) params.get("record");
} catch (ClassCastException e) { } catch (ClassCastException e) {
throw new Exception("Type error in some parameter: " + e.getMessage()); throw new Exception("Type error in some parameter: " + e.getMessage());
} }
@ -884,10 +883,9 @@ public class SessionRestController {
throw new Exception("Parameter 'type' " + typeString + " is not defined"); throw new Exception("Parameter 'type' " + typeString + " is not defined");
} }
data = data != null ? data : ""; data = data != null ? data : "";
record = record != null ? record : true;
// Build COMMON options // Build COMMON options
builder.type(type).data(data).record(record); builder.type(type).data(data).record(true);
OpenViduRole role = null; OpenViduRole role = null;
KurentoOptions kurentoOptions = null; KurentoOptions kurentoOptions = null;
@ -974,7 +972,7 @@ public class SessionRestController {
.onlyPlayWithSubscribers(onlyPlayWithSubscribers).networkCache(networkCache).build(); .onlyPlayWithSubscribers(onlyPlayWithSubscribers).networkCache(networkCache).build();
} }
return builder.build(); return builder;
} }
protected ResponseEntity<String> generateErrorResponse(String errorMessage, String path, HttpStatus status) { protected ResponseEntity<String> generateErrorResponse(String errorMessage, String path, HttpStatus status) {