mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: Redis turn DB
parent
04e0c51165
commit
001d938312
|
@ -58,8 +58,17 @@ public class OpenviduConfig {
|
||||||
@Value("#{'${spring.profiles.active:}'.length() > 0 ? '${spring.profiles.active:}'.split(',') : \"default\"}")
|
@Value("#{'${spring.profiles.active:}'.length() > 0 ? '${spring.profiles.active:}'.split(',') : \"default\"}")
|
||||||
private String springProfile;
|
private String springProfile;
|
||||||
|
|
||||||
@Value("${coturn.sqlite}")
|
@Value("${coturn.redis.ip}")
|
||||||
private String coturnSqlite;
|
private String coturnRedisIp;
|
||||||
|
|
||||||
|
@Value("${coturn.redis.dbname}")
|
||||||
|
private String coturnRedisDbname;
|
||||||
|
|
||||||
|
@Value("${coturn.redis.password}")
|
||||||
|
private String coturnRedisPassword;
|
||||||
|
|
||||||
|
@Value("${coturn.redis.connect-timeout}")
|
||||||
|
private String coturnRedisConnectTimeout;
|
||||||
|
|
||||||
private String finalUrl;
|
private String finalUrl;
|
||||||
|
|
||||||
|
@ -123,8 +132,9 @@ public class OpenviduConfig {
|
||||||
return springProfile;
|
return springProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCoturnSqlite() {
|
public String getCoturnDatabaseString() {
|
||||||
return coturnSqlite;
|
return "\"ip=" + this.coturnRedisIp + " dbname=" + this.coturnRedisDbname + " password="
|
||||||
|
+ this.coturnRedisPassword + " connect_timeout=" + this.coturnRedisConnectTimeout + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParticipantRole[] getRolesFromRecordingNotification() {
|
public ParticipantRole[] getRolesFromRecordingNotification() {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package io.openvidu.server.coturn;
|
package io.openvidu.server.coturn;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
|
@ -12,24 +11,20 @@ public class BashCoturnCredentialsService extends CoturnCredentialsService {
|
||||||
|
|
||||||
public BashCoturnCredentialsService(OpenviduConfig openviduConfig) {
|
public BashCoturnCredentialsService(OpenviduConfig openviduConfig) {
|
||||||
super(openviduConfig);
|
super(openviduConfig);
|
||||||
File f = new File(this.openviduConfig.getCoturnSqlite());
|
|
||||||
if (f.exists()) {
|
|
||||||
f.delete();
|
|
||||||
}
|
|
||||||
this.coturnDatabaseLocation = this.openviduConfig.getCoturnSqlite();
|
|
||||||
try {
|
try {
|
||||||
String response = CommandExecutor.execCommand("/bin/sh", "-c", "turnadmin -l -b " + this.coturnDatabaseLocation);
|
String response = CommandExecutor.execCommand("/bin/sh", "-c",
|
||||||
|
"turnadmin -l -N " + this.coturnDatabaseString);
|
||||||
if (response.contains("turnadmin: not found")) {
|
if (response.contains("turnadmin: not found")) {
|
||||||
// No coturn installed in the host machine
|
// No coturn installed in the host machine
|
||||||
log.warn("No COTURN server is installed in the host machine");
|
log.warn("No COTURN server is installed in the host machine. Response: " + response);
|
||||||
log.warn("No COTURN server will be configured for clients");
|
log.warn("No COTURN server will be automatically configured for clients");
|
||||||
this.coturnAvailable = false;
|
this.coturnAvailable = false;
|
||||||
} else if (response.contains("Cannot open SQLite DB connection")) {
|
} else if (response.contains("Cannot initialize Redis DB connection")) {
|
||||||
log.warn("COTURN SQLite database is not accesible at path " + this.coturnDatabaseLocation);
|
log.warn("Redis DB is not accesible with connection string " + this.coturnDatabaseString);
|
||||||
log.warn("No COTURN server will be configured for clients");
|
log.warn("No COTURN server will be automatically configured for clients");
|
||||||
this.coturnAvailable = false;
|
this.coturnAvailable = false;
|
||||||
} else {
|
} else {
|
||||||
log.info("COTURN sqlite database location: " + this.openviduConfig.getCoturnSqlite());
|
log.info("COTURN Redis DB accessible with string " + this.coturnDatabaseString);
|
||||||
}
|
}
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -43,22 +38,17 @@ public class BashCoturnCredentialsService extends CoturnCredentialsService {
|
||||||
log.info("Creating COTURN user");
|
log.info("Creating COTURN user");
|
||||||
String user = RandomStringUtils.randomAlphanumeric(6).toUpperCase();
|
String user = RandomStringUtils.randomAlphanumeric(6).toUpperCase();
|
||||||
String pass = RandomStringUtils.randomAlphanumeric(6).toLowerCase();
|
String pass = RandomStringUtils.randomAlphanumeric(6).toLowerCase();
|
||||||
String command = "turnadmin -a -u " + user + " -r openvidu -p " + pass + " -b " + this.coturnDatabaseLocation;
|
String command = "turnadmin -a -u " + user + " -r openvidu -p " + pass + " -N " + this.coturnDatabaseString;
|
||||||
String users = "";
|
|
||||||
lock.lock();
|
|
||||||
try {
|
try {
|
||||||
CommandExecutor.execCommand("/bin/sh", "-c", command);
|
String response = CommandExecutor.execCommand("/bin/sh", "-c", command);
|
||||||
users = CommandExecutor.execCommand("/bin/sh", "-c", "turnadmin -l -b " + this.coturnDatabaseLocation);
|
if (response.contains("connection success: " + this.trimmedCoturnDatabaseString)) {
|
||||||
} catch (IOException | InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
lock.unlock();
|
|
||||||
if (users.contains(user + "[openvidu]")) {
|
|
||||||
credentials = new TurnCredentials(user, pass);
|
credentials = new TurnCredentials(user, pass);
|
||||||
log.info("COTURN user created: true");
|
log.info("COTURN user created: true");
|
||||||
} else {
|
} else {
|
||||||
log.info("COTURN user created: false");
|
log.info("COTURN user created: false");
|
||||||
}
|
}
|
||||||
|
} catch (IOException | InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return credentials;
|
return credentials;
|
||||||
}
|
}
|
||||||
|
@ -68,18 +58,14 @@ public class BashCoturnCredentialsService extends CoturnCredentialsService {
|
||||||
boolean userRemoved = false;
|
boolean userRemoved = false;
|
||||||
|
|
||||||
log.info("Deleting COTURN user");
|
log.info("Deleting COTURN user");
|
||||||
String command = "turnadmin -d -u " + user + " -r openvidu -b" + this.coturnDatabaseLocation;
|
String command = "turnadmin -d -u " + user + " -r openvidu -N " + this.coturnDatabaseString;
|
||||||
String users = "";
|
String response = "";
|
||||||
lock.lock();
|
|
||||||
try {
|
try {
|
||||||
CommandExecutor.execCommand("/bin/sh", "-c", command);
|
response = CommandExecutor.execCommand("/bin/sh", "-c", command);
|
||||||
users = CommandExecutor.execCommand("/bin/sh", "-c", "turnadmin -l -b " + this.coturnDatabaseLocation);
|
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
|
||||||
lock.unlock();
|
|
||||||
}
|
}
|
||||||
userRemoved = !users.contains(user + "[openvidu]");
|
userRemoved = response.contains("connection success: " + this.trimmedCoturnDatabaseString);
|
||||||
log.info("COTURN user deleted: " + userRemoved);
|
log.info("COTURN user deleted: " + userRemoved);
|
||||||
return userRemoved;
|
return userRemoved;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package io.openvidu.server.coturn;
|
package io.openvidu.server.coturn;
|
||||||
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -15,14 +13,15 @@ public abstract class CoturnCredentialsService {
|
||||||
|
|
||||||
protected OpenviduConfig openviduConfig;
|
protected OpenviduConfig openviduConfig;
|
||||||
|
|
||||||
protected String coturnDatabaseLocation;
|
protected String coturnDatabaseString;
|
||||||
|
protected String trimmedCoturnDatabaseString;
|
||||||
|
|
||||||
protected boolean coturnAvailable = true;
|
protected boolean coturnAvailable = true;
|
||||||
|
|
||||||
protected ReentrantLock lock = new ReentrantLock();
|
|
||||||
|
|
||||||
public CoturnCredentialsService(OpenviduConfig openviduConfig) {
|
public CoturnCredentialsService(OpenviduConfig openviduConfig) {
|
||||||
this.openviduConfig = openviduConfig;
|
this.openviduConfig = openviduConfig;
|
||||||
|
this.coturnDatabaseString = this.openviduConfig.getCoturnDatabaseString();
|
||||||
|
this.trimmedCoturnDatabaseString = this.coturnDatabaseString.replaceAll("^\"|\"$", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract TurnCredentials createUser();
|
public abstract TurnCredentials createUser();
|
||||||
|
|
|
@ -21,4 +21,7 @@ openvidu.recording.custom-layout: /opt/openvidu/custom-layout
|
||||||
|
|
||||||
kms.uris=[\"ws://localhost:8888/kurento\"]
|
kms.uris=[\"ws://localhost:8888/kurento\"]
|
||||||
|
|
||||||
coturn.sqlite=/opt/openvidu/coturn/turndb
|
coturn.redis.ip=127.0.0.1
|
||||||
|
coturn.redis.dbname=0
|
||||||
|
coturn.redis.password=turn
|
||||||
|
coturn.redis.connect-timeout=30
|
Loading…
Reference in New Issue