openvidu-server: Fix OPENVIDU_WEBRTC_ICE_SERVERS not being used when customIceServer is an empty list but not null

pull/803/head
cruizba 2023-05-16 01:56:02 +02:00
parent 90d13cedc4
commit 72b95741ca
1 changed files with 19 additions and 7 deletions

View File

@ -21,6 +21,7 @@ import java.net.MalformedURLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -844,18 +845,29 @@ public class SessionRestController {
ConnectionType type = ConnectionProperties.fromJson(params).build().getType(); ConnectionType type = ConnectionProperties.fromJson(params).build().getType();
// Check if custom ice servers are defined in params
boolean definedCustomIceServers = false;
if (ConnectionType.WEBRTC.equals(type)) { if (ConnectionType.WEBRTC.equals(type)) {
if (params != null && params.get("customIceServers") == null if (params != null) {
&& !openviduConfig.getWebrtcIceServersBuilders().isEmpty()) { JsonArray customIceServersJsonArray = null;
// If not defined in Connection, check if defined in OpenVidu global config if (params.get("customIceServers") != null) {
for (IceServerProperties.Builder iceServerPropertiesBuilder : openviduConfig customIceServersJsonArray = new Gson().toJsonTree(params.get("customIceServers"), List.class)
.getWebrtcIceServersBuilders()) { .getAsJsonArray();
IceServerProperties.Builder configIceBuilder = iceServerPropertiesBuilder.clone(); definedCustomIceServers = customIceServersJsonArray.size() > 0;
builder.addCustomIceServer(configIceBuilder.build());
} }
} }
} }
if (!definedCustomIceServers && !openviduConfig.getWebrtcIceServersBuilders().isEmpty()) {
// If not defined in Connection, check if defined in OpenVidu global config
for (IceServerProperties.Builder iceServerPropertiesBuilder : openviduConfig
.getWebrtcIceServersBuilders()) {
IceServerProperties.Builder configIceBuilder = iceServerPropertiesBuilder.clone();
builder.addCustomIceServer(configIceBuilder.build());
}
}
return builder; return builder;
} }