diff --git a/openvidu-server/src/main/java/io/openvidu/server/config/OpenviduConfig.java b/openvidu-server/src/main/java/io/openvidu/server/config/OpenviduConfig.java index 3d6827ed..a54086eb 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/config/OpenviduConfig.java +++ b/openvidu-server/src/main/java/io/openvidu/server/config/OpenviduConfig.java @@ -18,7 +18,9 @@ package io.openvidu.server.config; import java.io.File; +import java.net.Inet4Address; import java.net.Inet6Address; +import java.net.InetAddress; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; @@ -83,7 +85,7 @@ public class OpenviduConfig { @Override public String toString() { return "Error [property=" + property + ", value=" + value + ", message=" + message + "]"; - } + } } private static final Logger log = LoggerFactory.getLogger(OpenviduConfig.class); @@ -287,13 +289,13 @@ public class OpenviduConfig { public int getSessionGarbageThreshold() { return openviduSessionsGarbageThreshold; } - + public String getDotenvPath() { return dotenvPath; } // Derived properties methods - + public String getSpringProfile() { return springProfile; } @@ -341,7 +343,7 @@ public class OpenviduConfig { } // Properties management methods - + public OpenviduConfig deriveWithAdditionalPropertiesSource(Map propertiesSource) { OpenviduConfig config = newOpenviduConfig(); config.propertiesSource = propertiesSource; @@ -429,8 +431,6 @@ public class OpenviduConfig { protected void checkConfigurationProperties() { - - serverPort = getValue("server.port"); coturnRedisDbname = getValue("coturn.redis.dbname"); @@ -460,7 +460,7 @@ public class OpenviduConfig { openviduStreamsVideoMinRecvBandwidth = asNonNegativeInteger("openvidu.streams.video.min-recv-bandwidth"); openviduStreamsVideoMaxSendBandwidth = asNonNegativeInteger("openvidu.streams.video.max-send-bandwidth"); openviduStreamsVideoMinSendBandwidth = asNonNegativeInteger("openvidu.streams.video.min-send-bandwidth"); - + openviduSessionsGarbageInterval = asNonNegativeInteger("openvidu.sessions.garbage.interval"); openviduSessionsGarbageThreshold = asNonNegativeInteger("openvidu.sessions.garbage.threshold"); @@ -473,7 +473,7 @@ public class OpenviduConfig { checkWebhook(); checkCertificateType(); - + dotenvPath = getValue("dotenv.path"); } @@ -490,7 +490,8 @@ public class OpenviduConfig { } private void checkCoturnIp() { - coturnIp = getValue("coturn.ip"); + String property = "coturn.ip"; + coturnIp = asOptionalIPv4OrIPv6(property); if (coturnIp == null || this.coturnIp.isEmpty()) { try { @@ -741,6 +742,26 @@ public class OpenviduConfig { return inetAddress; } + protected String asOptionalIPv4OrIPv6(String property) { + String ip = getValue(property); + if (ip != null && !ip.isEmpty()) { + boolean isIP; + try { + final InetAddress inet = InetAddress.getByName(ip); + isIP = inet instanceof Inet4Address || inet instanceof Inet6Address; + if (isIP) { + ip = inet.getHostAddress(); + } + } catch (final UnknownHostException e) { + isIP = false; + } + if (!isIP) { + addError(property, "Is not a valid IP Address (IPv4 or IPv6)"); + } + } + return ip; + } + protected String asFileSystemPath(String property) { try { String stringPath = this.asNonEmptyString(property); diff --git a/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/MediaEndpoint.java b/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/MediaEndpoint.java index eab45ca5..e3fcf8f8 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/MediaEndpoint.java +++ b/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/MediaEndpoint.java @@ -284,14 +284,61 @@ public abstract class MediaEndpoint { public void onSuccess(WebRtcEndpoint result) throws Exception { webEndpoint = result; - webEndpoint.setMaxVideoRecvBandwidth(maxRecvKbps); - webEndpoint.setMinVideoRecvBandwidth(minRecvKbps); - webEndpoint.setMaxVideoSendBandwidth(maxSendKbps); - webEndpoint.setMinVideoSendBandwidth(minSendKbps); + if (openviduConfig.getCoturnIp() != null && !openviduConfig.getCoturnIp().isEmpty() + && !openviduConfig.getCoturnIp().equals("localhost")) { + webEndpoint.setStunServerAddress(openviduConfig.getCoturnIp()); + webEndpoint.setStunServerPort(3478); + } endpointLatch.countDown(); log.trace("EP {}: Created a new WebRtcEndpoint", endpointName); endpointSubscription = registerElemErrListener(webEndpoint); + + // This can be done after unlocking latch. Not necessary to wait + webEndpoint.setMaxVideoRecvBandwidth(maxRecvKbps, new Continuation() { + @Override + public void onSuccess(Void result) throws Exception { + } + + @Override + public void onError(Throwable cause) throws Exception { + log.error("Error setting max video receive bandwidth for endpoint {}: {}", endpointName, + cause.getMessage()); + } + }); + webEndpoint.setMinVideoRecvBandwidth(minRecvKbps, new Continuation() { + @Override + public void onSuccess(Void result) throws Exception { + } + + @Override + public void onError(Throwable cause) throws Exception { + log.error("Error setting min video receive bandwidth for endpoint {}: {}", endpointName, + cause.getMessage()); + } + }); + webEndpoint.setMaxVideoSendBandwidth(maxSendKbps, new Continuation() { + @Override + public void onSuccess(Void result) throws Exception { + } + + @Override + public void onError(Throwable cause) throws Exception { + log.error("Error setting max video send bandwidth for endpoint {}: {}", endpointName, + cause.getMessage()); + } + }); + webEndpoint.setMinVideoSendBandwidth(minSendKbps, new Continuation() { + @Override + public void onSuccess(Void result) throws Exception { + } + + @Override + public void onError(Throwable cause) throws Exception { + log.error("Error setting min video send bandwidth for endpoint {}: {}", endpointName, + cause.getMessage()); + } + }); } @Override