mirror of https://github.com/OpenVidu/openvidu.git
Adapt coturn configuration to allow multiple coturns by kms uri
parent
b29ecafea5
commit
4f04f3b33c
|
@ -35,6 +35,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
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.ConcurrentHashMap;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
@ -159,7 +160,12 @@ public class OpenviduConfig {
|
||||||
|
|
||||||
private Integer openviduStreamsVideoMinSendBandwidth;
|
private Integer openviduStreamsVideoMinSendBandwidth;
|
||||||
|
|
||||||
private String coturnIp;
|
/**
|
||||||
|
* Map which relates used Coturn IP per Media Node.
|
||||||
|
* Depending on which media node will be used for the session,
|
||||||
|
* a coturn IP should be sent to the browser and Kurento.
|
||||||
|
*/
|
||||||
|
private ConcurrentHashMap<String, String> mapKmsUriCoturnIp = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private int coturnPort;
|
private int coturnPort;
|
||||||
|
|
||||||
|
@ -334,8 +340,8 @@ public class OpenviduConfig {
|
||||||
return this.openviduStreamsVideoMinSendBandwidth;
|
return this.openviduStreamsVideoMinSendBandwidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCoturnIp() {
|
public String getCoturnIp(String kmsUri) {
|
||||||
return this.coturnIp;
|
return this.mapKmsUriCoturnIp.get(kmsUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCoturnPort() {
|
public int getCoturnPort() {
|
||||||
|
@ -641,15 +647,21 @@ public class OpenviduConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkCoturnIp() {
|
private void checkCoturnIp() {
|
||||||
|
if (this.getKmsUris().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("'KMS_URIS' should contain at least one KMS url");
|
||||||
|
}
|
||||||
|
String firstKmsWsUri = this.getKmsUris().get(0);
|
||||||
String property = "COTURN_IP";
|
String property = "COTURN_IP";
|
||||||
coturnIp = asOptionalIPv4OrIPv6(property);
|
String coturnIp = asOptionalIPv4OrIPv6(property);
|
||||||
|
if (coturnIp == null || coturnIp.isEmpty()) {
|
||||||
if (coturnIp == null || this.coturnIp.isEmpty()) {
|
|
||||||
try {
|
try {
|
||||||
this.coturnIp = new URL(this.getFinalUrl()).getHost();
|
coturnIp = new URL(this.getFinalUrl()).getHost();
|
||||||
|
this.mapKmsUriCoturnIp.put(firstKmsWsUri, coturnIp);
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
log.error("Can't get Domain name from OpenVidu public Url: " + e.getMessage());
|
log.error("Can't get Domain name from OpenVidu public Url: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.mapKmsUriCoturnIp.put(firstKmsWsUri, coturnIp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class SessionEventsHandler {
|
||||||
CDR.recordSessionDestroyed(session, reason);
|
CDR.recordSessionDestroyed(session, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onParticipantJoined(Participant participant, String sessionId, Set<Participant> existingParticipants,
|
public void onParticipantJoined(Participant participant, String sessionId, String coturnIp, Set<Participant> existingParticipants,
|
||||||
Integer transactionId, OpenViduException error) {
|
Integer transactionId, OpenViduException error) {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
rpcNotificationService.sendErrorResponse(participant.getParticipantPrivateId(), transactionId, null, error);
|
rpcNotificationService.sendErrorResponse(participant.getParticipantPrivateId(), transactionId, null, error);
|
||||||
|
@ -184,7 +184,8 @@ public class SessionEventsHandler {
|
||||||
result.addProperty(ProtocolElements.PARTICIPANTJOINED_ROLE_PARAM,
|
result.addProperty(ProtocolElements.PARTICIPANTJOINED_ROLE_PARAM,
|
||||||
participant.getToken().getRole().name());
|
participant.getToken().getRole().name());
|
||||||
}
|
}
|
||||||
result.addProperty(ProtocolElements.PARTICIPANTJOINED_COTURNIP_PARAM, openviduConfig.getCoturnIp());
|
|
||||||
|
result.addProperty(ProtocolElements.PARTICIPANTJOINED_COTURNIP_PARAM, coturnIp);
|
||||||
result.addProperty(ProtocolElements.PARTICIPANTJOINED_COTURNPORT_PARAM, openviduConfig.getCoturnPort());
|
result.addProperty(ProtocolElements.PARTICIPANTJOINED_COTURNPORT_PARAM, openviduConfig.getCoturnPort());
|
||||||
List<IceServerProperties> customIceServers = participant.getToken().getCustomIceServers();
|
List<IceServerProperties> customIceServers = participant.getToken().getCustomIceServers();
|
||||||
if (customIceServers != null && !customIceServers.isEmpty()) {
|
if (customIceServers != null && !customIceServers.isEmpty()) {
|
||||||
|
|
|
@ -136,7 +136,7 @@ public class KurentoSessionManager extends SessionManager {
|
||||||
String error = "Timeout of " + KmsManager.MAX_SECONDS_LOCK_WAIT
|
String error = "Timeout of " + KmsManager.MAX_SECONDS_LOCK_WAIT
|
||||||
+ " seconds waiting to acquire lock";
|
+ " seconds waiting to acquire lock";
|
||||||
log.error(error);
|
log.error(error);
|
||||||
sessionEventsHandler.onParticipantJoined(participant, sessionId, null, transactionId,
|
sessionEventsHandler.onParticipantJoined(participant, sessionId, null, null, transactionId,
|
||||||
new OpenViduException(Code.ROOM_CANNOT_BE_CREATED_ERROR_CODE, error));
|
new OpenViduException(Code.ROOM_CANNOT_BE_CREATED_ERROR_CODE, error));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,8 @@ public class KurentoSessionManager extends SessionManager {
|
||||||
try {
|
try {
|
||||||
existingParticipants = getParticipants(sessionId);
|
existingParticipants = getParticipants(sessionId);
|
||||||
kSession.join(participant);
|
kSession.join(participant);
|
||||||
sessionEventsHandler.onParticipantJoined(participant, sessionId, existingParticipants,
|
String coturnIp = openviduConfig.getCoturnIp(kSession.getKms().getUri());
|
||||||
|
sessionEventsHandler.onParticipantJoined(participant, sessionId, coturnIp, existingParticipants,
|
||||||
transactionId, null);
|
transactionId, null);
|
||||||
} finally {
|
} finally {
|
||||||
kSession.joinLeaveLock.unlock();
|
kSession.joinLeaveLock.unlock();
|
||||||
|
@ -177,21 +178,21 @@ public class KurentoSessionManager extends SessionManager {
|
||||||
log.error(
|
log.error(
|
||||||
"Timeout waiting for join-leave Session lock to be available for participant {} of session {} in joinRoom",
|
"Timeout waiting for join-leave Session lock to be available for participant {} of session {} in joinRoom",
|
||||||
participant.getParticipantPublicId(), sessionId);
|
participant.getParticipantPublicId(), sessionId);
|
||||||
sessionEventsHandler.onParticipantJoined(participant, sessionId, null, transactionId,
|
sessionEventsHandler.onParticipantJoined(participant, sessionId, null, null, transactionId,
|
||||||
new OpenViduException(Code.GENERIC_ERROR_CODE, "Timeout waiting for Session lock"));
|
new OpenViduException(Code.GENERIC_ERROR_CODE, "Timeout waiting for Session lock"));
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
log.error(
|
log.error(
|
||||||
"InterruptedException waiting for join-leave Session lock to be available for participant {} of session {} in joinRoom",
|
"InterruptedException waiting for join-leave Session lock to be available for participant {} of session {} in joinRoom",
|
||||||
participant.getParticipantPublicId(), sessionId);
|
participant.getParticipantPublicId(), sessionId);
|
||||||
sessionEventsHandler.onParticipantJoined(participant, sessionId, null, transactionId,
|
sessionEventsHandler.onParticipantJoined(participant, sessionId, null,null, transactionId,
|
||||||
new OpenViduException(Code.GENERIC_ERROR_CODE,
|
new OpenViduException(Code.GENERIC_ERROR_CODE,
|
||||||
"InterruptedException waiting for Session lock"));
|
"InterruptedException waiting for Session lock"));
|
||||||
}
|
}
|
||||||
} catch (OpenViduException e) {
|
} catch (OpenViduException e) {
|
||||||
log.error("PARTICIPANT {}: Error joining/creating session {}", participant.getParticipantPublicId(),
|
log.error("PARTICIPANT {}: Error joining/creating session {}", participant.getParticipantPublicId(),
|
||||||
sessionId, e);
|
sessionId, e);
|
||||||
sessionEventsHandler.onParticipantJoined(participant, sessionId, null, transactionId, e);
|
sessionEventsHandler.onParticipantJoined(participant, sessionId, null,null, transactionId, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -299,9 +299,10 @@ public abstract class MediaEndpoint {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(WebRtcEndpoint result) throws Exception {
|
public void onSuccess(WebRtcEndpoint result) throws Exception {
|
||||||
webEndpoint = result;
|
webEndpoint = result;
|
||||||
|
String kmsUri = owner.getSession().getKms().getUri();
|
||||||
if (openviduConfig.getCoturnIp() != null && !openviduConfig.getCoturnIp().isEmpty()) {
|
String coturnIp = openviduConfig.getCoturnIp(kmsUri);
|
||||||
webEndpoint.setStunServerAddress(openviduConfig.getCoturnIp());
|
if (coturnIp != null && !coturnIp.isEmpty()) {
|
||||||
|
webEndpoint.setStunServerAddress(coturnIp);
|
||||||
webEndpoint.setStunServerPort(openviduConfig.getCoturnPort());
|
webEndpoint.setStunServerPort(openviduConfig.getCoturnPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,7 +167,7 @@ public class WebhookIntegrationTest {
|
||||||
|
|
||||||
// Client should have already received "connectionCreated" RPC response
|
// Client should have already received "connectionCreated" RPC response
|
||||||
// nonetheless
|
// nonetheless
|
||||||
verify(sessionEventsHandler, times(1)).onParticipantJoined(refEq(participant), anyString(), anySet(),
|
verify(sessionEventsHandler, times(1)).onParticipantJoined(refEq(participant), anyString(), anyString(), anySet(),
|
||||||
anyInt(), refEq(null));
|
anyInt(), refEq(null));
|
||||||
|
|
||||||
// Now webhook response for event "participantJoined" should be received
|
// Now webhook response for event "participantJoined" should be received
|
||||||
|
|
Loading…
Reference in New Issue