diff --git a/openvidu-java-client/src/main/java/io/openvidu/java/client/ConnectionProperties.java b/openvidu-java-client/src/main/java/io/openvidu/java/client/ConnectionProperties.java index 769b2965..6799f3f6 100644 --- a/openvidu-java-client/src/main/java/io/openvidu/java/client/ConnectionProperties.java +++ b/openvidu-java-client/src/main/java/io/openvidu/java/client/ConnectionProperties.java @@ -4,6 +4,7 @@ import java.net.MalformedURLException; import java.net.URI; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -20,6 +21,19 @@ import com.google.gson.JsonObject; */ public class ConnectionProperties { + public static class DefaultValues { + public static final ConnectionType type = ConnectionType.WEBRTC; + public static final String data = ""; + public static final Boolean record = true; + public static final OpenViduRole role = OpenViduRole.PUBLISHER; + public static final KurentoOptions kurentoOptions = null; + public static final String rtspUri = null; + public static final Boolean adaptativeBitrate = true; + public static final Boolean onlyPlayWithSubscribers = true; + public static final Integer networkCache = 2000; + public static final List customIceServers = null; + } + private ConnectionType type; // COMMON private String data; @@ -57,7 +71,6 @@ public class ConnectionProperties { private Boolean onlyPlayWithSubscribers; private Integer networkCache; - /** * Builder for {@link io.openvidu.java.client.ConnectionProperties}. */ @@ -132,10 +145,9 @@ public class ConnectionProperties { /** * Call this method to flag the streams published by this Connection to be - * recorded or not. This only affects - * - * INDIVIDUAL recording - * . If not set, by default will be true. + * recorded or not. This only affects + * INDIVIDUAL recording . If not set, by default will be true. */ public Builder record(boolean record) { this.record = record; @@ -242,28 +254,34 @@ public class ConnectionProperties { } /** - * On certain type of networks, clients using default OpenVidu STUN/TURN server can not be reached it because - * firewall rules and network topologies at the client side. This method allows you to configure your - * own ICE Server for specific connections if you need it. This is usually not necessary, only it is usefull for - * OpenVidu users behind firewalls which allows traffic from/to specific ports which may need a custom - * ICE Server configuration + * On certain type of networks, clients using default OpenVidu STUN/TURN server + * can not be reached it because firewall rules and network topologies at the + * client side. This method allows you to configure your own ICE Server for + * specific connections if you need it. This is usually not necessary, only it + * is usefull for OpenVidu users behind firewalls which allows traffic from/to + * specific ports which may need a custom ICE Server configuration * - * Add an ICE Server if in your use case you need this connection to use your own ICE Server deployment. - * When the user uses this connection, it will use the specified ICE Servers defined here. + * Add an ICE Server if in your use case you need this connection to use your + * own ICE Server deployment. When the user uses this connection, it will use + * the specified ICE Servers defined here. * - * The level of precedence for ICE Server configuration on every OpenVidu connection is: - *
    - *
  1. Configured ICE Server using Openvidu.setAdvancedCofiguration() at openvidu-browser.
  2. + * The level of precedence for ICE Server configuration on every OpenVidu + * connection is: + *
      + *
    1. Configured ICE Server using Openvidu.setAdvancedCofiguration() at + * openvidu-browser.
    2. *
    3. Configured ICE server at - * {@link io.openvidu.java.client.ConnectionProperties#customIceServers ConnectionProperties.customIceServers}
    4. - *
    5. Configured ICE Server at global configuration parameter: OPENVIDU_WEBRTC_ICE_SERVERS
    6. + * {@link io.openvidu.java.client.ConnectionProperties#customIceServers + * ConnectionProperties.customIceServers} + *
    7. Configured ICE Server at global configuration parameter: + * OPENVIDU_WEBRTC_ICE_SERVERS
    8. *
    9. Default deployed Coturn within OpenVidu deployment
    10. *
    *
    - * If no value is found at level 1, level 2 will be used, and so on until level 4. + * If no value is found at level 1, level 2 will be used, and so on until level + * 4.
    + * This method is equivalent to level 2 of precedence.
    *
    - * This method is equivalent to level 2 of precedence. - *

    * Only for * {@link io.openvidu.java.client.ConnectionType#WEBRTC} */ @@ -303,15 +321,14 @@ public class ConnectionProperties { } /** - * PRO Whether the streams published by this Connection will be - * recorded or not. This only affects - * - * INDIVIDUAL recording - * . + * PRO Whether + * the streams published by this Connection will be recorded or not. This only + * affects + * INDIVIDUAL recording . */ public Boolean record() { return this.record; @@ -401,11 +418,12 @@ public class ConnectionProperties { } /** - * Returns a list of custom ICE Servers configured for this connection. - *

    - * See {@link io.openvidu.java.client.ConnectionProperties.Builder#addCustomIceServer(IceServerProperties)} for more - * information. - *

    + * Returns a list of custom ICE Servers configured for this connection.
    + *
    + * See + * {@link io.openvidu.java.client.ConnectionProperties.Builder#addCustomIceServer(IceServerProperties)} + * for more information.
    + *
    * Only for * {@link io.openvidu.java.client.ConnectionType#WEBRTC} */ @@ -485,6 +503,10 @@ public class ConnectionProperties { ConnectionProperties.Builder builder = new ConnectionProperties.Builder(); + if (params == null) { + params = new HashMap<>(); + } + String typeString; String data; try { @@ -499,12 +521,12 @@ public class ConnectionProperties { if (typeString != null) { type = ConnectionType.valueOf(typeString); } else { - type = ConnectionType.WEBRTC; + type = DefaultValues.type; } } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Parameter 'type' " + typeString + " is not defined"); } - data = data != null ? data : ""; + data = data != null ? data : DefaultValues.data; // Build COMMON options builder.type(type).data(data).record(true); @@ -523,7 +545,7 @@ public class ConnectionProperties { if (roleString != null) { role = OpenViduRole.valueOf(roleString); } else { - role = OpenViduRole.PUBLISHER; + role = DefaultValues.role; } } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Parameter role " + params.get("role") + " is not defined"); @@ -623,9 +645,10 @@ public class ConnectionProperties { } catch (ClassCastException e) { throw new IllegalArgumentException("Type error in some parameter: " + e.getMessage()); } - adaptativeBitrate = adaptativeBitrate != null ? adaptativeBitrate : true; - onlyPlayWithSubscribers = onlyPlayWithSubscribers != null ? onlyPlayWithSubscribers : true; - networkCache = networkCache != null ? networkCache : 2000; + adaptativeBitrate = adaptativeBitrate != null ? adaptativeBitrate : DefaultValues.adaptativeBitrate; + onlyPlayWithSubscribers = onlyPlayWithSubscribers != null ? onlyPlayWithSubscribers + : DefaultValues.onlyPlayWithSubscribers; + networkCache = networkCache != null ? networkCache : DefaultValues.networkCache; if (rtspUri != null) { try { checkRtspUri(rtspUri); @@ -649,7 +672,7 @@ public class ConnectionProperties { } catch (ClassCastException e) { throw new IllegalArgumentException("Type error in parameter 'record': " + e.getMessage()); } - record = record != null ? record : true; + record = record != null ? record : DefaultValues.record; builder.record(record); return builder; diff --git a/openvidu-java-client/src/main/java/io/openvidu/java/client/SessionProperties.java b/openvidu-java-client/src/main/java/io/openvidu/java/client/SessionProperties.java index 0fa5b1b4..304fb7fb 100644 --- a/openvidu-java-client/src/main/java/io/openvidu/java/client/SessionProperties.java +++ b/openvidu-java-client/src/main/java/io/openvidu/java/client/SessionProperties.java @@ -31,6 +31,17 @@ import com.google.gson.reflect.TypeToken; */ public class SessionProperties { + public static class DefaultValues { + public static final MediaMode mediaMode = MediaMode.ROUTED; + public static final RecordingMode recordingMode = RecordingMode.MANUAL; + public static final RecordingProperties defaultRecordingProperties = new RecordingProperties.Builder().build(); + public static final String customSessionId = ""; + public static final String mediaNode = null; + public static final VideoCodec forcedVideoCodec = VideoCodec.MEDIA_SERVER_PREFERRED; + public static final VideoCodec forcedVideoCodecResolved = VideoCodec.NONE; + public static final Boolean allowTranscoding = false; + } + private MediaMode mediaMode; private RecordingMode recordingMode; private RecordingProperties defaultRecordingProperties; @@ -45,14 +56,14 @@ public class SessionProperties { */ public static class Builder { - private MediaMode mediaMode = MediaMode.ROUTED; - private RecordingMode recordingMode = RecordingMode.MANUAL; - private RecordingProperties defaultRecordingProperties = new RecordingProperties.Builder().build(); - private String customSessionId = ""; - private String mediaNode; - private VideoCodec forcedVideoCodec = VideoCodec.MEDIA_SERVER_PREFERRED; - private VideoCodec forcedVideoCodecResolved = VideoCodec.NONE; - private Boolean allowTranscoding = false; + private MediaMode mediaMode = DefaultValues.mediaMode; + private RecordingMode recordingMode = DefaultValues.recordingMode; + private RecordingProperties defaultRecordingProperties = DefaultValues.defaultRecordingProperties; + private String customSessionId = DefaultValues.customSessionId; + private String mediaNode = DefaultValues.mediaNode; + private VideoCodec forcedVideoCodec = DefaultValues.forcedVideoCodec; + private VideoCodec forcedVideoCodecResolved = DefaultValues.forcedVideoCodecResolved; + private Boolean allowTranscoding = DefaultValues.allowTranscoding; /** * Returns the {@link io.openvidu.java.client.SessionProperties} object properly @@ -338,18 +349,14 @@ public class SessionProperties { } try { - // Safe parameter retrieval. Default values if not defined + // Safe parameter retrieval. Let default values if not defined if (recordingModeString != null) { RecordingMode recordingMode = RecordingMode.valueOf(recordingModeString); builder = builder.recordingMode(recordingMode); - } else { - builder = builder.recordingMode(RecordingMode.MANUAL); } if (mediaModeString != null) { MediaMode mediaMode = MediaMode.valueOf(mediaModeString); builder = builder.mediaMode(mediaMode); - } else { - builder = builder.mediaMode(MediaMode.ROUTED); } if (customSessionId != null && !customSessionId.isEmpty()) { if (!isValidCustomSessionId(customSessionId)) { @@ -358,12 +365,10 @@ public class SessionProperties { } builder = builder.customSessionId(customSessionId); } - if (forcedVideoCodec != null) { builder = builder.forcedVideoCodec(forcedVideoCodec); builder = builder.forcedVideoCodecResolved(forcedVideoCodec); } - if (allowTranscoding != null) { builder = builder.allowTranscoding(allowTranscoding); } @@ -380,7 +385,6 @@ public class SessionProperties { } if (defaultRecordingPropertiesJson != null) { try { - String jsonString = defaultRecordingPropertiesJson.toString(); RecordingProperties.Builder recBuilder = RecordingProperties .fromJson(new Gson().fromJson(jsonString, Map.class), null); @@ -390,8 +394,6 @@ public class SessionProperties { throw new IllegalArgumentException( "Parameter 'defaultRecordingProperties' is not valid: " + e.getMessage()); } - } else { - builder.defaultRecordingProperties(new RecordingProperties.Builder().build()); } String mediaNode = getMediaNodeProperty(params); diff --git a/openvidu-server/src/main/java/io/openvidu/server/rest/SessionRestController.java b/openvidu-server/src/main/java/io/openvidu/server/rest/SessionRestController.java index 37ab747b..8da23651 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/rest/SessionRestController.java +++ b/openvidu-server/src/main/java/io/openvidu/server/rest/SessionRestController.java @@ -269,10 +269,10 @@ public class SessionRestController { @RequestMapping(value = "/sessions/{sessionId}/connection", method = RequestMethod.POST) public ResponseEntity initializeConnection(@PathVariable("sessionId") String sessionId, - @RequestBody Map params) { + @RequestBody(required = false) Map params) { log.info("REST API: POST {} {}", RequestMappings.API + "/sessions/" + sessionId + "/connection", - params.toString()); + params != null ? params.toString() : "{}"); Session session = this.sessionManager.getSessionWithNotActive(sessionId); if (session == null) { @@ -838,7 +838,8 @@ public class SessionRestController { ConnectionType type = ConnectionProperties.fromJson(params).build().getType(); if (ConnectionType.WEBRTC.equals(type)) { - if (params.get("customIceServers") == null && !openviduConfig.getWebrtcIceServersBuilders().isEmpty()) { + if (params != null && params.get("customIceServers") == null + && !openviduConfig.getWebrtcIceServersBuilders().isEmpty()) { // If not defined in Connection, check if defined in OpenVidu global config for (IceServerProperties.Builder iceServerPropertiesBuilder : openviduConfig .getWebrtcIceServersBuilders()) {