mirror of https://github.com/OpenVidu/openvidu.git
openvidu: Add OPENVIDU_WEBRTC_ICE_SERVERS configuration paramater
parent
40ed2c5efc
commit
4d579cf8b3
|
@ -1516,9 +1516,11 @@ export class Session extends EventDispatcher {
|
||||||
let rtcIceServer: RTCIceServer = {
|
let rtcIceServer: RTCIceServer = {
|
||||||
urls: [ iceServer.url ]
|
urls: [ iceServer.url ]
|
||||||
}
|
}
|
||||||
|
logger.log("STUN/TURN server IP: " + iceServer.url);
|
||||||
if (iceServer.username != null && iceServer.credential != null) {
|
if (iceServer.username != null && iceServer.credential != null) {
|
||||||
rtcIceServer.username = iceServer.username;
|
rtcIceServer.username = iceServer.username;
|
||||||
rtcIceServer.credential = iceServer.credential;
|
rtcIceServer.credential = iceServer.credential;
|
||||||
|
logger.log('TURN credentials [' + iceServer.username + ':' + iceServer.credential + ']');
|
||||||
}
|
}
|
||||||
this.openvidu.iceServers.push(rtcIceServer);
|
this.openvidu.iceServers.push(rtcIceServer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ import java.util.Map.Entry;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
import io.openvidu.java.client.IceServerProperties;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.validator.routines.DomainValidator;
|
import org.apache.commons.validator.routines.DomainValidator;
|
||||||
|
@ -220,10 +221,12 @@ public class OpenviduConfig {
|
||||||
|
|
||||||
private MediaServer mediaServerInfo = MediaServer.kurento;
|
private MediaServer mediaServerInfo = MediaServer.kurento;
|
||||||
|
|
||||||
// Media properties
|
// Webrtc properties
|
||||||
|
|
||||||
private boolean webrtcSimulcast = false;
|
private boolean webrtcSimulcast = false;
|
||||||
|
|
||||||
|
private List<IceServerProperties> webrtcIceServers;
|
||||||
|
|
||||||
// Plain config properties getters
|
// Plain config properties getters
|
||||||
|
|
||||||
public String getCoturnDatabaseDbname() {
|
public String getCoturnDatabaseDbname() {
|
||||||
|
@ -290,6 +293,10 @@ public class OpenviduConfig {
|
||||||
return this.webrtcSimulcast;
|
return this.webrtcSimulcast;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<IceServerProperties> getWebrtcIceServers() {
|
||||||
|
return webrtcIceServers;
|
||||||
|
}
|
||||||
|
|
||||||
public String getOpenViduRecordingPath() {
|
public String getOpenViduRecordingPath() {
|
||||||
return this.openviduRecordingPath;
|
return this.openviduRecordingPath;
|
||||||
}
|
}
|
||||||
|
@ -619,6 +626,8 @@ public class OpenviduConfig {
|
||||||
|
|
||||||
checkCertificateType();
|
checkCertificateType();
|
||||||
|
|
||||||
|
webrtcIceServers = loadWebrtcIceServers("OPENVIDU_WEBRTC_ICE_SERVERS");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkCertificateType() {
|
private void checkCertificateType() {
|
||||||
|
@ -1147,4 +1156,46 @@ public class OpenviduConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<IceServerProperties> loadWebrtcIceServers(String property) {
|
||||||
|
String rawIceServers = asOptionalString(property);
|
||||||
|
List<IceServerProperties> webrtcIceServers = new ArrayList<>();
|
||||||
|
if (rawIceServers == null || rawIceServers.isEmpty()) {
|
||||||
|
return webrtcIceServers;
|
||||||
|
}
|
||||||
|
List<String> arrayIceServers = asJsonStringsArray(property);
|
||||||
|
for (String iceServerString : arrayIceServers) {
|
||||||
|
try {
|
||||||
|
IceServerProperties iceServerProperties = readIceServer(property, iceServerString);
|
||||||
|
webrtcIceServers.add(iceServerProperties);
|
||||||
|
} catch (Exception e) {
|
||||||
|
addError(property, iceServerString + " is not a valid webrtc ice server: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return webrtcIceServers;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IceServerProperties readIceServer(String property, String iceServerString) {
|
||||||
|
String url = null, username = null, credential = null;
|
||||||
|
String[] iceServerPropList = iceServerString.split(",");
|
||||||
|
for (String iceServerProp: iceServerPropList) {
|
||||||
|
String[] iceServerPropEntry = iceServerProp.split("=");
|
||||||
|
if (iceServerPropEntry.length == 2) {
|
||||||
|
if (iceServerProp.startsWith("url=")) {
|
||||||
|
url = iceServerPropEntry[1];
|
||||||
|
} else if (iceServerProp.startsWith("username=")) {
|
||||||
|
username = iceServerPropEntry[1];
|
||||||
|
} else if (iceServerProp.startsWith("credential=")) {
|
||||||
|
credential = iceServerPropEntry[1];
|
||||||
|
} else {
|
||||||
|
addError(property, "Wrong parameter: " + iceServerProp);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
addError(property, "Wrong parameter: " + iceServerProp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
IceServerProperties iceServerProperties = new IceServerProperties.Builder()
|
||||||
|
.url(url).username(username).credential(credential).build();
|
||||||
|
return iceServerProperties;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -934,6 +934,11 @@ public class SessionRestController {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new Exception("Type error in some parameter of 'customIceServers': " + e.getMessage());
|
throw new Exception("Type error in some parameter of 'customIceServers': " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
} else if(!openviduConfig.getWebrtcIceServers().isEmpty()){
|
||||||
|
// If not defined in connection, check if defined in openvidu config
|
||||||
|
for (IceServerProperties iceServerProperties: openviduConfig.getWebrtcIceServers()) {
|
||||||
|
builder.addCustomIceServer(iceServerProperties);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build WEBRTC options
|
// Build WEBRTC options
|
||||||
|
|
Loading…
Reference in New Issue