Реализация динамического запроса TURN при подключении
This commit is contained in:
@@ -19,7 +19,8 @@ public class Packet28IceServers extends Packet {
|
||||
String url = stream.readString();
|
||||
String username = stream.readString();
|
||||
String credential = stream.readString();
|
||||
RTCIceServer iceServer = new RTCIceServer(url, username, credential);
|
||||
String transport = stream.readString();
|
||||
RTCIceServer iceServer = new RTCIceServer(url, username, credential, transport);
|
||||
iceServers.add(iceServer);
|
||||
}
|
||||
}
|
||||
@@ -33,6 +34,7 @@ public class Packet28IceServers extends Packet {
|
||||
stream.writeString(iceServer.getUrl());
|
||||
stream.writeString(iceServer.getUsername());
|
||||
stream.writeString(iceServer.getCredential());
|
||||
stream.writeString(iceServer.getTransport());
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
@@ -28,13 +28,11 @@ public class ForwardUnitService {
|
||||
private Logger logger;
|
||||
private Set<SFU> sfuConnections = ConcurrentHashMap.newKeySet();
|
||||
private ClientManager clientManager;
|
||||
private Set<RTCIceServer> turnServers = new HashSet<>();
|
||||
private ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
|
||||
public ForwardUnitService(Logger logger, ClientManager clientManager) {
|
||||
this.logger = logger;
|
||||
this.clientManager = clientManager;
|
||||
this.readAllTurnServers();
|
||||
this.sfuConnectionsSheduler();
|
||||
}
|
||||
|
||||
@@ -65,37 +63,6 @@ public class ForwardUnitService {
|
||||
}, 10, 10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Читаем все TURN сервера из переменной окружения и сохраняем их для дальнейшего
|
||||
* использования при организации звонков через SFU серверы.
|
||||
*/
|
||||
private void readAllTurnServers() {
|
||||
String turnServersEnv = System.getenv("TURN_SERVERS");
|
||||
if(turnServersEnv == null || turnServersEnv.isEmpty()) {
|
||||
this.logger.info(Color.YELLOW + "No TURN servers configured, skipping TURN servers boot");
|
||||
return;
|
||||
}
|
||||
String[] turnServers = turnServersEnv.split(",");
|
||||
for(String turnServer : turnServers) {
|
||||
String[] parts = turnServer.split("@");
|
||||
if(parts.length != 2) {
|
||||
this.logger.error(Color.RED + "Invalid TURN server configuration: " + turnServer);
|
||||
continue;
|
||||
}
|
||||
String address = parts[0];
|
||||
String credentialsPart = parts[1];
|
||||
String[] credentialsParts = credentialsPart.split(":");
|
||||
if(credentialsParts.length != 2) {
|
||||
this.logger.error(Color.RED + "Invalid TURN server credentials configuration: " + credentialsPart);
|
||||
continue;
|
||||
}
|
||||
String username = credentialsParts[0];
|
||||
String credential = credentialsParts[1];
|
||||
RTCIceServer iceServer = new RTCIceServer(address, username, credential);
|
||||
this.turnServers.add(iceServer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Инициализирует соединения к SFU серверам для звонков.
|
||||
* Ожидается, что адреса SFU серверов и секретные ключи для них будут переданы через переменную окружения SFU_SERVERS в формате "address1@secretKey1,address2@secretKey2,...".
|
||||
@@ -239,6 +206,13 @@ public class ForwardUnitService {
|
||||
* @return список серверов для RTC
|
||||
*/
|
||||
public Set<RTCIceServer> getTurnServers() {
|
||||
Set<RTCIceServer> turnServers = new HashSet<>();
|
||||
for(SFU sfu : this.sfuConnections) {
|
||||
RTCIceServer turnServer = sfu.getTurnServer();
|
||||
if(turnServer != null) {
|
||||
turnServers.add(turnServer);
|
||||
}
|
||||
}
|
||||
return turnServers;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user