mirror of https://github.com/OpenVidu/openvidu.git
Add 'docker' new option for publicUrl to use container IP
parent
e83afb9994
commit
b2b3dac208
|
@ -0,0 +1,36 @@
|
|||
package io.openvidu.server;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class CommandExecutor {
|
||||
|
||||
public static String execCommand(String... command) throws IOException, InterruptedException {
|
||||
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command);
|
||||
|
||||
processBuilder.redirectErrorStream(true);
|
||||
|
||||
Process process = processBuilder.start();
|
||||
StringBuilder processOutput = new StringBuilder();
|
||||
|
||||
try (BufferedReader processOutputReader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream()));) {
|
||||
String readLine;
|
||||
|
||||
while ((readLine = processOutputReader.readLine()) != null) {
|
||||
processOutput.append(readLine + System.lineSeparator());
|
||||
}
|
||||
|
||||
process.waitFor();
|
||||
}
|
||||
|
||||
return processOutput.toString().trim();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
System.out.println(execCommand("/bin/sh","-c","hostname -i | awk '{print $1}'"));
|
||||
}
|
||||
|
||||
}
|
|
@ -17,6 +17,7 @@ package io.openvidu.server;
|
|||
|
||||
import static org.kurento.commons.PropertiesManager.getPropertyJson;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.kurento.jsonrpc.JsonUtils;
|
||||
|
@ -149,9 +150,12 @@ public class OpenViduServer implements JsonRpcConfigurer {
|
|||
public static void main(String[] args) throws Exception {
|
||||
ConfigurableApplicationContext context = start(args);
|
||||
OpenviduConfiguration openviduConf = context.getBean(OpenviduConfiguration.class);
|
||||
OpenViduServer.publicUrl = "wss://localhost:" + openviduConf.getServerPort();
|
||||
|
||||
if (openviduConf.getOpenViduPublicUrl().equals("ngrok")) {
|
||||
|
||||
String publicUrl = openviduConf.getOpenViduPublicUrl();
|
||||
String type = publicUrl;
|
||||
|
||||
switch (publicUrl) {
|
||||
case "ngrok":
|
||||
try {
|
||||
NgrokController ngrok = new NgrokController();
|
||||
final String NEW_LINE = System.getProperty("line.separator");
|
||||
|
@ -162,18 +166,47 @@ public class OpenViduServer implements JsonRpcConfigurer {
|
|||
"-------------------------" + NEW_LINE;
|
||||
System.out.println(str);
|
||||
OpenViduServer.publicUrl = ngrok.getNgrokServerUrl().replaceFirst("https://", "wss://");
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println(" No ngrok connection ");
|
||||
System.err.println("Ngrok URL was configured, but there was an error connecting to ngrok: "+e.getClass().getName()+" "+e.getMessage());
|
||||
System.err.println("Fallback to local URL");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "docker":
|
||||
try {
|
||||
OpenViduServer.publicUrl = "wss://"+getContainerIP() + ":" + openviduConf.getServerPort();
|
||||
} catch(Exception e) {
|
||||
System.err.println("Docker container IP was configured, but there was an error obtaining IP: "+e.getClass().getName()+" "+e.getMessage());
|
||||
System.err.println("Fallback to local URL");
|
||||
}
|
||||
} else if (!openviduConf.getOpenViduPublicUrl().equals("local")) {
|
||||
System.out.println("CUSTOM URL");
|
||||
OpenViduServer.publicUrl = openviduConf.getOpenViduPublicUrl().replaceFirst("https://", "wss://");
|
||||
break;
|
||||
|
||||
case "local":
|
||||
break;
|
||||
|
||||
default:
|
||||
type = "custom";
|
||||
OpenViduServer.publicUrl = publicUrl.replaceFirst("https://", "wss://");
|
||||
if (!OpenViduServer.publicUrl.startsWith("wss://")) {
|
||||
OpenViduServer.publicUrl = "wss://" + OpenViduServer.publicUrl;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(OpenViduServer.publicUrl == null) {
|
||||
type = "local";
|
||||
OpenViduServer.publicUrl = "wss://localhost:" + openviduConf.getServerPort();
|
||||
}
|
||||
|
||||
System.out.println("OpenVidu Server using "+type+" URL: "+OpenViduServer.publicUrl);
|
||||
}
|
||||
|
||||
private static String getContainerIP() throws IOException, InterruptedException {
|
||||
return CommandExecutor.execCommand("/bin/sh","-c","hostname -i | awk '{print $1}'");
|
||||
}
|
||||
|
||||
public static ConfigurableApplicationContext start(String[] args) {
|
||||
log.info("Using /dev/urandom for secure random generation");
|
||||
System.setProperty("java.security.egd", "file:/dev/./urandom");
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.springframework.stereotype.Component;
|
|||
public class OpenviduConfiguration {
|
||||
|
||||
@Value("${openvidu.publicurl}")
|
||||
private String openviduPublicUrl; //local, ngrok, FINAL_URL
|
||||
private String openviduPublicUrl; //local, ngrok, docker, FINAL_URL
|
||||
|
||||
@Value("${server.port}")
|
||||
private String serverPort;
|
||||
|
|
Loading…
Reference in New Issue